[D3D]DrawPrimitive无法显示绘图问题
code 如下:
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
IDirect3DDevice9* Device = NULL;
IDirect3DVertexBuffer9* VB = NULL;
D3DXMATRIX world;
struct ColorVertex
{
ColorVertex(){};
ColorVertex(float x,float y,float z,D3DCOLOR cl)
{
_x = x;_y = y;_z = z;_color = cl;
}
float _x,_y,_z;
D3DCOLOR _color;
static const DWORD FVF;
};
BOOL Setup()
{
Device->CreateVertexBuffer(3 * sizeof(ColorVertex),D3DUSAGE_WRITEONLY,ColorVertex::FVF,D3DPOOL_MANAGED,&VB,0);
ColorVertex* v;
VB->Lock(0,0,(void**)&v,0);
v[0] = ColorVertex(-1.0f,0.0f,2.0f,RED);
v[1] = ColorVertex(0.0f,1.0f,2.0f,GREEN);
v[2] = ColorVertex(1.0f,0.0f,2.0f,BLUE);
VB->Unlock();
//视图矩阵
D3DXVECTOR3 position(0.0f,0.0f,-5.0f);
D3DXVECTOR3 target(0.0f,0.0f,0.0f);
D3DXVECTOR3 up(0.0f,1.0f,0.0f);
D3DXMATRIX Vi;
D3DXMatrixLookAtLH(&Vi,&position,&target,&up);
Device->SetTransform(D3DTS_VIEW,&Vi);
//投影矩阵
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(&proj,D3DX_PI * 0.5f,600/800,1.0f,1000.0f);
Device->SetTransform(D3DTS_PROJECTION,&proj);
//渲染模式
//Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
//屏蔽灯光
Device->SetRenderState(D3DRS_LIGHTING,FALSE);
return TRUE;
}
BOOL Display(float timeDetal)
{
if (Device)
{
Device->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0xffffffff,1.0f,0);
Device->BeginScene();
Device->SetFVF(Vertex::FVF);
Device->SetStreamSource(0,VB,0,sizeof(Vertex));
D3DXMatrixTranslation(&world,-1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&world);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_FLAT);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
D3DXMatrixTranslation(&world,1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&world);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_GOURAUD);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
Device->EndScene();
Device->Present(0,0,0,0);
}
return TRUE;
}
进行了视图,投影,世界的转换,屏蔽了灯光,运行效果是:什么都没有,编译通过,请问是哪出问题?
[解决办法]
把代码格式化一下啊, 这样看着头疼。