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.

After searching for a while, I found no way to draw vector/scalable fonts in XNA 4.0 (which would be perfect...) and I am currently in a bind about how to render fonts for my game.
In the game I use fonts of variable size, ranging from very small to quite large, and I have no idea how to efficiently deal with this.

The only way I can currently accomplish what I want is to load a large number of SpriteFonts different sizes, manually pick the font closest to the size I want, and then fine-tune the size with a scale close to 1. (A scale too large or too small will make the font look horrible.) I've also started using the Nuclex font processor which makes the fonts looks somewhat better, but it's obviously not the answer to my problem.

Is there really no other way to deal with this?
It seems very strange to me that something as elaborate and well done as XNA 4.0 has such a profound lack of tools to deal with font rendering.

This is quite a big problem for me currently, so any help and ideas on possible ways to deal with this or even to ease the pain are very welcome.

share|improve this question
1  
+1 I've wondered about this before, and arrived at the same conclusion as you. Would really like to know of a better solution :) –  David Gouveia Jul 15 '12 at 1:58
    
Is it not possible to decompose the vector outlines of a ttf into triangles, then rendering the shapes in 3D? –  Quasiperfect Jul 15 '12 at 4:49
    
What's your target platform? If Windows, you can use the content pipeline assemblies at run time to generate assets dynamically. –  David Lively Jul 16 '12 at 5:11

2 Answers 2

public void DrawString ( SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth )

Unless I'm missing something, there is a scale overload on DrawString.

share|improve this answer
4  
The problem is that once the font has passed through the content pipeline, it is transformed into a bitmap. So what the scale parameter does is scale that bitmap, which results in a loss of quality, which he wants to avoid. –  David Gouveia Jul 15 '12 at 1:57
    
exactly as @DavidGouveia said - scaling utterly ruins the quality (unless the scale is very close to 1). Nuclex helps with this a little bit (and just makes fonts prettier in general), but its still nowhere near a solution for this problem. –  Acidic Jul 15 '12 at 2:00
    
Ah, Well I'll leave it hear incase it helps a newbie some day. –  Cyral Jul 15 '12 at 12:50

This is not an easy problem to solve. If the "multiple sprite fonts" technique doesn't work for you, there's no other built-in way in XNA to get what you want. So you have to do some custom development.

One method is to use Valve's technique, as described in the paper: Improved Alpha-Tested Magnification for Vector Textures and Special Effects. This involves specially encoded textures and a special pixel shader. I've implemented this before and it's not too difficult. The results are reasonable, although not perfect.

Another method that is worth considering is to offload font rendering to Windows (rendering fonts to a texture - just like the content pipeline does to produce bitmap fonts). This has the added benefit of allowing you to use any character from your font, rather than only what you have available in the bitmap font. If you render entire strings at once, you'll get reasonable performance and this will solve many internationalisation issues that sprite fonts have.

Another method is to simply use vector fonts (at least above a certain size threshold). This is probably the easiest to get working - on the basis that you could just use Nuclex.Fonts.

Finally, this post might be worth reading for some additional ideas.

share|improve this answer

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.