|
刚接触Direct3D,不理解颜色的使用。
我是按照龙书的写法显示一个正方体的,使用8个顶点,36个索引
顶点结构如下:
struct ColorVertex
{
ColorVertex(){}
ColorVertex(float x, float y, float z, D3DCOLOR color)
{
_x = x;
_y = y;
_z = z;
_color = color;
}
float _x, _y, _z;
D3DCOLOR _color;
static const DWORD FVF;
};
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
如下创建8个顶点和36个索引。
Device->CreateVertexBuffer(
8 * sizeof(ColorVertex),
D3DUSAGE_WRITEONLY,
ColorVertex::FVF,
D3DPOOL_MANAGED,
&VB,
0);
Device->CreateIndexBuffer(
36 * sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&IB,
0);
如下显示
Device->SetStreamSource(0, VB, 0, sizeof(ColorVertex));
Device->SetIndices(IB);
Device->SetFVF(ColorVertex::FVF);
// Draw cube.
Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
采用fillmode的wireframe模式显示是正确的。但采用shademode的gouraud时
最终显示的正方体是全黑的。我想知道为什么。难道是采用索引顶点缓存的问题? [em5] |
|