title: Drawing a rectangle in Direct X
body: <p>Using the tutorial here, I have managed to get a red triangle up on my screen: <a href="http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-4" rel="noreferrer">http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-4</a></p>
  
  <pre><code>CUSTOMVERTEX OurVertices[] =
  {
      { 0, 0, 0, 1.0f, D3DCOLOR_XRGB( 127, 0, 0 ) },
      { WIDTH, 0, 0, 1.0f, D3DCOLOR_XRGB( 127, 0, 0 ) },
      { 0, 300, 0, 1.0f, D3DCOLOR_XRGB( 127, 0, 0 ) },
      { WIDTH, 300, 0, 1.0f, D3DCOLOR_XRGB( 127, 0, 0 ) }
  };
  
  d3dDevice-&gt;CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
      0,
      CUSTOMFVF,
      D3DPOOL_MANAGED,
      &amp;vBuffer,
      NULL);
  
  VOID* pVoid;    // the void* we were talking about
  
  vBuffer-&gt;Lock(0, 0, (void**)&amp;pVoid, 0);    // locks v_buffer, the buffer we made earlier
  memcpy(pVoid, OurVertices, sizeof(OurVertices));    // copy vertices to the vertex buffer
  vBuffer-&gt;Unlock();    // unlock v_buffer
  
  d3dDevice-&gt;SetFVF(CUSTOMFVF);
  d3dDevice-&gt;SetStreamSource(0, vBuffer, 0, sizeof(CUSTOMVERTEX));
  d3dDevice-&gt;DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
  </code></pre>
  
  <p>But you can see that I really want to be drawing a rectangle.</p>
  
  <p>I have changed the Primitive to draw 2 triangles and extended the buffer size to 4*size of my custom vertex but I can't really say I understand how to get it from my triangle to my rectangle I would like:</p>
  
  <p><img src="https://i.stack.imgur.com/6syuA.jpg" alt="enter image description here"></p>
  
  <p>Is there a better way of drawing a rectangle rather than using a quad considering I just want to sling some text on top of it something like this:</p>
  
  <p><a href="http://1.bp.blogspot.com/-6HjFVnrVM94/TgRq8oP4U-I/AAAAAAAAAKk/i8N0OZU999E/s1600/monkey_island_screen.jpg" rel="noreferrer">http://1.bp.blogspot.com/-6HjFVnrVM94/TgRq8oP4U-I/AAAAAAAAAKk/i8N0OZU999E/s1600/monkey_island_screen.jpg</a></p>