Home | nevrax.com |
|
How to compute and render strings
SummaryA 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) 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 :
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. Rq : a character is defined by
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 :
CComputedStringRendering parameters The coordinates are screen-relatives :
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);
|