深度
深度测试
声明变量ID3DXMesh* box = 0;
ID3DXMesh* wall = 0;
设置网格D3DXCreateBox(g_pd3dDevice, 8, 8, 8, &box, NULL);
D3DXCreateBox(g_pd3dDevice, 10, 10, 0.5f, &wall, NULL);
开启深度测试g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, true);
刷新深度缓存(这段有没有一个卵样)g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
开启深度前
开启深度后
没有效果?
D3DPRESENT_PARAMETER结构下加上下面代码d3dpp.EnableAutoDepthStencil = true; //自动管理深度缓存
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; //24位像素深度值
渲染前加上//其中清除深度缓存
g_pd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0L);