Game Development Reference
In-Depth Information
6.
The FreeString() routine clears the internal FreeType glyphs cache:
void FreeString()
{
for ( size_t i = 0 ; i < FString.size() ; i++ )
if ( FString[i].FCacheNode != NULL )
FTC_Node_UnrefPTR(FString[i].FCacheNode,FManager);
FString.clear();
}
7. FString contains all the characters from the string being rendered. The
initialization and deinitialization functions are called in the constructor and
destructor, respectively:
TextRenderer(): FLibrary( NULL ), FManager( NULL ),
FImageCache( NULL ), FCMapCache( NULL )
{
InitFreeType();
FMaskMode = false;
}
virtual ~clTextRenderer() { StopFreeType(); }
8.
To utilize the TrueType fonts and render the glyphs, we need to create a simple set
of management routines to load the font iles. The irst one is the LoadFontFile()
function, which loads the font ile, stores its contents in the list, and returns the
error code:
FT_ErrorLoadFontFile( const std::string& File )
{
if ( FAllocatedFonts.count( File ) > 0 ) { return 0; }
char* Data = NULL;
int DataSize;
ReadFileData( File.c_str(), &Data, DataSize );
FT_Face TheFace;
9. We always use the 0-th face, which is the irst one in the loaded ile:
FT_Error Result = FT_New_Memory_FacePTR(FLibrary,
(FT_Byte*)Data, (FT_Long)DataSize, 0, &TheFace );
10. Check for success and store the font in the array of loaded font faces:
if ( Result == 0 )
{
FFontFaceHandles[File] = TheFace;
FAllocatedFonts[File] = ( void* )Data;
FFontFaces.push_back( File );
}
return Result;
}
 
Search WWH ::




Custom Search