我的 XNA 立方体有什么问题? [英] What's wrong with my XNA cube?

查看:30
本文介绍了我的 XNA 立方体有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 这个示例 尝试构建在上面.我将代码合并到我的解决方案中,这是一个 Windows 窗体应用程序(使用 XNA 有点棘手).

I'm following this sample trying to build on it. I incorporated the code into my solution, which is a windows form app (a little tricky w/ XNA).

当我终于得到一个立方体来画它时,它是由内向外……还是由外向内……或者?自己看看.

When I finally got a cube to draw it ended up inside out... or outside in... or? See for yourself.

该应用程序现在有几千行,所以我无法将其粘贴到此处.我需要知道从哪里开始寻找.

The app is now several thousand lines so I can't paste it here. I'll need to know where to start looking.

知道这里出了什么问题吗?

Any idea what's wrong here?

看起来两边的画乱了……但这应该无关紧要.图形引擎应该确定什么是可见的,什么是不可见的,但它似乎出错了.

It looks like the sides are getting drawn out of order... but that shouldn't matter. The graphics engine should determine what's visible and what's not visible but it seems to be getting it wrong.

提前致谢.

推荐答案

有一个名为 GraphicsDevice 的 XNA Framework 类,它包含基本渲染参数的所有属性.

There is an XNA Framework class called GraphicsDevice which contains all of the properties for the basic rendering parameters.

GraphicsDevice 内部有一个成员结构体 DepthStencilState,需要配置以下属性:

Inside GraphicsDevice there is a member struct DepthStencilState which needs to be configured with the following attributes:

  • DepthBufferEnable=true
  • DepthBufferFunction=LessThanEqual
  • DepthBufferWriteEnable=true

最简单的方法是简单地将其设置为静态定义的默认值.

The easiest way is to simply set it to the statically defined Default.

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

如果您仍然遇到问题,请确保您要渲染到的 RenderTarget 是支持深度的纹理.示例:

If you are still having problems, make sure the RenderTarget to which you are rendering is a texture that supports depth. Example:

finalFrameRT = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);

如果您不想看到背面的背面,则需要根据顶点索引的顺序将 RasterizerState 设置为 CullClockwise 或 CullCounterClockwise.

If you do not wish to see the backs of rear-facing sides, you need to set RasterizerState to CullClockwise or CullCounterClockwise according to the order of your vertex indices.

这篇关于我的 XNA 立方体有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆