Game Development Reference
In-Depth Information
40. The auxiliary MultColor() function multiplies each component of the integer-
encoded color by the Mult factor:
unsigned int MultColor( unsigned int C, unsigned int Mult )
{ return (Mult << 24) | C; }
How it works...
The minimal code to render a UTF-8 string covers the creation of a TextRenderer instance,
font loading, and actual text rendering using the loaded font:
TextRenderer txt;
int fnt = txt.GetFontHandle("some_font.ttf");
Render the Portuguese word direção , which means direction , as an example:
char text[] = { 'D','i','r','e',0xC3,0xA7,0xC3,0xA3,'o',0 };
auto bmp =
txt.RenderTextWithFont(text, fnt, 24, 0xFFFFFFFF, true);
The result is the bmp variable, which contains the rendered text, as shown in the
following screenshot:
There's more…
This is the longest recipe ever, and still some important details have been left out. If the
amount of text you render for each frame is large enough, it makes sense to pre-render
some of the strings and avoid recreation of images.
Localization of in-game strings
Mobile applications are used on a variety of devices and, quite often, these devices are
conigured to use a language other than English. This recipe shows how to internationalize
textual messages displayed in the application UI.
Getting ready
Review Chapter 4 , Organizing a Virtual Filesystem , for the read-only ile access using
our implementation of the virtual ilesystem abstraction.
 
Search WWH ::




Custom Search