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 just want to render some text to the screen using:

  • monogame 3.0
  • MS Visual Studio 2010 C# Express

In XNA, you were able to add fonts to the content pipeline quite easily. But this doesn't seem to be the case in monogame. Loading TTF Files using Content<SpriteFont>.Load() doesn't work. Is there any way to generate or download *.spritefont files or *.xnb files containing the font data (without resorting to install XNA)?

share|improve this question
    
I also had a lot of problems figuring this out, this tutorial helped me out a whole lot. youtube.com/watch?v=BwtQn02oy6A –  user29722 Apr 19 '13 at 8:11
add comment

7 Answers

up vote 3 down vote accepted

An alternative is to use pre-generated bitmap fonts instead. Here's a tutorial I wrote a while back on using the BMFont tool to get text into your game.

http://www.craftworkgames.com/blog/tutorial-bmfont-rendering-with-monogame/

share|improve this answer
    
Although I'm not 100% satisfied with this solution, I guess I'll go with bitmap fonts for now and hope for the best in the near future. –  Khôi Dec 25 '12 at 11:37
add comment

I ran into the same problem as you. Thankfully, I had an existing XNA project that already used a .spritefont file, and generated the XNB file. I just compiled it, and copied the XNB into my MonoGame project, and I can use it without any problems.

(Disclaimer: I tried building the XNA content pipeline for MonoGame 3.0 beta as per instructions, and after a few hours, I gave up; it wouldn't include the project properly in Visual Studio.)

share|improve this answer
    
Thanks for tip. Good to know that you can work around it like this. –  Khôi Dec 25 '12 at 11:33
    
@Khôi it's not perfect, but it can at least get you somewhere while you figure out how to integrate the content pipeline project. –  ashes999 Dec 25 '12 at 15:11
add comment

At least in August this year generating spritefonts was not yet supported by MonoGame, however the content pipeline was the main focus of attention the last few months so I wouldn't be surprised if it does work currently. Of course you need to know the syntax of a .spritefont file which needs to be added to your content folder. For that see the bottom of this post.

As far as I can tell, even as far back as August, the loading of already compiled spritefonts from XNB files is supported. Since you don't want to install XNA to generate these XNB files you might want to check the XNA Content Compiler Project on codeplex.

Here is an example .spritefont file so you can see if it's currently supported

<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="Graphics:FontDescription">

    <!--
    Modify this string to change the font that will be imported.
    -->
    <FontName>Arial</FontName>

    <!--
    Size is a float value, measured in points. Modify this value to change
    the size of the font.
    -->
    <Size>10</Size>

    <!--
    Spacing is a float value, measured in pixels. Modify this value to change
    the amount of spacing in between characters.
    -->
    <Spacing>0</Spacing>

    <!--
    UseKerning controls the layout of the font. If this value is true, kerning information
    will be used when placing characters.
    -->
    <UseKerning>true</UseKerning>

    <!--
    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
    and "Bold, Italic", and are case sensitive.
    -->
    <Style>Regular</Style>

    <!--
    If you uncomment this line, the default character will be substituted if you draw
    or measure text that contains characters which were not included in the font.
    -->
    <!-- <DefaultCharacter>*</DefaultCharacter> -->

    <!--
    CharacterRegions control what letters are available in the font. Every
    character from Start to End will be built and made available for drawing. The
    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
    character set. The characters are ordered according to the Unicode standard.
    See the documentation for more information.
    -->
    <CharacterRegions>
      <CharacterRegion>
        <Start>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>
share|improve this answer
    
As of now (25.12.2012 - merry xmas!), spritefonts are not supported by monogame 3.0 yet. I just tried it out according to your instructions. –  Khôi Dec 25 '12 at 11:27
    
The XNA Content Compiler won't run for me either. Since it seems you need to have XNA installed to run the content compiler. The XNA Content Compiler builds a dummy project using XNA in the background to compile .xnb files. –  Khôi Dec 25 '12 at 11:31
    
@Khôi Merry Christmas to you too :). Strange that the project requires XNA installed, makes it quite useless for most scenarios! –  Roy T. Dec 25 '12 at 11:50
    
It's not strange, nor useless. MonoGame needs its own content pipline to support other platforms, like Android. This is a temporary xrutch--piggyback off the XNA content pipeline. –  ashes999 Dec 25 '12 at 15:12
add comment

I have been working on this for several days now, trying to fix this and eventually i got i to work. What i am working on is Windows8, VS2012, MonoGame. i should add that this is as "monoGame Windows OpenGL Pjoject"

Let me take you through the steps i have taken. 1. I installed monGame for VS2012 2. I installed WindowsPhone SDK8 3. I installed XNA 4.0 for my VS2010

I dont know if all these steps are nessecery....

Sence you cant generate a .spritefont in vs2012 I generated a spriteFont file in my vs2010 and then added i to my vs2012 project....BUT it did not work. And this morning I saw that the URL for that .spritefont file was wrong. When i added it through solution explorer..content-->add exsisting item...then the url was wrong.. "C:\Users\admin\Documents\Visual Studio 2012\Projects\MyGame\MyGame\Content" this is not where vs2012 where looking for my *.spritefot file it was here..--> "C:\Users\admin\Documents\Visual Studio 2012\Projects\MyGame\MyGame\bin\WindowsGL\Debug\Content" I added i manully, and WOW it worked. i paste some code here so you better can see what i have done.. inside my game class i put these variables

    SpriteFont myFont;
    int score;

in my loadcontent method autogenerated by VS was

    myFont = Content.Load<SpriteFont>("test");

in my draw method autogenerated by VS was

         spriteBatch.Begin();
     spriteBatch.DrawString(myFont, "Score: " +score, new Vector2(20,10),Color.Red);
        spriteBatch.End();

and then manully added my spritefont file in the right folder

The strange thing is that i have added pictures with this way and the have ended up in the right folder but not the *.spritefont, you have to manully add it in the later folder to get i to work..

I hope some of this makes sense to someone because this has given me the biggest headache these last days. I may have forgotten some steps and all this may be useless, but I hope that I may ease the headaches for some out there

And i hope that monoGame will be updated to fix these issues...

share|improve this answer
add comment

Check this out guys, I've been compiling my *.spritefont files to .xnb for use in MonoGame, for me, it's the only way it worked.

Check it out, might help you too. http://xnacontentcompiler.codeplex.com/

share|improve this answer
add comment

The best alternative is to pre-generate the font xnb via XNA first then just use them in your Monogame for Windows project or you can do the old trick of getting the Window.Handle and the screen coordinates ScreenToClient then use the GDI to draw your text with the System.Drawing.dll.

share|improve this answer
add comment

I've used XNB Builder to manually convert them into .xnb files. Simply run the app, choose your files and it will convert them into XNB files that are ready to use with MonoGame.

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.