The GL_TRIANGLE_STRIP way of building triangles can be confusing under some circumstances, so i try to explain it here.
GL_TRIANGLE_STRIP is one of the ways to push vertices down the OpenGL pipeline for further processing (“to create geometry”). There are two others for creating triangles too: GL_TRIANGLES and GL_TRIANGLE_FAN – but they’re not covered here. Take a look at the OpenGL Programming Guide to get information about those two.
Take a look at the following drawing to get a feeling for the triangle strip:
This strip is made from a total of 6 vertices, which form 4 triangles. The order of pushing the vertices into the pipeline is crucial cause of the winding order.
At least 3 vertices are needed in a strip to form a triangle, each additional vertex forms a new triangle. The triangle itself is built with respect if the current vertex is even or odd:
Let’s dissect the example above to get a feeling for it:
- The vertices V1, V2 and V3 form the first triangle
- You can say too: V3 is odd numbered, so the next triangle is formed out of V1, V2 and V3
- The vertex V4 is even numbered, so the next triangle is formed out of V3, V2 and V4
- The vertex V5 is odd numbered, so the next triangle is formed out of V3, V4 and V5
- The vertex V6 is even numbered, so the next triangle is formed out of V5, V4 and V6
Due to the two different ways of building the triangles, the winding order (counter-clockwise, GL_CCW) is preserved.