我正在尝试了解模具。我可以使用一个很好的教程来解释它们的工作原理,但与此同时,这是我正在使用的方法:

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);


可能会有一些换位/卫生错误,但是有什么想法我做错了吗?

最佳答案

我建议搜索与XNA / Windows Phone无关的模板缓冲区。最后,这些值或用法完全相同。

所有图形卡都支持的基本功能以及DirectX和OpenGL都具有绑定功能。

http://en.wikipedia.org/wiki/Stencil_buffer
要么
http://www.google.cz/search?q=stencil+buffer

10-08 14:21