Game Development Reference
In-Depth Information
IwGxFont draws text by rendering a rectangular polygon for each character in
our text, with the relevant part of the font image mapped on to it. By specifying a
scaling factor we can change the size of the polygons used to render the individual
characters, though this can yield poor results if we scale up by a large factor (for
example, more than double the original size of the font).
Optimizing drawing by preparing text
One of the problems with rendering text is that in order to perform alignment, word
wrapping, and the like, it is necessary to format the text by considering it one character
at a time to see if the next character crosses the rectangular bounding box area.
If we need to draw a piece of fixed text, such as an instructions screen, we can
prevent having to calculate the formatting information in every frame by preparing
the text for rendering once and then using some cached data to draw it from then on.
To do this we use the function IwGxFontPrepareText . This function takes a
reference to a CIwGxFontPreparedData class instance, the string of text to prepare,
and optionally the number of characters in the string that we want to consider. If this
parameter is omitted, the entire string is processed.
With the text prepared we can then draw it using another version of
the IwGxFontDrawText function. This version takes a reference to the
CIwGxFontPreparedData instance and two optional parameters that indicate
the first character from the prepared data to draw and the number of characters
to draw. Here's a code example:
CIwGxFontPreparedData lFontData;
IwGxFontSetRect(CIwRect(100, 100, 200, 100));
IwGxFontPrepareText(lFontData, "This is the text to be prepared!");
IwGxFontDrawText(lFontData);
Note that the text will be drawn on screen at the position indicated by the formatting
rectangle set in the call to IwGxFontSetRect .
Implementing user interfaces
Every game will need some kind of user interface, even if it is just a button that
can be pressed to start a new game. In this section we will take a look at how a
user interface can be implemented for your own game.
 
Search WWH ::




Custom Search