|
|
有一段时间没有弄 DX 了,现在居然忘记怎么绘制三角形了,下面是俺绘制的代码,各位有空顺便帮俺看看,那里出了问题。哪位有 D9 下绘制三角形的代码(没有用VS)能否给在下一份,俺看看到底出什么问题了。先谢谢各位了。
这是顶点格式,
struct SVertex
{
FLOAT x, y, z;
static DWORD FVF;
};
DWORD SVertex::FVF = D3DFVF_XYZ;
这是创建顶点的代码
g_pDirect3DDevice->CreateVertexBuffer( 3 * sizeof (SVertex),
0,
SVertex::FVF,
D3DPOOL_DEFAULT,
&g_pVertex,
NULL);
SVertex* pData = NULL;
g_pVertex->Lock(0, 3 * sizeof (SVertex), (void**)&pData, 0);
pData->x = 0.0f;
pData->y = 100.0f;
pData->z = 0.0f;
pData++;
pData->x = 150.0f;
pData->y = -250.0f;
pData->z = 0.0f;
pData++;
pData->x = -150.0f;
pData->y = -250.0f;
pData->z = 0.0f;
g_pVertex->Unlock();
这是渲染的代码
g_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 128), 1.0f, 0);
g_pDirect3DDevice->BeginScene();
g_pDirect3DDevice->SetStreamSource(0, g_pVertex, 0, 3 * sizeof (SVertex));
g_pDirect3DDevice->SetFVF(SVertex::FVF);
g_pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
g_pDirect3DDevice->EndScene();
g_pDirect3DDevice-> resent(NULL, NULL, hWnd, NULL);
[em4] [em4] [em4] [em4] [em4] |
|