1

I have problem when I draw a string in XNA 4.0 3D.I known problem is spriteBatch.Begin(). But I don't know how to solve it.

protected override void Draw(GameTime gameTime)
{
  GraphicsDevice.Clear(Color.DeepSkyBlue);
  //Draw string 
  spriteBatch.Begin();
  spriteBatch.DrawString(fontArial, "Demotesting", new Vector2(100, 100), Color.Red);
  spriteBatch.End();
  //Draw Models Ship
  ship.Draw();

  base.Draw(gameTime);
}

Before draw string: http://nq1.upanh.com/b4.s32.d1/6c6ce19bded8d054341ce45e17426c51_49358001.before.png

After draw string: http://nq2.upanh.com/b6.s30.d2/9ff7c3c009215348b06a53c5a067d282_49358002.after.png

0

2 Answers 2

2

Put this at the top of you draw method:

GraphicsDevice.BlendState = BlendState.AlphaBlend;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

And that should solve it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks your answer, I'm success Draw text 2D in 3D
@user1690759 It is customary to accept the answer that solves the question asked. This is how stackoverflow works!
0

The sprite batch mucks around with some rendering settings, you'll need to google around to find out what to set, I'd start by enabling the depth buffer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.