Note that there are some explanatory texts on larger screens.

plurals
  1. PODirect3D11(C++): Rendering (basic) question
    primarykey
    data
    text
    <p>I've been following a book about basics for game programming with D3D11. I now understand the absolute basics of Direct3D :)</p> <p>but... I have a question. In the book, I always had to make one demo at a time. Now, I'm trying to make a 2D game with it. Since I don't want to get used to bad habits so I need your advice.</p> <p>In the book, I always had to define a (struct VertexPos with texcoord and position members) OR (struct VertexPos with only a XMFLOAT3 position member). In the game I'm making, I want to be able to draw both solid surfaces without textures and surfaces with textures. I'm not sure how to do this, let alone do this efficiently.</p> <p>Here is my rendering function:</p> <pre><code>void GameSpriteDemo::Render() { if (m_pD3DContext == 0) {return;} float ClearColor[4] = {0.0f, 0.0f, 0.25f, 1.0f}; m_pD3DContext-&gt;ClearRenderTargetView(m_pBackBufferTarget,ClearColor); UINT stride = sizeof(VertexPos); UINT offset = 0; m_pD3DContext-&gt;IASetInputLayout(m_pInputLayout); m_pD3DContext-&gt;IASetVertexBuffers(0,1,&amp;m_pVertexBuffer, &amp;stride, &amp;offset); m_pD3DContext-&gt;IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); m_pD3DContext-&gt;VSSetShader(m_pSolidColorVS,0,0); m_pD3DContext-&gt;PSSetShader(m_pSolidColorPS,0,0); m_pD3DContext-&gt;PSSetShaderResources(0,1,&amp;m_pColorMap); m_pD3DContext-&gt;PSSetSamplers(0,1,&amp;m_pColorMapSampler); for(int i=0; i &lt; 2; ++i) { XMMATRIX world = m_Sprites[i].GetWorldMatrix(); XMMATRIX mvp = XMMatrixMultiply( world, m_VpMatrix ); mvp = XMMatrixTranspose(mvp); m_pD3DContext-&gt;UpdateSubresource(m_pMvpCB,0,0,&amp;mvp,0,0); m_pD3DContext-&gt;VSSetConstantBuffers(0,1,&amp;m_pMvpCB); m_pD3DContext-&gt;Draw(6,0); } m_pSwapChain-&gt;Present(0,0); } </code></pre> <p>So, how should I handle this efficiently with multiple vertex buffers, input layouts, Shaders, Blenders, etc?</p> <p>Should I just create multiple versions of those, and then set reset the input assembly, shaders and such after the Draw call? Or does this not work/ is this not efficient?</p> <p>Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload