我正在尝试在 DirectX 10 中制作自定义 HUD 系统。我当前的攻击方法是简单地使用网格树来表示不同级别的菜单。
我相信通过禁用深度测试,我可以制作一个网格,并将其粘贴在背景中的 3d 世界的其余部分之上。为了实现这一点,我尝试使用 D3D10_DEPTH_STENCIL_DESC 将 DepthEnable 选项设置为 false。然后我将这个 D3D10_DEPTH_STENCIL_DESC 绑定到一个模板状态,然后在我绘制网格之前激活它。到目前为止,这给我留下了一个缺失的网格。
我的问题真的可以归结为:我是否走在正确的轨道上,或者我是否需要完全重新考虑这一点?此外,如果这是一个很好的解决这个问题的计划,有什么我忘记考虑的吗?
以下是我尝试获取此 HUD 的代码片段
创建 D3D10_DEPTH_STENCIL_DESC:
//HUD Elements
D3D10_DEPTH_STENCIL_DESC dsDesc;
//Depth Settings
dsDesc.DepthEnable = false;
dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
dsDesc.DepthFunc = D3D10_COMPARISON_LESS;
//Stencil settings
dsDesc.StencilEnable = true;
dsDesc.StencilReadMask = 0xff;
dsDesc.StencilWriteMask = 0xff;
//Always pass the stencil test, and replace the current stencil value with
// the stencil reference value 1
dsDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
dsDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_REPLACE;
dsDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
// We are not rendering backfacing polygons, so these settings do not matter.
dsDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
dsDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
dsDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_REPLACE;
dsDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
//Bind HUD to a stencil
HR(md3dDevice->CreateDepthStencilState(&dsDesc,&hud));
绘制我只是这样做:
md3dDevice->OMSetDepthStencilState(hud, 1);
menu.draw(mVP);