Game Development Reference
In-Depth Information
Using FreeType for text rendering
It is possible that the interface avoids rendering the textual information. However, most
applications have to display some text on the screen. It is time to consider the FreeType text
rendering in all its detail with kerning and glyph caching. This is the longest recipe of this
book, but we really wish not to miss the details and subtleties of the FreeType usage.
Getting ready
It is time to make the real use of the recipe on the FreeType compilation from Chapter 2 ,
Porting Common Libraries . We start with an empty application template described in Chapter
1 , Establishing a Build Environment . The following code supports multiple fonts, automatic
kerning, and glyph caching.
In typography, kerning (less commonly mortising) is the process of adjusting the
spacing between characters in a proportional font, usually to achieve a visually
pleasing result.
Courtesy: http://en.wikipedia.org/wiki/Kerning
Glyph caching is a feature of the FreeType library, which reduces memory usage using glyph
images and character maps. You can read about it at http://www.freetype.org/
freetype2/docs/reference/ft2-cache_subsystem.html .
How to do it...
Here we develop the TextRenderer class, which holds all the states of the FreeType library.
We wrap the text rendering in a class to support multiple instances of this class and ensure
the thread safety.
1.
The required FreeType library initialization includes the library instance, glyph cache,
character map cache, and image cache. We declare the internal FreeType objects
irst:
class TextRenderer
{
// Local instance of the library (for thread-safe
execution)
FT_Library FLibrary;
// Cache manager
FTC_Manager FManager;
// Glyph cache
FTC_ImageCache FImageCache;
// Character map cache
FTC_CMapCache FCMapCache;
 
Search WWH ::




Custom Search