title: Draw a rectangle with DX11
body: <p>I need to draw a simple rectangle (not a filled box) with directx 11.</p>
  <p>I have found this code:</p>
  <pre><code>    const float x = 0.1;
      const float y = 0.1;
      const float height = 0.9;
      const float width = 0.9;
      
     VERTEX OurVertices[] =
      {
          { x, y, 0, col },
          { x + width, y, 0, col },
          { x, y + height, 0, col },
          { x + width, y, 0, col },
          { x + width, y + height, 0 , col },
          { x, y + height, 0, col }
      };
  
      static const XMVECTORF32 col = { 1.f, 2.f, 3.f, 4.f };
  
      // this is the function used to render a single frame
      void RenderFrameTest(void)
      {
          // float color[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
          float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
      
          // clear the back buffer to a deep blue
          devcon-&gt;ClearRenderTargetView(backbuffer, color);
      
          // select which vertex buffer to display
          UINT stride = sizeof(VERTEX);
          UINT offset = 0;
      
           devcon-&gt;IASetVertexBuffers(0, 1, &amp;pVBuffer, &amp;stride, &amp;offset);
          // select which primtive type we are using
        //   draw the vertex buffer to the back buffer
          devcon-&gt;IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
          devcon-&gt;Draw(sizeof(OurVertices) / sizeof(VERTEX), 0);
        
          swapchain-&gt;Present(0, 0);
      
      }
      
      
  
     
      void DrawRectangle(float x, float y, float width, float height, XMVECTORF32 col)
      {
          D3D11_BUFFER_DESC bd;
          ZeroMemory(&amp;bd, sizeof(bd));
          bd.Usage = D3D11_USAGE_DYNAMIC;
          bd.ByteWidth = sizeof(OurVertices);
          bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
          bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
          HRESULT val = dev-&gt;CreateBuffer(&amp;bd, NULL, &amp;pVBuffer);                   // create the buffer
          D3D11_MAPPED_SUBRESOURCE ms;
          val = devcon-&gt;Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &amp;ms);   // map the buffer
          memcpy(ms.pData, OurVertices, sizeof(OurVertices));                      // copy the data
          devcon-&gt;Unmap(pVBuffer, NULL);
      }
  </code></pre>
  <p>but the result is not what I expected:</p>
  <p><a href="https://i.stack.imgur.com/ob9Ym.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ob9Ym.png" alt="enter image description here" /></a></p>
  <p>I suspect the problem is OurVertices array and &quot;D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP&quot; but I don't have have experience with DirectX in general.</p>
  <p>Can you help me please ?</p>