PDA

View Full Version : Vertex Array concept question.



rnodal
09-10-2008, 11:50 AM
Hello all:
I'm trying to understand vertex array a little bit more. In my current code I use vertex arrays to store all the information of the 2D images that I render using quads but I would like to add more shapes(triangles, points, etc). How do I go about doing that?Do I need a separate array for each primitive or can I mix them and then there is a trick to process them?Any help would be greatly appreciated. Thank!

-r

unsigned void
09-10-2008, 11:09 PM
Well, basic idea as follows: create your vertex structure, for example
struct Vertex
{
float x,y,z; //coord
float s,t; //texcoord
float nx,ny,nz//normal
}
then get your models into array of vertices. Also create array of indices for them to render in quads, triangles or triangle strips. Indices are going to separate array, because their number is not connected directly with number of vertices they reference...

Generate two buffers with glGenBuffersARB(2, vbo);

Set vertex buffer data with
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[0])
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vSize, vertexArray, GL_STATIC_DRAW_ARB);

Set index buffer data with
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[1])
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, iSize, indexArray, GL_STATIC_DRAW_ARB);

Then draw it with glDrawRangeElements, and that's it. :)

rnodal
09-11-2008, 12:56 PM
Thank you so much for taking the time to answer my question. I will study the code that you just posted and report back if I have any other questions. Thanks a ton.

-r