[D3D]DrawPrimitive无法显示绘图问题code如下:constDWORDColorV


[D3D]DrawPrimitive无法显示绘图问题
code 如下:


const DWORD ColorVertex::FVF = D3DFVFXYZ | D3DFVFDIFFUSE;

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,D3DPOOLMANAGED,&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,D3DXPI * 0.5f,600/800,1.0f,1000.0f);

Device->SetTransform(D3DTS
PROJECTION,&proj);

//渲染模式
//Device->SetRenderState(D3DRSFILLMODE,D3DFILLWIREFRAME);

//屏蔽灯光
Device->SetRenderState(D3DRSLIGHTING,FALSE);




return TRUE;
}

BOOL Display(float timeDetal)
{

if (Device)
{

Device->Clear(0,0,D3DCLEAR
TARGET | D3DCLEARZBUFFER,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(D3DRSSHADEMODE,D3DSHADEFLAT);

Device->DrawPrimitive(D3DPTTRIANGLELIST,0,1);

D3DXMatrixTranslation(&world,1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS
WORLD,&world);

Device->SetRenderState(D3DRSSHADEMODE,D3DSHADEGOURAUD);

Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);


Device->EndScene();

Device->Present(0,0,0,0);

}

return TRUE;
}

进行了视图,投影,世界的转换,屏蔽了灯光,运行效果是:什么都没有,编译通过,请问是哪出问题?

游戏开发 程序开发 开发与设计

芙兰的胸罩 10 years, 12 months ago


把代码格式化一下啊, 这样看着头疼。

土御门春虎 answered 10 years, 12 months ago

Your Answer