Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C&x2B中的DirectX 10 HUD+;_C++_Directx_Directx 10 - Fatal编程技术网

C++ C&x2B中的DirectX 10 HUD+;

C++ C&x2B中的DirectX 10 HUD+;,c++,directx,directx-10,C++,Directx,Directx 10,我正在尝试在DirectX 10中制作一个自定义HUD系统。我目前的攻击方法是简单地使用网格树来表示菜单的不同级别 我相信,通过禁用深度测试,我可以制作一个网格,它粘贴在背景中我的3d世界的其余部分之上。为了实现这一点,我尝试使用D3D10_DEPTH_STENCIL_DESC,将DepthEnable选项设置为false。然后我将D3D10_DEPTH_STENCIL_DESC绑定到一个模具状态,然后在绘制网格之前激活该状态。到目前为止,这给我留下了一个缺失的网格 我的问题真的可以归结为:我是

我正在尝试在DirectX 10中制作一个自定义HUD系统。我目前的攻击方法是简单地使用网格树来表示菜单的不同级别

我相信,通过禁用深度测试,我可以制作一个网格,它粘贴在背景中我的3d世界的其余部分之上。为了实现这一点,我尝试使用D3D10_DEPTH_STENCIL_DESC,将DepthEnable选项设置为false。然后我将D3D10_DEPTH_STENCIL_DESC绑定到一个模具状态,然后在绘制网格之前激活该状态。到目前为止,这给我留下了一个缺失的网格

我的问题真的可以归结为:我是在正确的轨道上,还是我需要重新思考这个问题?此外,如果这是一个很好的解决这个问题的计划,有什么我忘记考虑的吗

下面是我试图获取这个HUD的代码

创建D3D10_DEPTH_模具描述:

    //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);

是的,你说对了。但要记住的是,如果菜单系统是分层的,那么你必须向后拉,因为Z缓冲区帮不了你。这将意味着相当多的透支

另一种解决方案允许您通过使用Z缓冲区(尤其是使用早期的Z缓冲区拒绝硬件支持)和前后绘图来限制透支量。但是,您会遇到与场景交互的问题。只需在呈现菜单之前清除Z缓冲区,即可轻松解决此问题

TBH尽管您最好使用Z缓冲区清除方法,因为这意味着您可以更高效地批处理一起绘制调用。ie不断地映射和填充ID3D10Buffer比一次然后不断地重新绘制要慢。当然,当状态改变时,您可能需要编辑缓冲区,但您可以限制编辑缓冲区的数量,并且在没有状态改变时,您不会不必要地对CPU进行检查