|
[em21]渲染后,一片空白,没见到如期的2个彩色三角形,code如下
//顶点结构体
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;
};
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
IDirect3DDevice9* Device = NULL;
IDirect3DVertexBuffer9* VB = NULL;
D3DXMATRIX world;
BOOL Setup()
{
Device->CreateVertexBuffer(3 * sizeof(ColorVertex),D3DUSAGE_WRITEONLY,ColorVertex::FVF,D3DPOOL_MANAGED,&VB,0);
ColorVertex* v;
VB->Lock(0,sizeof(ColorVertex),(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_LIGHTING,FALSE);
return TRUE;
}
BOOL Display(float timeDetal)
{
if (Device)
{
Device->Clear(0,0,D3DCLEAR_TARGET,0xffffffff,1.0f,0);
//开始渲染
Device->BeginScene();
Device->SetFVF(ColorVertex::FVF);
Device->SetStreamSource(0,VB,0,sizeof(ColorVertex));
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-> resent(0,0,0,0);
}
return TRUE;
}
查看别人的类似也一样的渲染,为什么这里渲染不出来,环境:P8400,9600GM,WIN7 64,在线等 |
|