XNA: Models drawn last visible from certain angles?

Started by
2 comments, last by Drakken255 11 years, 9 months ago
I have been challenging myself to make a basic port of Minecraft to XNA just for the fun of it, but have ran into this very confusing problem. When looking at a 3x3x3 grid of cube models, randomly textured, I find that at any time my camera is in a negative coordinate, some of the blocks which should not be visible are showing through. I think it's a view or projection problem, but it's all right by the offline samples I've seen. (I don't have Internet much ATM.) Here are my view and projection lines:
View = Matrix.CreateLookat(cameraPosition, cameraLookat, Vector3.Up);
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1f, 1000f);

Each block is its own class. View and Projection are passed every Draw call.

Let me know if anyone needs more information to solve this dilemma.
Advertisement
If depth buffer writing or testing are disabled, the objects you render last will draw over any other objects. This seems most likely given the symptoms, and will be the easiest thing to check first.
Sometimes XNA is so dumb. You would expect a library that makes things easier would have depth testing enabled by default... Also, my "Steve" model that I made is having problems: XNA is culling the outside head faces! I know how to turn cull mode off, but I'd rather have all models cull correctly. I made him with Blender 2.6 and exported to fbx. Should I just export as obj to Max and export there?

EDIT: My Steve model's head face normals were somehow wrong in Blender, so I got them flipped and solved. And the depth buffer is not the problem. Could it be my model files being exported all screwy by Blender?
Ladies and Gentlemen: I have solved the problem. SpriteBatch screws up a bunch of graphics settings when Begin is called, namely the DepthStencilState. I thought setting the state to Default didn't work because I did that in LoadContent, when SpriteBatch changes it every frame. I now realize that I must change it back every frame.

This topic is closed to new replies.

Advertisement