Saturday, June 27, 2015

textures - How to handle font loading?


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.




Answer



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)


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...