Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a model which draws correctly in XNA4.

However if I try to add a background image (or any sprite), the rendering of my model is messed up. There are two problems with the rendering

  1. model is partially transparent
  2. hidden surfaces are visible.

This is the 'problem' rendering Above is the 'problem' rendering (the cyan coloured cockpit cover is visible through the bottom of the ship)

This is how the rendering *should* look This is how the rendering should look

share|improve this question
add comment

1 Answer 1

The problem is caused by the SpriteBatch.Begin() changing some of the rendering states.

This problem is solved in XNA 3.1 and earlier by using the SaveState flag (see this answer).

However in XNA 4.0+ you need to restore the state yourself.

Insert the following code after your sprite drawing but before your model drawing (or 3D primitive drawing)

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

Information based on original article by Shawn Hargreaves

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.