使用此处的教程,我设法在屏幕上显示了一个红色三角形: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);
但是你可以看到我真的很想画一个矩形。
我已将 Primitive 更改为绘制 2 个三角形并将缓冲区大小扩展到自定义顶点的 4*size 但我不能说我明白如何将它从我的三角形获取到我想要的矩形:
考虑到我只想在它上面悬挂一些文本,有没有更好的方法来绘制矩形而不是使用四边形: