5

使用此处的教程,我设法在屏幕上显示了一个红色三角形: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 但我不能说我明白如何将它从我的三角形获取到我想要的矩形:

在此处输入图像描述

考虑到我只想在它上面悬挂一些文本,有没有更好的方法来绘制矩形而不是使用四边形:

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

4

1 回答 1

9

我不得不扩展我的缓冲区以允许 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

于 2013-04-07T20:15:52.217 回答