Load

bool Load(
const char *filename,
int width = 9, int height = 12,
Rgba col = Rgba::BLACK, int italics = 0,
bool useHinting = true );

Load the font from a True Type Font file.


bool Load(
const TextRenderer &otherRenderer,
int width = 9, int height = 12,
Rgba col = [inherit], int italics = [inherit] );

Load the font by making an altered copy of an existing TextRenderer. If you don't pass anything as the color or the italics parameter they'll be inherited from otherRenderer.


bool Load(
GLYPH_FACE *face = 0,
int width = 9, int height = 12,
Rgba col = Rgba::BLACK, int italics = 0,
bool useHinting = true );

Load the font by using a GlyphKeeper font face.

The alpha value of the color controls the opacity of the printed text. The higher the alpha value is, the more visible the text will be. For more information about alpha values see the definition of Bitmap.

If any of these functions fail to load the font an error log will be added to the allegro.log file. In addition the IsValid() -method will return false if the TextRenderer is not ready to use.

A word of caution: You can't load any TextRenderers before Setup::SetupProgram and Setup::SetupScreen are called!

Examples

// The usage of the Load -method is generally the same as with the constructors //

// Construct a new font by loading a true type font Arial.ttf in the fonts -folder //
// with the width of 10, the height of 15 and a black color //
TextRenderer myTextRenderer;
if( myTextRenderer.Load"fonts/Arial.ttf"1015Rgba::BLACK ) == false ) {
   allegro_message( "Couldn't load the font Arial.ttf!" );
   exit( -1 );
}

// Construct a same looking font but with italics angle of 12 (the common italics angle) //
TextRenderer myItalicsRenderer;
if( myItalicsRenderer.Load"fonts/Arial.ttf"1015Rgba::BLACK, 12 ) == false ) {
   allegro_message( "Couldn't load the font Arial.ttf!" );
   exit( -1 );
}

// Construct a font which looks like myTextRenderer but with the opacity of only 30% //
TextRenderer myTranslucentRenderer;
if( myTranslucentRenderer.Load"fonts/Arial.ttf"1015Rgba0.00.00.00.30 )) == false ) {
   allegro_message( "Couldn't load the font Arial.ttf!" );
   exit( -1 );
}

// Construct a smaller copy of an existing font (sized 9x12) //
// If you don't specify a color it'll be inherited //
// from the passed TextRenderer //
TextRenderer smallerTextRenderer;
smallerTextRenderer.Load( myTextRenderer, 912 );

// Construct the font from a glyph keeper font face //
// with a slightly yellow green color //
GLYPH_FACE *glyphKeeperFace = ...; 

TextRenderer otherTextRenderer;
if( otherTextRenderer.Load( glyphKeeperFace, 2015Rgba0.31.00.0 )) == false ) {
   allegro_message( "Couldn't load the font from a Glyph Keeper face!" );
   exit( -1 );
}



Other functions of the class TextRenderer
Load
Load the font
Print
Prints the given text to the screen
SetColor
Sets the color of the font
GetColor
Returns the text color of the font
SetItalics
Sets the italics angle of the text
GetItalics
Returns the italics angle of the text
Width
Returns the width of the given text
Height
Returns the height of the given text
FirstLineWidth
Returns the width of the first text line of the given text
FirstLineHeight
Returns the height of the first text line of the given text
IsValid
Checks if the TextRenderer was loaded correctly

Advanced functions

GetFace
SendToGPU
UnloadFromGPU
UseAutoDelete


Questions about Load? Click here.