Draw a rectangle in Direct X

Using the tutorial here, I managed to get a red triangle on my screen: http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-4

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->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
    0,
    CUSTOMFVF,
    D3DPOOL_MANAGED,
    &vBuffer,
    NULL);

VOID* pVoid;    // the void* we were talking about

vBuffer->Lock(0, 0, (void**)&pVoid, 0);    // locks v_buffer, the buffer we made earlier
memcpy(pVoid, OurVertices, sizeof(OurVertices));    // copy vertices to the vertex buffer
vBuffer->Unlock();    // unlock v_buffer

d3dDevice->SetFVF(CUSTOMFVF);
d3dDevice->SetStreamSource(0, vBuffer, 0, sizeof(CUSTOMVERTEX));
d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

But you can see that I really want to draw a rectangle.

I changed the primitive to draw 2 triangles, and increased the buffer size to 4 * the size of my user vertex, but I cannot say that I understand how to get it from my triangle to my rectangle. I would like to:

enter image description here

Is there a better way to draw a rectangle rather than use a quad, given that I just want to move some text on top of it like this:

http://1.bp.blogspot.com/-6HjFVnrVM94/TgRq8oP4U-I/AAAAAAAAAKk/i8N0OZU999E/s1600/monkey_island_screen.jpg

+5
source
1

, 4 :

d3dDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX),
    0,
    CUSTOMFVF,
    D3DPOOL_MANAGED,
    &vBuffer,
    NULL);

TRIANGLELIST STRIP, , 2

d3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 0, 2 );

: http://www.mdxinfo.com/tutorials/tutorial4.php

+8

All Articles