I noticed an interesting feature in OpenGL related to vertex indexing, and so far I can’t understand why this is happening.
So, what is the point:
I have a clockwise order to bypass the vertices for visible faces. There are 4 vertices (the usual rectangle), they are set approximately as follows: 
In the array, they are like this:
vertices[DefaultGeometryType::PLANE] = { { { (size / 2), (size / 2), 0.0f },{ 1.0f,0.0f,0.0f },{ 1.0f,1.0f } }, { { (size / 2), -(size / 2), 0.0f },{ 0.0f,1.0f,0.0f },{ 1.0f,0.0f } }, { { -(size / 2), -(size / 2), 0.0f },{ 0.0f,0.0f,1.0f },{ 0.0f,0.0f } }, { { -(size / 2), (size / 2), 0.0f },{ 1.0f,1.0f,0.0f },{ 0.0f,1.0f } }, }; Then I have an array of indices for this square. It looks like this:
indices[DefaultGeometryType::PLANE] = { 0,1,2,0,2,3 }; Thus, it turns out that the square is divided into 2 triangles with common vertices 0 and 2 (diagonal 0-2 will be a common edge for these two triangles). As a result, I get this picture:
It seems to be all right. And then I decided to change the indices a bit, so that the common edge for the two triangles would not be a diagonal of 0-2 and 3-1. I changed the indices as follows:
3,0,1,1,2,3 And in the end, the square began to look like this:
Agree, the picture is completely different. It seems that the interpolation of colors is not entirely correct. I tried different versions of the order of the indices, but it always turned out that when a rectangle divides diagonally 0-2 everything is fine, and when 3-1 it is such a strange picture. But why? Maybe this is some kind of incorrect indexing of vertices? Are there any rules for correct indexing? Or am I missing something and really should be?


