Cross-Platform Game Programming with gameplay3d/Text and Fonts

Importing fonts into gameplay3d
Gameplay3d supports TrueType fonts, but these must first be converted to a gameplay bundle file (see ../gameplay3d_Design_Concepts) before use in your project.

Use the following steps to import a font into your project:


 * Find or create a TrueType font file (.ttf).
 * Pass the .ttf file to the gameplay-encoder command line tool and specify the size you want. A pre-compiled version of gameplay-encoder is available under GamePlay/bin:


 * The gameplay-encoder will output a .gpb file.
 * Copy the .gpb file to your game's resource directory. (The .ttf file does not need to be included.)
 * Import your font into your project as follows:

Drawing text with a Font
To render using a font:
 * first, call  on your font instance to start text drawing;
 * second, call  to draw some text at a defined location. There are four different overloads for this function, the parameters for which can be found in Font.h; and
 * finally, call  to finish text batching for the relevant font and render all drawn text.

Here is an example of loading a font and using it to render the game's frame rate on the screen.

Batching
It is possible to call  multiple times between   and   in order to draw different text in different places with the same font.

High-quality text using distance fields
Since version 2.0.0, gameplay3d supports distance field fonts. You can read more about distance field fonts in the Valve paper Improved Alpha-Tested Magnification for Vector Textures and Special Effects but, in short, distance fonts look a lot better than bitmap fonts, particularly at high magnification!

To create a distance field font, use the  option parameter when running gameplay-encoder, e.g.: