Jump to content

  • Log In with Google      Sign In   
  • Create Account

Draw rectangle Directx 12


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1   Members   

108
Like
1Likes
Like

Posted 29 June 2016 - 11:31 PM

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


#2   Members   

822
Like
11Likes
Like

Posted 30 June 2016 - 03:05 AM

*
POPULAR

I don't want to discourage you but I think it's better if you start with OpenGL or previous D3D versions as you clearly don't have much experience in the graphics. Otherwise you would take in account used topology ( probably you rendering triangles as your topology ) or you would change it to triangle strip. Adding one more point does not tell D3D to render rectangle. In D3D12_GRAPHICS_PIPELINE_STATE_DESC structure, there's a field primitiveTopologyType but it doesn't have a topology responsible for drawing strips. You may need to call IASetPrimitiveTopology() on your command list adn tell to render triangle strip by passing D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP. Then probably it may work, but once again - if this is your start with 3D graphics, do not start from DX12 or Vulkan. First understand certain concepts with OpenGL and DX9/10/11. Otherwise you will end your journey quicker than you think simply being demotivated but things you cannot get working due to lack of experience. 



#3   Members   

7674
Like
2Likes
Like

Posted 30 June 2016 - 03:09 PM

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.


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#4   Members   

822
Like
0Likes
Like

Posted 30 June 2016 - 03:57 PM

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 :)



#5   Members   

4638
Like
1Likes
Like

Posted 30 June 2016 - 05:41 PM

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.


I gets all your texture budgets!





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.