Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to Understand Stencils (XNA 4.0, Windows Phone 7)
    text
    copied!<p>I'm trying to understand stencils. I could use a good tutorial explaining how they work, but in the mean time here's what I'm working with:</p> <pre><code>DepthStencilState _StencilAlways; DepthStencilState _StencilKeepIfZero; SpriteBatch _StencilBatch; SpriteBatch _MaskBatch; _StencilAlways = new DepthStencilState(); _StencilAlways.StencilEnable = true; _StencilAlways.StencilFunction = CompareFunction.Always; _StencilAlways.StencilPass = StencilOperation.Replace; _StencilAlways.ReferenceStencil = 1; _StencilAlways.DepthBufferEnable = false; _StencilKeepIfZero = new DepthStencilState(); _StencilKeepIfZero.StencilEnable = true; _StencilKeepIfZero.StencilFunction = CompareFunction.Equal; _StencilKeepIfZero.StencilPass = StencilOperation.Keep; _StencilKeepIfZero.ReferenceStencil = 0; _StencilKeepIfZero.DepthBufferEnable = false; RenderTarget2D MaskRenderTarget = new RenderTarget2D(device, Width, Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents); GraphicsDevice.SetRenderTarget(MaskRenderTarget); GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, new Color(0, 0, 0, 1), 0, 0); _MaskBatch.Begin(SpriteSortMode.Immediate, null, null, _StencilAlways, null); _MaskBatch.Draw( Texture, Position, null, Shade, 0, Vector2.Zero, Scale, SpriteEffects.None, 0); _MaskBatch.End(); _StencilBatch.Begin(SpriteSortMode.Immediate, null, null, _StencilKeepIfZero, null); _StencilBatch.DrawString( _Font, Line, Position2, Shade); _StencilBatch.End(); _RenderedTexture = MaskRenderTarget; GraphicsDevice.SetRenderTargets(null); </code></pre> <p>There might be some transposition/sanitation errors, but any ideas what I'm doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload