XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Outputting text with XNA in 3D

Last post 16/04/2009 13:01 by Teradil. 5 replies.
  • 14/04/2009 18:02

    Outputting text with XNA in 3D

    Hey folks, I worked through the 3D tutorial and wanted to add score to the "game". So I included a SpriteFont object and loaded a simple .spritefont file. All okay, but when I try to display the text, the terrain is cut off, if I draw the text after the terrain. If I draw the text before the terrain, the text simply does not appear, which is clear to me, as the terrain is drawn above the text... What can I do to fix this problem?
  • 14/04/2009 18:15 In reply to

    Re: Outputting text with XNA in 3D

    Teradil:
    Hey folks, I worked through the 3D tutorial and wanted to add score to the "game". So I included a SpriteFont object and loaded a simple .spritefont file. All okay, but when I try to display the text, the terrain is cut off, if I draw the text after the terrain. If I draw the text before the terrain, the text simply does not appear, which is clear to me, as the terrain is drawn above the text... What can I do to fix this problem?
    You are changing states and not resetting them.

    Use the proper option in your SpriteBatch.Begin call.
  • 14/04/2009 18:31 In reply to

    Re: Outputting text with XNA in 3D

    The tutorial doesn't use a spriteBatch at all. So I just used a spriteBatch.Begin(); spriteBatch.DrawString(font, pointsString + points, fontPosition, Color.CadetBlue, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f); spriteBatch.End();
  • 14/04/2009 18:37 In reply to

    Re: Outputting text with XNA in 3D

    Teradil:
    The tutorial doesn't use a spriteBatch at all. So I just used a spriteBatch.Begin(); spriteBatch.DrawString(font, pointsString + points, fontPosition, Color.CadetBlue, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f); spriteBatch.End();
    You are changing states and not resetting them. Use the proper option in Spritebatch.Begin().
  • 14/04/2009 19:33 In reply to

    Re: Outputting text with XNA in 3D

    I'm not 100% sure about this but try these options (draw the text after the terrain)

    </div><div>            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None);</div><div>


    SaveStateMode.None means you'll most likely have to set render states yourself.  I hear it's much faster to set your states manually that to use the default SaveStateMode.SaveState

    When you use SpriteBlendMode.AlphaBlend a lot of states are set that you might not want elsewhere.   

    This page made sense of everything when I had problems : http://blogs.msdn.com/shawnhar/archive/2006/11/13/spritebatch-and-renderstates.aspx
    Steve Mulligan
    Pwned - Multiplayer Chess for XBLIG
  • 16/04/2009 13:01 In reply to

    Re: Outputting text with XNA in 3D

    Thanks Steve, that answer helped a lot! I assumed spriteBatch.End() would revert such changes so 2D + 3D would be working together. Thanks a lot!
Page 1 of 1 (6 items) Previous Next