Question about order of VertexPositionTexture array

I am new to monogame, so this question may be dumb…

class CodedCube:DrawableGameComponent
{

VertexPositionTexture[] floorVerts;

public override void Initialize()
{
floorVerts = new VertexPositionTexture[3];

        floorVerts[0].Position = new Vector3(-1, -1, 0);
        floorVerts[1].Position = new Vector3(0, 1, 0);
        floorVerts[2].Position = new Vector3(1, -1, 0);


}


}

I successfully draw a triangle with code above by following a tutorial, however, if I switch the order of vertex position, like this:

        floorVerts[0].Position = new Vector3(0, 1, 0);  <- this was floorVerts[1]
        floorVerts[1].Position = new Vector3(-1, -1, 0); <- this was floorVerts[0]
        floorVerts[2].Position = new Vector3(1, -1, 0);

the triangle will not be drawn(or it is drawn but the camera cannot catch it? I tried to change the camera to several different position, but it does not work).

so I wonder about is there a specific order for vertices array? What is rule of the order?

Usually the GPU is set up to only draw triangles that have their vertices wound in a set direction, either clockwise or counterclockwise. That’s an optimization that’s most useful in 3D application. Because most 3D models are closed volumes, it’s a waste to draw the back side that’s occluded by the front side of the volume itself. GPU’s support what’s called backface culling for that reason. You can tell the GPU to only draw triangles that come in in the right order, so it does not draw the backside of a model.

In MG you can set the winding order or disable backface culling with the CullMode property of the RasterizerState set on the GraphicsDevice. The default is CullCounterClockwise, so your vertices are expected to be wound clockwise. To disable culling you can set the predefined RasterizerState CullNone:

GraphicsDevice.RasterizerState = RasterizerState.CullNone;
1 Like

Thank you very much, I have change the vertices to another clockwise order and it works!

1 Like