D3D画线的颜色问题

xiaolizi xiaolizi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

我想在3D场景中画线,可是没有颜色(黑色)。我不知道哪儿弄错了。

另外D3DFVF_XYZRHW这个FVF标志是什么意思呢?MSDN上这么说
Vertex format includes the position of a transformed vertex. This flag cannot be used with the D3DFVF_XYZ or D3DFVF_NORMAL flags.
我还是不明白,transformed vertex到底是指什么?


根据例子,我是这么做的


#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)

LPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL; // Buffer to hold vertices

struct CUSTOMVERTEX
{
FLOAT x, y, z; // The transformed position for the vertex.
DWORD colour; // The vertex colour.
};

HRESULT InitialiseVertexBuffer()
{
VOID* pVertices;

//Store each point of the triangle together with it's colour
CUSTOMVERTEX cvVertices[] =
{
{0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255),}, {20.0f,0.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255),},
{0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0),},
{0.0f,20.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255),},
{0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0),},
{0.0f, 0.0f,20.0f, D3DCOLOR_XRGB(0, 0, 255),},
};

//Create the vertex buffer from our device
if(FAILED(g_d3ddevice.GetObject()->CreateVertexBuffer(6 * sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVertexBuffer,0)))
{
return E_FAIL;
}

if(FAILED(g_pVertexBuffer->Lock(0, sizeof(cvVertices), (void**)&pVertices, 0)))
{
return E_FAIL;
}

//Copy our stored vertices values into the vertex buffer
memcpy(pVertices, cvVertices, sizeof(cvVertices));

//Unlock the vertex buffer
g_pVertexBuffer->Unlock();

return S_OK;
}


void Render()
{
dev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);


dev->BeginScene();

D3DXMATRIX world_mat;
D3DXMatrixIdentity(&world_mat);

dev->SetTransform(D3DTS_WORLD, &world_mat);
dev->SetStreamSource(0, g_pVertexBuffer,0,sizeof(CUSTOMVERTEX));
dev->SetFVF(D3DFVF_CUSTOMVERTEX);
dev->DrawPrimitive(D3DPT_LINELIST, 0, 3);

dev->EndScene();

dev->Present(NULL, NULL, NULL, NULL);

}


...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
xiaolizi
游戏开发 8,323 成员 23,685 内容