PS : Please don't link me to a tutorial page with C++ code
OpenGL and Vertex Arrays
OpenGL and Vertex Arrays
I hear the Vertex Arrays were a lot much faster, so I want to use them, with Purebasic of course, but I don't know really how... Does someone know how to ?
PS : Please don't link me to a tutorial page with C++ code
PS : Please don't link me to a tutorial page with C++ code
Re: OpenGL and Vertex Arrays
IMHO that's not always the truth. Sometime displaylists win, sometimes vertexarrays are faster. I think it depends on what you're trying to do.Polo wrote:I hear the Vertex Arrays were a lot much faster[...]
No tutorial? Fine...PS : Please don't link me to a tutorial page with C++ code
You can do it exactly like in C, here's a small code example, called the obligatory "RenderMeACubeAndMakeMeHappyExample"
Code: Select all
Dim vertices.f(23)
Dim indices.b(23)
Restore vertices
For i=0 To 23
Read vertex.f
vertices(i) = vertex
Next
Restore indices
For i=0 To 23
Read index.b
indices(i) = index
Next
DataSection
vertices:
Data.f -1.0, 1.0, 1.0
Data.f 1.0, 1.0, 1.0
Data.f 1.0, -1.0, 1.0
Data.f -1.0, -1.0, 1.0
Data.f -1.0, 1.0, -1.0
Data.f 1.0, 1.0, -1.0
Data.f 1.0, -1.0, -1.0
Data.f -1.0, -1.0, -1.0
indices:
Data.b 0, 1, 2, 3
Data.b 4, 5, 1, 0
Data.b 3, 2, 6, 7
Data.b 5, 4, 7, 6
Data.b 1, 5, 6, 2
Data.b 4, 0, 3, 7
EndDataSection
Code: Select all
glEnableClientState_(#GL_VERTEX_ARRAY)
glVertexPointer_(3, #GL_FLOAT, 0, vertices())
glDrawElements_(#GL_QUADS, 24, #GL_UNSIGNED_BYTE, indices())
Good programmers don't comment their code. It was hard to write, should be hard to read.
They are defined in the opengl include.What values are #GL_VERTEX_ARRAY, #GL_FLOAT, #GL_QUADS, #GL_UNSIGNED_BYTE ?
Well, just take your favourite searchengine. There are a lot of tutorials on this.And is there a tutorial for beginners explaining vertices and indices? Or life, the universe and everything?
OpenGL-related I can't recommend http://nehe.gamedev.net often enough. The OGL-Redbook (http://www.opengl.org)
also explains some basics of 3d, like the things you were asking for.
Other than that, I guess the best way to learn this kind of stuff is to read lots of books and to try.
Feel free to contact me on further questions.
And yes, 42...
Good programmers don't comment their code. It was hard to write, should be hard to read.
If they are in arrays they are allready in memory, you could access the memory location like this
address.l = @myarray(0).
or you can reserve memory
memaddress.l = AllocateMemory(0, size, 0)
and write to memory
PokeF(memaddress, vertex) // float values
and read
value.f=PeekF(memaddress)
for each new value you must increment the memoryaddress
you can test it with this code:
memaddress.l = AllocateMemory(0, 100, 0)
PokeF(memaddress, 125.23)
value.f=PeekF(memaddress)
MessageRequester("value read from memory: ", StrF(value), 0);
address.l = @myarray(0).
or you can reserve memory
memaddress.l = AllocateMemory(0, size, 0)
and write to memory
PokeF(memaddress, vertex) // float values
and read
value.f=PeekF(memaddress)
for each new value you must increment the memoryaddress
you can test it with this code:
memaddress.l = AllocateMemory(0, 100, 0)
PokeF(memaddress, 125.23)
value.f=PeekF(memaddress)
MessageRequester("value read from memory: ", StrF(value), 0);
Thanks for the reply !
But that's not what I mean, I know how to use the memory, I mean, instead of putting :
glVertexPointer_(3, #GL_FLOAT, 0, vertices())
vertices is a Dim array, and I want to know if we can use the memory for that, if I use your example :
But that's not what I mean, I know how to use the memory, I mean, instead of putting :
glVertexPointer_(3, #GL_FLOAT, 0, vertices())
vertices is a Dim array, and I want to know if we can use the memory for that, if I use your example :
Well, perhaps not like that, but you see what I mean ?memaddress.l = AllocateMemory(0, 100, 0)
PokeF(memaddress, 125.23)
PokeF(memaddress+4, 125.23)
PokeF(memaddress+8, 125.23)
[...]
;and....
glVertexPointer_(3, #GL_FLOAT, 0, memaddress.l)
Display lists will probably be alot faster than anything held in local sys-mem.(Depending on your card, display lists are usually stored within AGP memory, which is ddr on decent cards, and much closer to the gpu)
not to mention encapsulating everything needed to render the model in one ultra-tiday call.(Obviously not the reason to use it, but a nice side-effect
)
not to mention encapsulating everything needed to render the model in one ultra-tiday call.(Obviously not the reason to use it, but a nice side-effect


