Each value in the index array indicates the same time for the position, normal and texture coordinates.
They are organized only by groups of 3, because they simply describe the vertices of a triangle, so, of course, 3 vertices = 1 triangle.
const GLushort tigerBottomIndices[] = { 0,1,2,
So, let's pick the first value of these indices, 0 .
It means:
Select vertex position number 0
Also select normal vertex number 0
And select texture coordinates 0
const Vertex3D tigerBottomPositions[] = { {0.176567, 0.143711, 0.264963},
So, this information is sent to the vertex shader:
VertexPosition: 0.176567, 0.143711, 0.264963
VertexNormal: -0.425880, -0.327633, 0.350967
VertexTextureCoordinates: 0.867291, 0.359728
...
If you use no indexes, opengl will send this vertex data linearly, so after sending the vertex data number 0 it will send the data to position 1 of the arrays, then 2, 3, 4, etc.
This is good, but sometimes your triangles end with one or two identical vertices. Consider this:
You can see 2 triangles forming a square, and they have 2 common vertices, 0 and 2. Therefore, instead of 6 vertices, which are 3 for each triangle, we have only 4, and 2 tragedies use the same data for 2 of their vertices. This is good for performance, especially when you have large models with hundreds of triangles.
To draw the first triangle, we need the numbers of vertices 0, 1, and 2, and for the second triangle we need the numbers of vertices 0, 2, and 3.
See without an array of indices opendl will try to use the vertices 0, 1 and 2 (ok for the first triangle), but for the second triangle opengl will look for the vertices 3, 4 and 5. This is not true.
And so we create an index array, so opengl can send the correct vertices for the vertex shader. In our case, our index array will look like this:
const GLushort tigerBottomIndices[] = { 0,1,2, 0,2,3, }