I have got simple 1x1x1 cube model. I draw 3 of them. They are located at:
1,0,0 2,0,0 3,0,0
I draw them in the same order every time. When I move the camera and look at them from one end everything is fine. If I look at them from the opposite end I can see parts of the cubes that should be occluded by the cubes.
How can I have them draw properly?
Answer
The reason why your draw order is messed up is probably because your depth buffer is not being used. With the depth buffer enabled the order in which you draw your meshes makes no difference.
And since you've just stated that you were using a SpriteBatch component, it pretty much confirms that this is the problem:
Quoting that article:
Before you draw anything in 3D you will probably want to reset these states:
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
Depending on your 3D content, you may also want to set:
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
In this case, the culprit is GraphicsDevice.DepthStencilState being set to None instead of Default.
No comments:
Post a Comment