Angel 3.2
A 2D Game Prototyping Engine
Functions
TextRendering.h File Reference
#include "../Util/StringUtil.h"

Go to the source code of this file.

Functions

const bool RegisterFont (const String &filename, int pointSize, const String &nickname)
 
const bool IsFontRegistered (const String &nickname)
 
const bool UnRegisterFont (const String &nickname)
 
Vector2 DrawGameText (const String &text, const String &nickname, int pixelX, int pixelY, float angle=0.0f)
 
Vector2 DrawGameTextRaw (const String &text, const String &nickname, int pixelX, int pixelY, float angle=0.0f)
 
Vector2 GetTextExtents (const String &text, const String &nickname)
 
float GetTextAscenderHeight (const String &nickname)
 

Detailed Description

A low-level C-style interface for drawing text to the screen. Most of the functionality is wrapped in TextActor, which is where you should probably be focusing if you care about text. But if you want/need to wrangle your own text functionality, here you go.

Definition in file TextRendering.h.

Function Documentation

const bool RegisterFont ( const String &  filename,
int  pointSize,
const String &  nickname 
)

Register a font with our text rendering system.

Parameters
filenameThe path to the font file you want to use. Must be a format readable by FreeType (http://www.freetype.org). Most major font formats are acceptable.
pointSizeThe size, in points, that you want the text to render.
nicknameHow you want to refer to the font when telling it to draw
Returns
Whether or not it successfully registered (check the error log if this returns false)

Definition at line 48 of file TextRendering.cpp.

const bool IsFontRegistered ( const String &  nickname)

Tell whether there is already a font with a given name (to avoid repeat loading).

Returns
Whether or not there is currently a registered font by the given name.

Definition at line 79 of file TextRendering.cpp.

const bool UnRegisterFont ( const String &  nickname)

If you're done using a font and are concerned about memory usage, you can remove it from active use.

Parameters
nicknameThe name you gave the font when you registered it
Returns
Whether it successfully unregistered. If false, check the error log.

Definition at line 92 of file TextRendering.cpp.

Vector2 DrawGameText ( const String &  text,
const String &  nickname,
int  pixelX,
int  pixelY,
float  angle = 0.0f 
)

Draw text on the screen (but only once, so you need to call this every frame if you want the text to stay up).

Parameters
textThe string to write
nicknameThe name you've assigned to the font you want to use
pixelXThe X-coordinate (in pixels) to start drawing
pixelYThe Y-coordinate (in pixels) to start drawing
angleThe angle at which to draw the text
Returns
The 2d point (in pixels) representing the bottom-most, right-most point where you could safely start drawing and not overwrite the string you just displayed.

Definition at line 106 of file TextRendering.cpp.

Vector2 DrawGameTextRaw ( const String &  text,
const String &  nickname,
int  pixelX,
int  pixelY,
float  angle = 0.0f 
)

Renders text without first doing the transformation to screenspace. If you're drawing a lot of text and have already set up your projection, this can save you from needless matrix manipulation.

Parameters
textThe string to write
nicknameThe name you've assigned to the font you want to use
pixelXThe X-coordinate (in pixels) to start drawing
pixelYThe Y-coordinate (in pixels) to start drawing
angleThe angle at which to draw the text
Returns
The 2d point (in pixels) representing the bottom-most, right-most point where you could safely start drawing and not overwrite the string you just displayed.

Definition at line 152 of file TextRendering.cpp.

Vector2 GetTextExtents ( const String &  text,
const String &  nickname 
)

If you're just interested in how much space a certain string will take up, but don't want to bother drawing it, this is the function for you.

Parameters
textThe string you care about
nicknameThe font you would want to render it in
Returns
The 2d point (in pixels) representing the bottom-most, right-most point where you could safely start drawing and not overwrite the string if you had drawn it to the screen.

Definition at line 186 of file TextRendering.cpp.

float GetTextAscenderHeight ( const String &  nickname)

Gets the standard line height of this font – the number of pixels vertically occupied by a String containing capital letters. This does not include descenders like the bottom loop of a lowercase "g", only the height from the baseline. Useful for laying out multi-line text.

Parameters
nicknameThe font whose height you want.
Returns
The number of vertical pixels used. Will return 0 if a font is not registered.

Definition at line 204 of file TextRendering.cpp.