我正在尝试通过D3DImage将Direct9引擎集成到新的WPF应用程序中。除Z缓冲区外,其他所有东西都在工作。使用FALSE的AutoDepthStencil,我可以渲染我的网格,但是深度不能正常工作。当我激活AutoDepthStencil时,什么也没画。我已经到处逛了好几天,什么也没找到
她的演示文稿参数
ZeroMemory( m_pp, sizeof(m_pp) );
m_pp->AutoDepthStencilFormat = D3DFMT_D16;
m_pp->BackBufferCount = 1;
m_pp->MultiSampleQuality = 0;
m_pp->Windowed = Windowed;
m_pp->MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
m_pp->EnableAutoDepthStencil = FALSE;
m_pp->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
m_pp->Windowed = TRUE;
m_pp->BackBufferHeight = 1;
m_pp->BackBufferWidth = 1;
m_pp->SwapEffect = D3DSWAPEFFECT_DISCARD;
m_pp->BackBufferFormat = D3DFMT_A8R8G8B8;
renderStates:
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_LIGHTING, TRUE); // turn off the 3D lighting
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50,50,50));
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_SPECULARENABLE, TRUE );
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); // both sides of the triangles
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZENABLE, TRUE); // turn on the z-buffer
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
m_graphics->GetDeviceD3D()->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
m_graphics->GetDeviceD3D()->LightEnable( 0, TRUE );
重置:
m_graphics->GetDeviceD3D()->Clear(0, NULL, D3DCLEAR_TARGET , D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
m_graphics->GetDeviceD3D()->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
表面和设备创建:
if (FAILED(m_pD3D9->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
dwVertexProcessing,
m_pp, NULL, GetDevicePtr())))
{
return NULL;
}
// obtain the standard D3D device interface
if (FAILED(GetDeviceD3D()->QueryInterface(__uuidof(IDirect3DDevice9), reinterpret_cast<void **>(GetDevicePtr()))))
{
return NULL;
}
// create and set the render target surface
// it should be lockable on XP and nonlockable on Vista
if (FAILED(GetDeviceD3D()->CreateRenderTarget(Width, Height,
D3DFMT_A8R8G8B8, D3DMULTISAMPLE_8_SAMPLES, 0,
false, // lockable
GetSurfacePtr(), NULL)))
{
return NULL;
}
GetDeviceD3D()->SetRenderTarget(0, m_surface);
矩阵:
// set the projection transform
D3DXMATRIX matProjection; // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45), // the horizontal field of view
1.f, // aspect ratio TODO
0.001f, // the near view-plane
1000.0f); // the far view-plane
m_graphics->GetDeviceD3D()->SetTransform(D3DTS_PROJECTION, &matProjection); // set the projection
//CAMERA
D3DXMATRIX matView;
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (m_scene->Cam->Position.X, m_scene->Cam->Position.Y, m_scene->Cam->Position.Z), // the camera position
&D3DXVECTOR3 (m_scene->Cam->Target.X, m_scene->Cam->Target.Y, m_scene->Cam->Target.Z), // the look-at position
&D3DXVECTOR3 (m_scene->Cam->UpVector.X, m_scene->Cam->UpVector.Y, m_scene->Cam->UpVector.Z)); // the up direction
d3ddev->m_device->SetTransform(D3DTS_VIEW, &matView); // set the view transform to matView
最佳答案
在EnableAutoDepthStencil设置为TRUE的情况下,确保CreateRenderTarget使用与演示文稿参数中设置的宽度和高度相同的宽度和高度