问题
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?
Here's the see through wall declaration:
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)));
Culling is set to None and x2,x1,z1,z2 are vertices positions. Any thoughts?
Thank you
回答1:
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;
来源:https://stackoverflow.com/questions/26130016/xna-textured-primitives-are-see-through