I’m planning on using VBO in order to display a large points array, around 512×512. In order to display it each vertex depends on its nearest neighbors. For example if I have the following table:
[ 1, 2, 3, 5, 6, 7
8, 9,10,11,12,13,
14,15,16,17,18,19]
and I would like to draw a polygon using 5th point I will have to use the following code:
glBegin(GL_TRIANGLE_STRIP)
glVertex(Points5)
glVertex(Points6)
glVertex(Points11)
glVertex(Points12)
glEnd()
and so on for any other point..
I know that at any given moment my buffer holds only 512×512 points, but how can I “teach” it to draw in that specific way using the GL_TRIANGLE_STRIP and VBOs?
First of all don’t draw a separate triangle strip for each individual quad! Just split each of these quads into two triangles and put all the vertex indices of these triangles into a single index array/buffer, like Brett Hale suggests. This way you can then draw the whole mesh with a single call to
glDrawElements(GL_TRIANGLES, ...).If you don’t know wth an index array is or what a vertex array/buffer is in general, then you should delve a little deeper into this topic. But by all means, please stay away from your current solution of drawing a single strip for each quad. It may sound great at first (regarding number of vertices to send) but it isn’t. Remember that the advantage of VBOs is not just the possible GPU storage, but also the fact that you don’t need a driver call for each individual primitive and your current solution can only be done that way.
You could also use
GL_QUADSinstead ofGL_TRIANGLES. This way you still only need 4 indices per quad (in contrast to 6 when using triangles) and can still draw it in one single call. But also keep in mind thatGL_QUADShas been dropped from the core profile of newer OpenGL versions (3+) and also from ES. SoGL_TRIANGLESmight be a more portable solution (and the GPU splits it into triangles anyway).