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 need to display text in my game, who doesn't.

I had originally thought that I could just statically render all the text I would need to images and use those. I'm starting to think that is a bad idea. I figure I'll have to internationalize it in the future, and the game has score counters and such which cannot be statically rendered. It looks like I'll need to use a more dynamic approach.

So my question.

How do games usually handle font loading?

  • Load the TTF directly and render it to a texture atlas.
  • Pre-bake the TTF into an image with a configuration file storing locations and kerning.
share|improve this question

4 Answers 4

up vote 5 down vote accepted

This is what you're looking for:

http://www.angelcode.com/products/bmfont/

Used by numerous games, from indies to AAA titles, to create bitmap fonts from TTFs

Using this tool or something similar is probably the most common way to implement font rendering in a game. Other options do exist (e.g. rendering vector fonts directly with something like FreeType), but the simplicity and performance of bitmap fonts usually makes them the obvious choice

(Note that Valve's distance-field stuff is super-sweet for extreme magnification of text, such as the examples of decals in an FPS, but of little or no benefit for UI text, which is often being scaled down from the source texture, or maybe scaled up just a little)

share|improve this answer
1  
I totally disagree. We used Valve's font stuff for our UI, and it was an enormous memory savings compared to caching bitmaps for each character + outlined character + bold character at 3 font sizes, and it makes text scaling in flashy UIs much cheaper / nicer. –  user744 Aug 14 '10 at 10:22

If you are working with something that supports shaders and reasonably large textures, Valve has a technique for font rendering that scales very nicely and has minimal memory cost compared to other methods.

http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf

If you need Unicode support, you can split the font textures up by codepage block or whatever. I believe we found that even fairly complicated kanji were readable at small-ish prerendered sizes (128x128 and 64x64).

If you are trying something more complicated, like Arabic, or Devanagari, you are pretty much screwed, no matter the method you choose. There's no way to render arbitrary text in some languages efficiently in real-time, and you'll end up needing to render character digraphs/trigraphs/whole words at once.

share|improve this answer
    
Indeed, the moment I found out I had to support Japanese and Korean I switched to static bitmaps for a project. –  Kaj Aug 13 '10 at 23:10
    
@Kaj: Japanese and Korean require special IMEs but the rendering is the same as English. Valve's technique works fine, as do more traditional techniques. Where Valve's technique fails is languages with complicated kerning. –  user744 Jun 11 '12 at 18:53

One important question is how many languages you plan to support. If you are going to need to support things like Arabic, you are pretty much stuck with freetype (which speaks TTF) since rewriting Arabic kerning rules is probably up there with writing your own GPU driver in terms of pain.

share|improve this answer

Distributing the TTF is usually significantly more expensive (money wise) than other licensing schemes, so the games that do that are pretty rare. See also this thread. You don't want to make a Unicode font yourself.

Most implementations I've seen follow something like what you suggested in your second bullet point. A lot of modern AAA games, though, are starting to use Flash to render all their UI elements and I'm not entirely sure how that handles its fonts.

share|improve this answer
1  
Flash for the UI! Really? How does that work? –  deft_code Aug 13 '10 at 17:32
1  
Look up ScaleForm. That's what a lot of AAA games use. If you need something cheaper look at this thread: gamedev.stackexchange.com/questions/1707/is-gameswf-usable –  Tetrad Aug 13 '10 at 17:34

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.