c++direct3d12

Question about D3D12 vertex drawing order


I want to draw a rectangle using D3D12, but why do I need to set the 'N' shaped vertex order to draw it correctly? I am not quite familiar with this aspect.

struct GRS_VERTEX
{
    XMFLOAT4 Position;
    XMFLOAT4 Color;
};

GRS_VERTEX stTriangleVertices[] =
            {
                { { -0.75f, -0.75f, 0.0f ,1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
                { { -0.75f, 0.75f, 0.0f ,1.0f  }, { 0.0f, 1.0f, 0.0f, 1.0f } },
                { { 0.75f, 0.75f, 0.0f  ,1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
                { { 0.75, -0.75f, 0.0f  ,1.0f }, { 0.0f, 0.0f, 0.25f, 1.0f } }
            };

// ......

                //Draw Call!!!
                pICMDList->DrawInstanced(4, 1, 0, 0);


Unexpected Result


GRS_VERTEX stTriangleVertices[] =
            {
                { { -0.75f, -0.75f, 0.0f ,1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
                { { -0.75f, 0.75f, 0.0f ,1.0f  }, { 0.0f, 1.0f, 0.0f, 1.0f } },
                { { 0.75f, -0.75f, 0.0f  ,1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
                { { 0.75, 0.75f, 0.0f  ,1.0f }, { 0.0f, 0.0f, 0.25f, 1.0f } }
            };

// ......

                //Draw Call!!!
                pICMDList->DrawInstanced(4, 1, 0, 0);


Rectangle


Solution

  • Because in DirectX, a triangle that the vertices are in clockwise order is facing the camera. I think your 'N' shaped means triangle strips. See here for vertices order in Triangle Strips, https://learn.microsoft.com/en-us/windows/win32/direct3d9/triangle-strips.