Mixing 2D and 3D
One thing we need to know when mixing 2D and 3D is that the order of drawing is important. If we draw our 2D graphics last, they will be in front of our models. This can be necessary for the HUD (heads up display) for instance. A background however needs to be behind the model, so we need to draw it first.
Also, calling the End
method on a SpriteBatch
object doesn't reset the states. We need to do this manually, and if we don't, our model won't appear correctly. We need to set the blend state, the depth stencil state, and the sampler states before drawing the model. The blend state controls how colors are blended, or mixed, together. The depth stencil state controls how depth impacts rendering (if we don't set this, our model will have no depth). And finally, the sampler state defines how textures are sampled, including the method of filtering and level of detail.
graphics.GraphicsDevice.BlendState = BlendState.Opaque; graphics.GraphicsDevice.DepthStencilState =DepthStencilState...