Game Development Reference
In-Depth Information
As you can see, it's fairly self-explanatory. The comments at the start of the file are
primarily used by the font builder utility to know what settings were used to create
the font, so you should leave these values well alone if you want to edit the font later.
We can edit a font in the font builder utility at a later date by using
File | Load Font or by pressing the Load… button. A file requester
will appear allowing us to choose the GXFONT file we wish to edit.
The part of the GXFONT file we're really interested in is the definition of the
CIwGxFont instance. The three parameters we see here indicate that the character
encoding to be used with this font should be UTF-8, the bitmap image to use is
called numbers.tga , and the characters present in the font are the numerals zero
through nine.
By default, UTF-8 character encoding is chosen, as this format often
provides the most compact memory representation of text strings,
at least as far as European languages are concerned.
If we've specified any other font settings in the font builder utility, such as character
subranges or kerning information, this will also be represented in both the comments
at the top of the file and the CIwGxFont structure. We won't cover this here though,
since the font builder takes care of all the hard work for us.
Loading and accessing font resources
As with all the resource types we've seen, we load a font resource into our program
by adding a reference to it into a GROUP file, loading the GROUP file using the
resource manager, and then searching for the font resource.
For completeness, here is a code snippet showing how to do this:
CIwResGroup* lpResGroup = IwGetResManager()->
LoadGroup("fonts/fonts.group");
CIwGxFont* lpSmallFont = static_cast<CIwGxFont*>(IwGetResManager()->
GetResNamed("small", "CIwGxFont"));
Drawing text using a font resource
With a font resource loaded and a pointer to it obtained, we can start to draw some
text on screen with it. First we'll look at the basics of drawing a string of text, then
we'll take a look at how we can justify the text, change its size, and how we can make
drawing it a little more optimized.
 
Search WWH ::




Custom Search