Graphics‎ > ‎2D‎ > ‎

Text

I picture gives you a thousand words when you only need one

There are three parts to drawing text in a game, the font, the texture and the glyph information. Drawing text in 3D is the same but you draw the text to a texture and then draw a surface with the texture.

The Font
This is the style of the text you will use. There exist many font's and you need to pick the one and make sure you have the license for it.

Texture
This is a texture that contain the characters you will use in the game. It can be pre-made with all the characters you need or created when the game is running.

Offline
With a offline system you create all the characters you will use in a texture. As the font's are put in the texture they will have a set style and size.
Online
By drawing the fonts when the game is running you can use more options such as different sizes and bold settings. When you need a character of a certain style it is drawn to the texture if it does not exist there already. The font rendering is a bit slow but it only need to be done once and can then use any characters that the font support.

To render the font's you can use FreeType.

Glyph Info
To draw the text from the texture you also need the glyph info. It's a data structure where you have information about each character. It's position in the texture, how much to advance the position of the next character when this is drawn and other information.

Comments