gpt4 book ai didi

c# - 尝试理解模板(XNA 4.0、Windows Phone 7)

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:27 26 4
gpt4 key购买 nike

我正在尝试理解模板。我可以使用一个很好的教程来解释它们是如何工作的,但与此同时,我正在使用的是:

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 都绑定(bind)了它。

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

关于c# - 尝试理解模板(XNA 4.0、Windows Phone 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5781345/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com