Using the tutorial here, I have managed to get a red triangle up 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 be drawing a rectangle.
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:
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:
{(-2, 2, 0), (2, 2, 0), (2, 1, 0), (-2, 1, 0)}
(top left, top right, bottom right, bottom left) and your index buffer might contain{(0, 1, 3), (3, 1, 2)}
(TL, TR, BL, followed by BL, TR, BR). The index buffer just tells it which vertices come in which order. You should be aware of whether it's CW or CCW as well for culling. You have to do some additionSetIndexBuffer
etc. with it as well. Forgive me, since it's been a while since I've done that, and I never liked those as much as the premade mesh functions. – RoguishD3DXCreateSphere
and I know there's a cube and a teapot one as well. It would probably be easier just to make a cube mesh with no depth (if it lets you; otherwise a very small depth) and live with the extra ten triangles, but I'd say it's worth learning how to do right, and I'm no expert. – Roguish