c++openglterraingl-triangle-strip

How does OpenGL actually read indices?


I trying to figure out how to draw a flat terrain with triangle_strips, and while I was writing the loop for creating indices array I thought how does OpenGL know to parse the indices because so far I have seen everybody when creating indices write them like that:

0 3 1 4 2 5 0xFFFF 3 6 4 7 5 8

(here being 0xFFFF primitive restart that marks the end of the strip)

and so technically as I understand this should be parsed with offset +1 for every triangle...so the first triangle would use first three indices (0 3 1) and the next with offset +1 (3 1 4)...next (1 4 2) and so on. Here's the picture in case I didn't explain well: First way

But other way that I have seen is creating indices for every triangle separately .... so: 0 3 1 3 1 4 1 4 2 4 2 5 Second way

So my question is how to specify the layout...does OpenGL do this automatically as I set draw call to GL_TRIANGLE_STRIP or else?


Solution

  • There are three kinds of triangle primitives:

    Your first scenario describes a GL_TRIANGLE_STRIP, while your second scenario describes GL_TRIANGLES.