2

Hi I started to study directx12. I don't have any knowledge on prior versions.

I am following this example program HelloWorldTriangle which rendering a triangle. I want to draw a rectangle so,

I changed

Vertex triangleVertices[] =
        {
            { { 0.0f, 0.25f * m_aspectRatio, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
            { { 0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
            { { -0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }

        };

m_commandList->DrawInstanced(3, 1, 0, 0);

to

Vertex triangleVertices[] =
            {
                { { 0.0f, 0.25f * m_aspectRatio, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
                { { 0.25f, -0.25f * m_aspectRatio, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
                { { -0.25f, -0.3f * m_aspectRatio, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
                { { -0.25f, -0.2f * m_aspectRatio, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },

            };

    m_commandList->DrawInstanced(4, 1, 0, 0);

But still draws a triangle with different angle .. Please explain what I have to change to get a rectangle.

It will be really helpful for me if you give some links or books to headstart directx12 ..

Thanks in advance ..

Wickkiey
  • 4,446
  • 2
  • 39
  • 46
  • 3
    I strongly recommend you focus on learning Direct3D 11 before trying to take on Direct3D 12. Direct3D 12 is really for people who would be comfortable writing the Direct3D 11 Runtime from scratch. See [this thread](http://stackoverflow.com/questions/29719853/directx-c-3d-engine-programming-learn-now-or-wait-for-directx-12/29779660#29779660) for some more details. – Chuck Walbourn Jun 30 '16 at 07:03
  • 1
    [DirectX Tool Kit for DirectX 12](https://github.com/Microsoft/DirectXTK12/wiki/Getting-Started) is now available. That said, you should really know Direct3D 11 well before tackling Direct3D 12 which is an API designed for graphics experts and is therefore quite unforgiving to newbies. – Chuck Walbourn Jul 26 '16 at 17:22

1 Answers1

1

I don't want to download the whole code, but familiarize yourself with Topology concept. In this project primitive topology is set to D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, so it will draw triangle using 3 vertices, and then it will need 3 more to draw another one. If you want to draw second triangle using last 2 vertices and new one you have to use trianglestrip, however make sure your new triangle faces correct way (or you set D3D12_GRAPHICS_PIPELINE_STATE_DESC RasterizerState.CullMode = D3D12_CULL_MODE_NONE)

MaciekGrynda
  • 583
  • 2
  • 13