If you have 4 indexes, for example:
0 1 2 3
The division into two triangles will be one with the first three indices, and one with the first, third and fourth. In this example:
0 1 2 0 2 3
Try using some ASCII art to illustrate this:
3-------2 | /| | / | | / | |/ | 0-------1
Here you see 0 1 2 3 as a square, 0 1 2 as the first triangle (bottom right) and 0 2 3 as the second triangle (top left).
In the general case, for faces with vertices n you create triangles:
0 (i) (i + 1) [for i in 1..(n - 2)]
If you do not insist on individual triangles, you can also use the GL_TRIANGLE_FAN primitives, which are still mostly OpenGL. Thus, you can draw any convex polygon with a triangle fan using the original index sequence. Thus, a triangle with a vertex sequence of 0 1 2 3 describes a quad in this case and is very easy to generalize to a face with more than four vertices.
Edit: since you still have problems, let's see how this applies to the example in your post. I will list the initial quad index sequence for each face and the index sequence for two triangles after splitting the quadrant.
f 1 2 3 4 --> (1 2 3) (1 3 4) f 8 7 6 5 --> (8 7 6) (8 6 5) f 4 3 7 8 --> (4 3 7) (4 7 8) f 5 1 4 8 --> (5 1 4) (5 4 8) f 5 6 2 1 --> (5 6 2) (5 2 1) f 2 6 7 3 --> (2 6 7) (2 7 3)
It looks right to me when I draw a cube. Remember to subtract 1 from the indexes for your use, as these are 1-based indexes, and you will almost certainly need 0-based indexes.
source share