Game Development Reference
In-Depth Information
chapter 7
Rendering Text
Most games need text—at the very least to display a score or menu.
Text rendering is also very useful for rendering out variable values as the game
is running. A basic font system can be made very simply; each letter and number
is represented as a sprite. Then a string of text is translated into a list of sprites.
This method is easy to extend to any language, though Asian languages such as
Chinese will need a larger number of textures to account for all the different
glyphs.
Font Textures
Figure 7.1 is a texture with the entire Roman alphabet, numbers, and some
punctuation marks. This is a great base to use to draw text. Such textures are easy
to create if the correct tools are used. An excellent tool for bitmap fonts is
Andreas J¨nsson's Bitmap Font Generator, which is freely available on the
internet and is also included on the CD in Apps folder. It can take a True Type
font and generate a bitmap suitable for efficient rendering in a game. This is how
the texture shown in Figure 7.1 was created. The font texture can be found on the
CD in the Assets folder along with a data file that describes the U,V coordinates
of the glyphs in the texture.
To display this font, I've created a new project with a new game state called
TextTestState . I've added the font texture to the project as font.tga (you can
find this on the CD in the Assets folder); this has also been loaded into the
 
 
 
Search WWH ::




Custom Search