Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

C++
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);


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.
Posted
Updated 19-Mar-10 9:34am
v5

1 solution

Try to add this line:
g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_INCR );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900