Game Development Reference
In-Depth Information
FreeType glyph metrics
The xMin , xMax , yMin , and yMax values deine the dimensions of the glyph in logical
coordinates, and the advance value shows where the next glyph starts if we assume no
kerning. Once we want to render on the screen, we need to transform logical coordinates
used by FreeType into screen coordinates. FreeType avoids using loating point calculations
and stores everything in a 26.6 ixed-point format ( http://www.freetype.org/
freetype2/docs/glyphs/glyphs-6.html ). To convert these fancy values acquired from
FreeType, we right-shift these values by six bits (equivalent to the integer division by 64) and
get the value we can use with ease.
Rendering the individual images of each character is not enough. Sometimes characters look
better when they are rendered closer to each other and some letter combinations may even
produce new glyphs. The variation of the distance between the characters on the screen is
called kerning, and FreeType provides functions to calculate offsets between glyphs. Joining
several glyphs as a single glyph is called a ligature, and is outside of the scope of this topic
(see http://en.wikipedia.org/wiki/Typographic_ligature for details and
references). In Chapter 7 , Cross-platform UI and Input System , we use only simple kerning,
which is good enough for our interactive applications.
To show the basic usage of FreeType, we are going to write the code in this recipe
implementing:
F An ASCII string renderer using a monospaced font.
F FreeType-based textures generator for monospaced fonts.
Later, we shall return to the advanced FreeType usage involving proportional fonts, UTF-8
encoding, and kerning.
 
Search WWH ::




Custom Search