Jump to content
  • Advertisement
Sign in to follow this  

Stencil masking

This topic is 4903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am attempting to use the stencil buffer as a mask. I am trying to make a magnifying glass which moves about. as it does, it displays a normally hidden textured poly (the magnified image). I am trying to enable the stencil buffer, draw a shape to represent the magnifying glass lens, then draw the textured poly, masked by the stencil buffer. No luck so far..... I think i am missing the obvious....any ideas?
   device->SetRenderState(D3DRS_STENCILENABLE,    true);
    device->SetRenderState(D3DRS_STENCILFUNC,      D3DCMP_ALWAYS);
    device->SetRenderState(D3DRS_STENCILREF,       0x1);
    device->SetRenderState(D3DRS_STENCILMASK,      0xffffffff);
    device->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
    device->SetRenderState(D3DRS_STENCILZFAIL,     D3DSTENCILOP_KEEP);
    device->SetRenderState(D3DRS_STENCILFAIL,      D3DSTENCILOP_KEEP);
    device->SetRenderState(D3DRS_STENCILPASS,      D3DSTENCILOP_REPLACE);
    device->SetRenderState(D3DRS_ZWRITEENABLE, false);
    device->SetRenderState( D3DRS_LIGHTING, FALSE );
    device->SetTransform( D3DTS_WORLD, &magStencilTrans );
    magStencil->DrawSubset( 0 );  //a mesh sphere defining the lens size
    device->SetRenderState( D3DRS_ZWRITEENABLE, true );

    device->SetRenderState(D3DRS_STENCILFUNC,  D3DCMP_EQUAL);
    device->SetRenderState(D3DRS_STENCILPASS,  D3DSTENCILOP_KEEP);

    device->SetTexture(0, g_pFossil);
    device->SetStreamSource(0, magVB, 0, sizeof(Vertex));
    device->SetFVF( Vertex::FVF_Flags );

    device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); //draw the fossil, masked?

    device->SetRenderState( D3DRS_STENCILENABLE, false);
thanks in advance Si

Share this post

Link to post
Share on other sites
What's the problem, I mean what does the output look like?
Another (stupid?) question, did you create a depth surface with a stencil buffer?

I didn't see any problem with you render state setup, provided that the matrices and primitives are in order.

Share this post

Link to post
Share on other sites
haha yeah good point - the problem is that the shape i am trying to render onto the stencil and the masked image are normally rendered.

Share this post

Link to post
Share on other sites
Another stupid question :) , are you sure that you're clearing the stencil buffer? If yes, are you sure you're not clearing it to one?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!