|
|
LPDIRECT3DDEVICE9 pDevice = NULL;
ID3DXMesh * teapot;
D3DMATERIAL9 mat;
void InitTeapot()
{
D3DXCreateTeapot(pDevice, &teapot, 0);
D3DXCOLOR red( D3DCOLOR_XRGB(255,0,0));
D3DXCOLOR black(D3DCOLOR_XRGB(0,0,0));
mat = InitMaterial(red,red,red,black,1.0f);
pDevice->SetMaterial(&mat);
D3DXVECTOR3 dir(1.0f, -0.0f, 0.25f);
D3DXCOLOR c(D3DCOLOR_XRGB(255,255,255));
D3DLIGHT9 dirLight = InitDirectionalLight(&dir, &c);
pDevice->SetLight(0, &dirLight);
pDevice->LightEnable(0, true);
SetupPerspective();
SetupCamera();
pDevice->SetRenderState(D3DRS_LIGHTING,false);
pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
pDevice->SetRenderState(D3DRS_SPECULARENABLE, false);
}
void SetupCamera()
{
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 V;
D3DXMatrixLookAtLH(&V,&position,&target,&up);
pDevice->SetTransform(D3DTS_VIEW,&V);
}
void SetupPerspective()
{
D3DXMATRIX pro;
D3DXMatrixPerspectiveFovLH(&pro,D3DX_PI * 0.5f,nWindowWidth/nWindowHeight,1.0f,1000.0f);
pDevice->SetTransform(D3DTS_PROJECTION,&pro);
}
D3DMATERIAL9 InitMaterial(D3DXCOLOR a,D3DXCOLOR d,D3DXCOLOR s,D3DXCOLOR e,float p)
{
D3DMATERIAL9 mat;
mat.Ambient = a;
mat.Diffuse = d;
mat.Specular = s;
mat.Emissive = e;
mat.Power = p;
return mat;
}
bool Render(double time)
{
if (pDevice == NULL) return false;
pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,155,255), 1.0f, 0);
pDevice->BeginScene();
D3DXMATRIX tploc;
static double y = 0;
y += time;
D3DXMatrixRotationY(&tploc,y);
pDevice->SetTransform(D3DTS_WORLD,&tploc);
teapot->DrawSubset(0);
pDevice->EndScene();
pDevice-> resent(0, 0, 0, 0);
return true;
}
程序能够运行,但物体就是白色的,这是为什么啊?我好像没有地方出错啊 |
|