1

When I tried adding text to my MonoGame program, I encountered a problem. It stopped rendering 3D objects properly, cutting front faces on some, not displaying others altogether.

I've tried ending the batch after drawing the models too, to the same effect

public override void Draw(GameTime gameTime)
    {
        spriteBatch.Begin();
        string output = "Score";

        spriteBatch.DrawString(spriteFont, output, Vector2.Zero, Color.LightGreen,
            0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

        spriteBatch.End();
        foreach (BasicModel model in models)
        {
            model.Draw(((Game1)Game).GraphicsDevice, ((Game1)Game).mainCamera);
        }
        base.Draw(gameTime);
    }

Why is my text implementation screwing up my 3D models?

Gnemlock
  • 325
  • 6
  • 22
Corpserule
  • 13
  • 5
  • 1
    The last parameter in the `DrawString()` method is the depth. `0.5f` means, you render it right in the middle between the nearplane and the farplane. So maybe your rendered text is just intersecting your objects in the scene? Try a value of `0.0f` just for test and check, if the result changes. – LInsoDeTeh Sep 11 '15 at 07:20
  • Attempted. no success. Thx for the suggestion, i overlooked that. – Corpserule Sep 11 '15 at 08:41

1 Answers1

2

SpriteBatch.Begin() changes some grapic pipeline render states in a way that is best for 2d rendering but not for 3d rendering.

So after rendering your 2d, you need to reset those states for the 3d rendering.

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

Now your 3d will draw fine. See this link for more info.

Add those 2 lines between your spriteBatch.End() and your foreach()

Steve H
  • 5,479
  • 4
  • 20
  • 26