Sign in to follow this  

Stencil masking

This topic is 4598 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
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

This topic is 4598 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this