mfc与D3D结合
我之前做了一个D3D的太阳系,关闭了天空盒zbuffer,天空盒跟着摄影机一起动,前后移动的话,看起来就只有那些星球在动,但是我把它跟mfc结合之后,可以正常显示,但是前后移动的话,看起来好像天空盒的zBuffer没关一样,移动一会星球就跑到天空盒外了,星球相对屏幕却一直不动,谁能告诉我为什么吗?(d3d的太阳系没什么错误,该注意的都注意了,且都正常运行,就是跟mfc结合之后出现了问题)下面附上天空盒部分代码
void CSkyBox::render(D3DXVECTOR3 CamPos)MFC d3d
{
m_pd3dDevice->GetTransform(D3DTS_WORLD, &m_OriWorldTransMatrix);
//关闭灯光
m_pd3dDevice->SetRenderState(D3DRS_LIGHTING,false);
//防止zbuffer写入
m_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,false);
m_pd3dDevice->SetRenderState(D3DRS_ZENABLE,false);
//纹理寻址方式:夹取纹理
m_pd3dDevice->SetSamplerState(0,D3DSAMP_ADDRESSU,D3DTADDRESS_CLAMP);
m_pd3dDevice->SetSamplerState(0,D3DSAMP_ADDRESSV,D3DTADDRESS_CLAMP);
//天空盒和摄影机一起移动
D3DXMATRIX world;
D3DXMatrixTranslation(&world,CamPos.x, CamPos.y, CamPos.z);
m_pd3dDevice->SetTransform(D3DTS_WORLD,&world);
m_pd3dDevice->SetStreamSource(0,m_pVB,0,sizeof(CUSTOMVERTEX1));
m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVETREX1);
m_pd3dDevice->SetIndices(m_pIB);
for(int i = 0; i < 6; ++i)
{
m_pd3dDevice->SetTexture(0, m_pTextrue[i]);
m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
0, // 将要绘制的索引缓冲区的起始地址
i*4, // 索引数组中最小的索引值
4, // 要绘制的索引数组中的顶点数量
i*6, // 从索引数组中的第几个元 素开始绘制图元
2); // 绘制的图元数量
}
//恢复默认属性
m_pd3dDevice->SetRenderState(D3DRS_LIGHTING,true);
m_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,true);
m_pd3dDevice->SetRenderState(D3DRS_ZENABLE,true);
m_pd3dDevice->SetSamplerState(0,D3DSAMP_ADDRESSU,D3DTADDRESS_WRAP);
m_pd3dDevice->SetSamplerState(0,D3DSAMP_ADDRESSV,D3DTADDRESS_WRAP);
m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_OriWorldTransMatrix);
}