问题描述
我正在尝试实施第一人称射击游戏,在其中我需要查看狙击步枪的景象.我认为模板缓冲区对于实现狙击视图很有用.我正在努力做到这一点,但我无法做到.我经历了很多教程,但是它们只是使用模板缓冲区来讨论阴影,而且难以理解.
我试图做的是这样的:
1)禁用z缓冲区和颜色缓冲区
2)启用模板缓冲区
3)考虑到模具的功能和其他功能
Hi,
I am trying to implement a first person shooter game in which I need to make view for the sniper rifle. I thought stencil buffer can be useful to implement the sniper view. I am trying to make that but I am not able to get it. I went through lots of tutorials, but they just talk shadowing using stencil buffer, and are not understandable.
What I have tried to do is this:
1) disable the z buffer and color buffer
2) enable the stencil buffer
3) given the stencil fun val and other things
pd3dDevice->(SetRenderState(D3DRS_ZWRITEENABLE, false);
pd3dDevice->(SetRenderState(D3DRS_COLORWRITEENABLE, false);
pd3dDevice->(SetRenderState(D3DRS_STENCILENABLE, true);
pd3dDevice->(SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
pd3dDevice->(SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
pd3dDevice->(SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pd3dDevice->(SetRenderState(D3DRS_STENCILREF, 5);
pd3dDevice->(SetRenderState(D3DRS_STENCILMASK, 0);
然后我绘制我的模具形状(这是我绘制的四边形,是屏幕疏远的:pd3dDevice->renderQuad();
然后启用颜色和z缓冲区.请帮帮我,如果可能的话,请提供一些参考代码.
Then I am drawing my stencil shape (which is a quad- quad I am drawing is screen aliened:pd3dDevice->renderQuad();
Then I am enabling the color and the z buffer. Please help me out and if possible give some reference code.
推荐答案
g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_INCR );
这篇关于如何在DirectX中实现模具缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!