1

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

DGAF
  • 71
  • 7
  • In your first vertex array, you are trying to draw triangle strips with vertices: {v1, v2, v3}, {v1, v4, v3}. But this second triangle is invalid or degenerate because it includes v1. In your second vertex array, the triangle strips are comprised of vertices: {v1, v2, v3}, {v2, v4, v3} and so will be rendered properly as a quad composed of two triangles. – Maico De Blasio Jun 05 '23 at 03:43

1 Answers1

2

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.

kwikc
  • 72
  • 4