How do you draw text?

Since the XNA documentation is lousy, I'm gonna ask here.

How do you create text in XNA I want to use it for debugging purposes :(



Answer this question

How do you draw text?

  • zocmer

    The XNA Framework in itself does not supply a way to draw text on the screen. You would have to either download a component to do it for you, like BitMapFont, or make one yourself. Or you could just create a text file with streamwriter, and put all the information you need to output in there.


  • Matt McQuillen

    I tried using BitmapFont myself, but even though I copied all the code correctly from the example into my program, it tells me it cannot find the font. I included the .xml file and the .png file in the project. Could somebody tell me a detailed explanation of everything I need for the font to work correctly I need to know what I have to include where, but I think the code is fine.


  • Angus Leeming

    Why not just use Console.WriteLine or System.Debug

  • Pramod_SN

    yeh its really helpful.. but did anyone else experiance the problem of their 3D models looking messed up i thought it was the face normals but it could also be the transparency on the model.. basically i can look through the model and see his feet from a top down perspective.

  • Ivan Tx

    Here you go -

    http://jubbernaut.blogspot.com/

    I've made a little blog to explain how to very quickly plot a font on screen. Including a font I drew with my own fair hand!

    The code has been simplified down to the bare minimum for ease of understanding - but a good font routine will have tons of options for transparency, scaling, kerning etc. And possibly different routines if you intend to plot a lot of text - some without the options to increase speed a little.

    I've lost count of the number of font routines I've written, from back when you had to redefine the character set using VDU 23 commands on the BBC micro. C# is the winner so far for easy to write code.

    Cheers,

    Robin Jubber


  • JoshMartin

    Quick note - someone (anonymous) posted a question on the blog above asking "where do the characters come from" - well, in answer to your question Mr. Anonymous - with a call to the function along the following lines -

    draw_font( x, y, "here is my text" );

    and it will print out the entire line. If you need to include numbers, for instance checking a variable -

    draw_font( x, y, "this variable is " + some_variable.ToString() );

    Hope that helps

    Cheers,

    Robin.


  • Fiddel

    The files are in a folder called Content in the project. They show up in the solution explorer.

    BitmapFont m_font;

    protected override void Initialize()
    {
    // TODO: Add your initialization logic here
    m_font = new BitmapFont("Content/times.xml");

    base.Initialize();
    }

    The error is thrown in the BitmapFont class after calling the BitmapFont constructor.


  • Luc Pettett

    Hey Mike... I downloaded your BitMapFont class and it works great.. the only issue is now that i started to use it my 3d models look funky. It looks like the normals are all inverted. any suggestions

    Thanks,

    Beck

  • BIGuy

    Yeh, bitmap font is great :)

    I use it so much I even made a static library and link it to my project every time I need it :D - I would use a DLL, but nobody likes those :|


  • VS2005_evaluator

    I use BitMapFont as well, and just dump the data to the screen so I can see how the data I want to watch in real time changes as I play test the game.

    BitMapFont is available here.

    Mike Polzin

    WilderLand Software


  • Vj5

    Thanks a lot, fellas. I already uses BitmapFont the first time one of you fellas posted a link.

    It works great. I use Comic :)


  • Sunkyu Hwang

    Where did you put the image and XML files Are they in a sub-folder in the project If so, did you include the sub-folder in your path in referencing them Can you post the relevant code

  • Jones Christopher

    If you're talking about mixing 2D and 3D see here.

  • Shapupu

    Thanks alot Jim.. that was just what I was looking for... works great!

    - Wes

  • How do you draw text?