Overview
The text rendering system provides support for loading TrueType fonts, managing font atlases, and rendering text with proper kerning and positioning. Text objects can be added to scenes as UI elements.Font
TheFont structure manages font resources and glyph atlases.
Properties
The name of the font.
The font atlas that contains the glyphs for this font (map of char to Character).
The size of the font in pixels.
The resource associated with the font.
The texture atlas containing all glyphs.
Static Methods
Creates a font from a resource.Parameters:
fontName- The name to associate with the fontresource- The resource from which to create the fontfontSize- The size of the font in pixels
Gets the font associated with the given name.Parameters:
fontName- The name of the font to retrieve
Methods
Changes the size of the font. This will regenerate the font atlas.Warning: This operation is expensive. Use it when performance is not a concern.Parameters:
newSize- The new size for the font in pixels
Character
Structure representing a single character glyph in the font atlas.The size of the glyph.
The offset from the baseline to the top-left of the glyph.
The advance width of the glyph (horizontal spacing to next character).
The top-left UV coordinate in the atlas texture.
The bottom-right UV coordinate in the atlas texture.
Text
TheText class represents a text object that can be rendered in the game world or UI.
Constructors
Creates an empty text object.
Creates a text object with the given parameters.Parameters:
text- The text content to displayfont- The font with which to render the textposition- The position of the text in 2D space (default:{0, 0})color- The color of the text (default:Color::white())
Properties
The content of the text to render.
The font used to render the text.
The position of the text in 2D screen space.
The color of the text.
Methods
Prepares vertex buffers, shader state, and fonts for runtime use. Called automatically when added to a scene.
Renders the text glyphs to the screen honoring kerning and font metrics.Parameters:
dt- Delta time since last framecommandBuffer- Command buffer for renderingupdatePipeline- Whether to update the pipeline (default:false)
FontAtlas
A map that associates characters with their corresponding glyph information.Type:
std::map<char, Character>Example Usage
Notes
- Text rendering uses a font atlas texture to efficiently render multiple characters
- The
Characterstructure stores glyph metrics including size, bearing, advance, and UV coordinates - Font sizes can be changed dynamically but this regenerates the atlas (expensive operation)
- Text objects inherit from
UIObjectand are rendered as 2D screen-space elements - Position coordinates are in screen pixels (0,0 is typically top-left)
- Colors support alpha transparency for fade effects
- The font system automatically handles glyph spacing and kerning
- Multiple font sizes require separate Font instances