Model not rendering correctly XNA

Basically i am trying to render a model yet it seems to draw polygons that should be behind something, in front of it. So i end up seeing some faces that should be behind something, totally covering it. Bah, i suck at explaining so here's the pic:

See the Railing? It should be at the front, but it's covered by the top of the platform. Also, on the side, the shadowed area should be practically hidden from that front wall... Other bits are around the place too if you just look at it... :(

I tried the 3 different cull modes, none of them fixed it, so i don't think its the culling (in fact Clockwise made it worse... :P). Thanks for any help.

It looks like your depth buffer is not working. You should try something like:

device.RenderState.DepthBufferEnable = true;


I cant now test it, so this is just what I have googled. If it doesnt help, you can also try:

device.RenderState.DepthBufferFunction = CompareFunction.LessEqual;
device.RenderState.DepthBufferWriteEnable = true;

• Ahhh thankyou, the first solution was correct, however your code is shown in 3.1, i was using 4.0 :P So yes, the code i used was: DepthStencilState depthStencilState; depthStencilState = new DepthStencilState(); depthStencilState.DepthBufferEnable = true; device.DepthStencilState = depthBufferState;
– Joel
Oct 12 '11 at 5:46
• oh wow... that didn't come out in neat lines... :P hehe
– Joel
Oct 12 '11 at 5:46