Jump to content
  • Advertisement
Sign in to follow this  
vivek1may

DX12 Draw rectangle Directx 12

This topic is 751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ..

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 } },

Share this post


Link to post
Share on other sites
Advertisement

DX12 is intended for high-investment/high-performance programming. It's is alternative to DX11 rather than a replacement. Don't make the mistake of thinking that DX12 will give you better performance out of the box; you have to understand what's going on very well in order to make the kinds of changes required to see any improvement. If you're still at this stage of the game then just use DX11 until you have a strong understanding of the pipeline and process. Otherwise you'll spend a lot of extra time just to end up with a slower program.

Share this post


Link to post
Share on other sites

What @Khatharr said is very true not only about DX12, but Vulkan and Metal too. All these APIs exist for exactly same purpose. What's interesting is that indeed, "naive" code written using DX12 and Vulkan will probably be outperformed by equivalent code made with use of an older API. This is because the driver does LOTS of work trying to figure out what you want to do, how you want to do and takes care about parallelism etc. With DX12 you have to take care about it yourself. So it's not only graphics programming experience you need but you need to have knowledge about memory management ( I guess you didn't get yet to the resource transitions, descriptor heaps etc. ), synchronization ( using barriers is actually DIFFICULT even for experienced programmers! ), parallelism ( threading, proper way of distributing your workload, so you're not making a CPU be a bottleneck ).

 

There's one thing everyone who tries to touch those new APIs should know. Before the driver was doing all the work, but now it's YOU who write the driver. If you're ready for that ( and many programmers indeed are! ) then do it, but otherwise get more experienced. Understand what it takes to actually write such "driver-like" code.

 

Again, I don't want to discourage anybody. It's quite opposite. Get there, become DX12/Vulkan developer! Just do it following the right path. It's bit like learning for example physics. You're not going to start from learning about relativity etc. right? :) But once you have basics, understanding more complex topics comes more natural and easier :)

Share this post


Link to post
Share on other sites

I feel like there should be more of an emphasis in general on the fact that DirectX 12 and Vulkan are not APIs you want to dive into unless you actually have a need for them, or if you're planning on specifically refining your graphics engine development skills.

 

Starting with D3D12/Vulkan without any exposure to previous APIs just sets you up for a very very bad time with very bad results in the end (as mentioned above). Building a fully featured D3D12 engine which can outperform an established D3D11 engine is a complex task even for seasoned engineers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!