I'm beginning with the 3D rendering in Monogame and i'm facing not a real issue because i already find a way to bypass it but more of a question. I'm rendering a simple cube with 8 vertices like that:
_vertices[0] = new VertexPositionColor(new Vector3(-1, 1, -1), Color.Red);
_vertices[1] = new VertexPositionColor(new Vector3(-1, -1, -1), Color.Red);
_vertices[2] = new VertexPositionColor(new Vector3(1, -1, -1), Color.Red);
_vertices[3] = new VertexPositionColor(new Vector3(1, 1, -1), Color.Red);
_vertices[4] = new VertexPositionColor(new Vector3(-1, 1, 1), Color.Green);
_vertices[5] = new VertexPositionColor(new Vector3(-1, -1, 1), Color.Green);
_vertices[6] = new VertexPositionColor(new Vector3(1, -1, 1), Color.Green);
_vertices[7] = new VertexPositionColor(new Vector3(1, 1, 1), Color.Green);
But i'm also using an index buffer to draw each triangle for each faces and this is where my issue is. When i'm doing the following:
_indices = new int[] // 6 faces, each containing 2 triangles of 3 vertices
{
0, 1, 2, 0, 2, 3, // front
3, 2, 6, 3, 6, 7,
4, 0, 3, 4, 3, 7,
1, 5, 6, 1, 6, 2,
4, 5, 1, 4, 1, 0,
4, 7, 6, 4, 6, 5 // back
};
The render is perfect and every edge is rendered as you can see on this gif:
https://i.stack.imgur.com/ucNSV.jpg
But when i changed the order inside the index buffer of the back part, like the following:
_indices = new int[] // 6 faces, each containing 2 triangles of 3 vertices
{
0, 1, 2, 0, 2, 3, // front
3, 2, 6, 3, 6, 7,
4, 0, 3, 4, 3, 7,
1, 5, 6, 1, 6, 2,
4, 5, 1, 4, 1, 0,
4, 6, 7, 4, 5, 6 // back, update is here
};
The only thing that was updated is the order of the last column and the result is the following:
https://i.stack.imgur.com/YerSh.jpg
Why does the render is not done on the second case when the only change made is the order of two vertices ? I know that I can do a rasterize state to render each side of a triangle but one solution is working without it, so i'd like to avoid using it.
Thanks!