XNA 纹理图元是透明的 [英] XNA Textured primitives are see-through

查看:34
本文介绍了XNA 纹理图元是透明的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XNA 上遇到原语问题.正如你在链接中看到的,http://imgur.com/12UTd2s,一些有纹理的墙被看到-通过,有些不是.有人可以解释为什么会发生这种情况并帮助我提出解决方案吗?

I'm having a problem with primitives on XNA. As you can see in the link, http://imgur.com/12UTd2s, some of the textured walls are see-through and some aren't. Can someone explain why this happens and help me come up with a solution?

这是透明墙声明:

testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2), new Vector3(1, 0, 0), new Vector2(0,0)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,0)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2), new Vector3(1, 0, 0), new Vector2(0,1)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2), new Vector3(1, 0, 0), new Vector2(0,1)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,1)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,0)));

这是我看不到的墙的声明:

And here's the declaration of a wall I can't see through:

testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1 - 50), new Vector3(-1, 0, 0), new Vector2(0,1)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1), new Vector3(-1, 0, 0), new Vector2(0,0)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1 - 50), new Vector3(-1, 0, 0), new Vector2(1,1)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1 - 50), new Vector3(-1, 0, 0), new Vector2(1,1)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1), new Vector3(-1, 0, 0), new Vector2(1,0)));
                    testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1), new Vector3(-1, 0, 0), new Vector2(0,0)));

剔除设置为无,x2,x1,z1,z2 是顶点位置.有什么想法吗?

Culling is set to None and x2,x1,z1,z2 are vertices positions. Any thoughts?

谢谢

推荐答案

原因不是因为它们是透明的,而是因为你没有启用深度缓冲,所以墙会按照它们出现的顺序出现'重新绘制(从下到上).

The reason is not because they're see-through, but rather because you do not have depth buffering enabled, so the walls will appear in the order they're drawn (bottom to top).

在渲染之前,您需要设置渲染状态:

Prior to rendering you'll want to set the render state:

Renderer.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

这篇关于XNA 纹理图元是透明的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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