Hey guys,
Im trying to make a texture mask using stencil test on directx9, but for some reason i didnt understand totally stencil yet, or im doing something wrong.
My code it's:
renderDevice.GetDevice()->SetRenderState( D3DRS_COLORWRITEENABLE, 0 );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILENABLE, true );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILREF, 0 );
/*renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILMASK, 0xFFFFFFFF );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILWRITEMASK, 0xFFFFFFFF );*/
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_REPLACE );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
---(drawing mask image)
renderDevice.GetDevice()->SetRenderState( D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_EQUAL );
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_ZERO );
renderDevice.GetDevice()->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0 );
--(drawing object that i want to clipping)
renderDevice.GetDevice()->SetRenderState( D3DRS_STENCILENABLE, false );
I have a png image, where the black part it's i want to clip, but when i run the code, never happens, keep rendering entire object.
(ah, i was trying to follow this tutorial: https://research.ncl.ac.uk/game/mastersdegree/graphicsforgames/scissorsandstencils/Tutorial%205%20-%20Scissors%20and%20Stencils.pdf)
Thanks.