title: Direct3D 11 - Drawing a Triangle
body: <p>I have initialise all of Direct3D 11 but when i come to draw some geometry the geometry doesn't show.</p>
  
  <p>I have created the Pipeline, the Geometry and created a draw function for the geometry to be drawn. My main question is can anyone help me understand why the Triangle isn't drawn in the window?</p>
  
  <pre><code>void cSystem::Draw(UINT count)
  {
      // draw stuff...    
      UINT stride = sizeof(Vertex);
      UINT offset = 0;
      p_D3D11DeviceContext-&gt;IASetVertexBuffers(0, 1, &amp;p_VertextBuffer, &amp;stride, &amp;offset);
  
      p_D3D11DeviceContext-&gt;IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  
      p_D3D11DeviceContext-&gt;Draw(3, 0);
  
      if (count == 0)
      {
          INFO(L"Draw() Complete");
      }   
  }
  
  void cSystem::InitGeometry() // initialise the geometry for the scene
  {   
      Vertex vertices[] =
      {
          { D3DXVECTOR3(0.0f, 0.5f, 0.5f), D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f) },
          { D3DXVECTOR3(0.5f, -0.5f, 0.5f), D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f) },
          { D3DXVECTOR3(-0.5f, -0.5f, 0.5f), D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f) }
      };
  
      D3D11_BUFFER_DESC bdsc;
      ZeroMemory(&amp;bdsc, sizeof(D3D11_BUFFER_DESC));
      bdsc.Usage = D3D11_USAGE_IMMUTABLE;
      bdsc.ByteWidth = sizeof(Vertex) * 3;
      bdsc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
      bdsc.CPUAccessFlags = 0;
      bdsc.MiscFlags = 0;
      D3D11_SUBRESOURCE_DATA vinitdata;
      ZeroMemory(&amp;vinitdata, sizeof(D3D11_SUBRESOURCE_DATA));
      vinitdata.pSysMem = vertices;
  
      p_D3D11Device-&gt;CreateBuffer(&amp;bdsc, &amp;vinitdata, &amp;p_VertextBuffer);   
  
      /*D3D11_MAPPED_SUBRESOURCE ms;
      p_D3D11DeviceContext-&gt;Map(p_VertextBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &amp;ms);
      memcpy(ms.pData, vertices, sizeof(Vertex));
      p_D3D11DeviceContext-&gt;Unmap(p_VertextBuffer, NULL);*/
  
      INFO(L"InitGeometry() Complete");
  }
  
  void cSystem::InitPipeline(void)
  {   
  #if defined(DEBUG) || (_DEBUG)
      DWORD shaderflags = 0;
  #endif
      //p_D3D11Device-&gt;GetFeatureLevel() == D3D_FEATURE_LEVEL_11_0;
      ID3D10Blob *VS_, *PS_ = NULL;
      D3DX11CompileFromFile(L"Shader.shader", 0, 0, "VS", "vs_5_0", 0, 0, 0, &amp;VS_, 0, 0);
      D3DX11CompileFromFile(L"Shader.shader", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;PS_, 0, 0);
  
      p_D3D11Device-&gt;CreateVertexShader(VS_-&gt;GetBufferPointer(), VS_-&gt;GetBufferSize(), NULL, &amp;p_VS);
      p_D3D11Device-&gt;CreatePixelShader(PS_-&gt;GetBufferPointer(), PS_-&gt;GetBufferSize(), NULL, &amp;p_PS);
  
      p_D3D11DeviceContext-&gt;VSSetShader(p_VS, 0, 0);
      p_D3D11DeviceContext-&gt;PSSetShader(p_PS, 0, 0);
  
      D3D11_INPUT_ELEMENT_DESC layout[] =
      {
          { "POSITION", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
      };
      UINT NumElements = ARRAYSIZE(layout);
  
      p_D3D11Device-&gt;CreateInputLayout(layout, NumElements, VS_-&gt;GetBufferPointer(),
      VS_-&gt;GetBufferSize(), &amp;p_InputLayout);
  
      p_D3D11DeviceContext-&gt;IASetInputLayout(p_InputLayout);
  
      VS_-&gt;Release();
      PS_-&gt;Release();
  
      INFO(L"InitPipeline() Complete");
  }
  
  void cSystem::D3D11RenderFrame_(void)
  {
      // clear the back buffer
      p_D3D11DeviceContext-&gt;ClearRenderTargetView(p_D3D11RenderTargetView, m_BackBufferColour[0]);
      // clear the depth buffer
      p_D3D11DeviceContext-&gt;ClearDepthStencilView(p_D3D11DepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0.0f);  
  
      // draw 
      Draw(count++);
  
      // switch the back buffer and the front buffer
      p_D3D11SwapChain-&gt;Present(0, 0);
  }
  </code></pre>
  
  <p>The shader (or .fx file) is </p>
  
  <pre><code>struct VOut
  {
      float4 position : SV_POSITION;
      float4 color : COLOR;
  };
  
  VOut VS(float4 position : POSITION, float4 color : COLOR)
  {
      VOut output;
  
      output.position = position;
      output.color = color;
  
      return output;
  }
  
  
  float4 PS(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
  {
      return color;
  }
  </code></pre>
  
  <p>A link to a pic of the program is here : <a href="http://i.imgur.com/JyNkPqQ.png" rel="nofollow">http://i.imgur.com/JyNkPqQ.png</a></p>
  
  <p>The calls are made correctly in the execution of the program, but no display..
  Just in case my question is forgotten from the top, why isn't the triangle displaying?</p>
  
  <p>i hope someone can help.. :)</p>