Page 1 of 2
OpenGL and Vertex Arrays
Posted: Mon Jan 19, 2004 6:59 pm
by Polo
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

Re: OpenGL and Vertex Arrays
Posted: Mon Jan 19, 2004 9:36 pm
by traumatic
Polo wrote:I hear the Vertex Arrays were a lot much faster[...]
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.
PS : Please don't link me to a tutorial page with C++ code

No tutorial? Fine...
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
Later, you can render it like this:
Code: Select all
glEnableClientState_(#GL_VERTEX_ARRAY)
glVertexPointer_(3, #GL_FLOAT, 0, vertices())
glDrawElements_(#GL_QUADS, 24, #GL_UNSIGNED_BYTE, indices())
Voilá... no tutorial

Posted: Tue Jan 20, 2004 1:14 am
by Dare2
lol @ "renderMeACubeAndMakeMeHappy"
What values are #GL_VERTEX_ARRAY, #GL_FLOAT, #GL_QUADS, #GL_UNSIGNED_BYTE ?
And is there a tutorial for beginners explaining vertices and indices? Or life, the universe and everything?
Posted: Tue Jan 20, 2004 11:04 am
by Rings
Dare2 wrote:And is there a tutorial for beginners explaining vertices and indices? Or life, the universe and everything?
42
Posted: Tue Jan 20, 2004 11:49 am
by traumatic
What values are #GL_VERTEX_ARRAY, #GL_FLOAT, #GL_QUADS, #GL_UNSIGNED_BYTE ?
They are defined in the opengl include.
And is there a tutorial for beginners explaining vertices and indices? Or life, the universe and everything?
Well, just take your favourite searchengine. There are a lot of tutorials on this.
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...
Posted: Tue Jan 20, 2004 10:52 pm
by Dare2
Ah 42!
Well, so long, and thanks for all the fishes.

Posted: Wed Jan 21, 2004 1:35 pm
by Polo
instead of putting the vertices in arrays, can we put the vertices in memory ? If yes, how ?
Posted: Wed Jan 21, 2004 2:55 pm
by pg
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);
Posted: Wed Jan 21, 2004 3:46 pm
by Polo
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 :
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)
Well, perhaps not like that, but you see what I mean ?
Posted: Wed Jan 21, 2004 4:43 pm
by pg
sorry, I see....
I think this must work, it's just a memory address
void glVertexPointer(GLint size,
GLenum type,
GLsizei stride,
const GLvoid *pointer)
pointer Specifies a pointer to the first coordinate of the first vertex in the array
Posted: Wed Jan 21, 2004 5:07 pm
by pg
something like this if the first data is at 0...
glVertexPointer_(3, #GL_FLOAT, 0, @vertices(0))
Posted: Wed Jan 21, 2004 5:23 pm
by Polo
I can't put @vertices(0) if I'm using memory...
Posted: Wed Jan 21, 2004 5:39 pm
by pg
Yes, I did reboot my brain
that how I would do it, maybe you too?
Restore vertices
add.w=0
For i=0 To 23
Read vertex.f
PokeF(memaddress+add, vertex)
add=add+4
Next
Posted: Wed Jan 21, 2004 5:42 pm
by Polo
I do that : I have one memory with the vertices, one with the indexes. The fact is I want to use these stuffs which are in memory, and that I don't know how to do...
Posted: Thu Jan 22, 2004 9:09 am
by RonStyle
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

)