Is it possible to draw to a texture with stencils enabled? And if so, what is the correct order of operations?
What I want to do is begin rendering to a target, set the stencil so that only some parts of the texture will be drawn to (I have a very complex mask that works fine when I draw to the target, then mask it when drawing to the HUD), then draw on the texture. At present I'm doing this then drawing directly to the HUD with surface.DrawTexturedRect, but I'm now trying to draw this texture (generated during DrawHUD) during a cam.Start3D2D event. All I'm getting is a black square or the stencil being drawn over my textures instead of actually stencil-ing them.
Something like this I think
[lua]
render.SetStencilEnable( true )
render.SetStencilFailOperation( STENCILOPERATION_KEEP )
render.SetStencilZFailOperation( STENCILOPERATION_KEEP )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS )
render.SetStencilWriteMask( 1 )
render.SetStencilReferenceValue( 1 )
-- Render your mask
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilTestMask( 1 )
-- Render your texture
render.SetStencilEnable( false )
[/lua]
That also yields only a black texture for me. The core of the problem might be that I'm trying to put a render.RenderView into it. I've gotten success with your method by first rendering to an unstencil'd texture then enabling stenciling and rendering that. Just dropping the RenderView in doesn't seem okay.
My question now is how to set the parts of the texture that aren't being drawn to to be transparent. They're just displaying whatever was last rendered there.
[url]https://facepunch.com/showthread.php?t=1337232&p=43271812#post43271812[/url]
this covers the order of steps taken to use stencils, but idk how rendertargets will play into it
I ended up solving this by drawing the full thing to the render target and then stenciling it in the Start3D2D function later.
Sorry, you need to Log In to post a reply to this thread.