OpenGL VBOs + triangle strips

Soldato
Joined
23 May 2005
Posts
2,964
Location
Auckland, New Zealand
I'm relatively new to opengl and i might be pushing it a bit trying to write this but basically i'm trying to create a square grid of size x by x using vertex buffer objects. I can draw the grid using two triangles for each square, but this means that im declaring 6 vertices for each square and on a 512x512 grid, thats 1572864 vertices... when all there are really only 512x512 (262144) unique vertices - 6 times less memory (or thereabouts).

Now, I've uploaded the vertex information into the graphics memory so the grid (4x4 used for example) vertices are set up as shown:

A B C D
E F G H
I J K L
M N O P

I want to use a triangle strip to draw the whole lot at once, using glDrawArrays(GL_TRINAGLE_STRIP, start, numVertices). To draw the triangle strip I understand I have to create an index buffer and use degenerated triangles to jump between rows.

since im using

glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh->m_nVBOVertices );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );

before the call to draw arrays, i'm telling it to use the data sequentially straight out of the vertex buffer, drawing the vertices in the wrong order.

How would I set up an index buffer and tell drawarrays to use it instead of the vertex buffer? would I need to upload index buffer information to the graphics memory too? where each index is a pointer to a vertex?

sorry if thats all a bit hard to understand.

Joe
 
Back
Top Bottom