A character is displayed using a CTextureFont. To avoid creating a new CTextureFont for each character we use a CFontManager which provides the textures and manages CTextureFont instances in memory. A font manager is able to compute an entire string, to do that it fills a CComputedString. A CComputedString contains a list of primitive blocks (CPrimitiveBlock) [FIXME: CPrimitiveBlock no longer exists since the direct3d driver was implemented...] and materials (CMaterial).
It can then render the string through a driver (IDriver).
A CTextureFont object is a texture representing a unicode character. It inherits ITexture, and therefore CBitmap. The texture bitmap is built by calling generate() which fills in the same time useful fields, as:
GlyphIndex: number of the character in the this font
Top: Distance between origin and top of the texture
Left: Distance between origin and left of the texture
AdvX: Advance to the next caracter
All these values are given by the font generator.
About bitmap dimensions: if width or height are not powers of 2 there are set to the next power of 2. The true dimensions are still availables in the CTextureFont level.
The font manager manages CTextureFont pointers through a list of CSmartPtr. When the user requires the texture font representing a character, it generates and stores this pointer in the list. If this character has already been generated, and lies in the list, it increments its reference count and return the pointer.
A character is defined by:
The maximum memory used by the list of generated font textures in the font manager can be, and SHOULD be, set by the user after manager creation. Indeed the default value is 0. When the maximum memory is reached, the manager delete the useless characters until memory ammount is acceptable.
The font generator is the interface between Nel and FreeType. One generator is used for one font. Then, providing a unicode char and a size, the generator can return a generated bitmap containing the char bitmap.
A CDisplayDescriptor is a structure used to store screen parameters:
Rendering parameters
The coordinates are screen-relatives:
The scale parameters have the default value 1.
The rotation angle is set to 0 by default.
A string as a "hot spot" which indicates its relative display origin.
By default this value is LeftBottom.
The others are:
Here is an example generating and rendering a string:
// Font manager
CFontManager fontManager;
fontManager.setMaxMemory(2000000);
// Font generator
CFontGenerator fontGenerator("c:/winnt/fonts/arialuni.ttf");
// Screen parameters
CDisplayDescriptor displayDesc;
displayDesc.ResX = 800;
displayDesc.ResY = 600;
// Compute string
CComputedString cptedString;
fontManager.computeString("Nevrax", &fontGenerator, CRGBA(255,255,255), 100, displayDesc, cptedString);
//...here the driver is initialized...
// render string
cptedString.render2D(driver, 0.5, 0.7);