FreeTypeFontResourceManager Class
FreeType-based implementation of `FontResourceProvider` for OpenGL. More...
Declaration
Base class
| class | FontResourceProvider |
|
Abstract interface for loading fonts and providing glyph data. More... | |
Public Destructor Index
| ~FreeTypeFontResourceManager () override | |
|
Destructor that cleans up all OpenGL textures. More... | |
Public Member Functions Index
| void | loadFont (const helios::engine::core::data::FontId fontId, const unsigned int pixelHeight, const std::string_view pathToFont) override |
|
Loads a font from a file and caches its glyphs as OpenGL textures. More... | |
| helios::rendering::text::Glyph | glyph (const char c, const helios::engine::core::data::FontId fontId) override |
|
Retrieves the cached glyph data for a character. More... | |
Private Member Attributes Index
| std::unordered_map< helios::engine::core::data::FontId, FontCache > | fontCache_ |
|
Map of font IDs to their cached glyph data. More... | |
Description
FreeType-based implementation of `FontResourceProvider` for OpenGL.
`FreeTypeFontResourceManager` uses the FreeType library to load TrueType fonts, rasterize glyphs, and cache them as OpenGL textures. Each glyph is stored as a separate texture for simplicity.
## Responsibilities
- **Font Loading:** Parse font files using FreeType and extract glyph metrics.
- **Texture Creation:** Upload glyph bitmaps to GPU as GL_R8 textures.
- **Caching:** Store glyph data per font for efficient repeated access.
- **Resource Cleanup:** Delete OpenGL textures when the manager is destroyed.
## Usage
```cpp FreeTypeFontResourceManager fontManager; fontManager.loadFont(FontId{"roboto"}, "fonts/Roboto-Regular.ttf");
// Retrieve a glyph for rendering Glyph g = fontManager.glyph('A', FontId{"roboto"}); ```
Currently loads ASCII characters 0-127 with a fixed pixel size of 24.
- See Also
FontResourceProvider
- See Also
Glyph
- See Also
Definition at line 60 of file FreeTypeFontResourceManager.ixx.
Public Destructor
~FreeTypeFontResourceManager()
| inline |
Destructor that cleans up all OpenGL textures.
Iterates through all cached fonts and deletes the associated glyph textures to free GPU memory.
Definition at line 88 of file FreeTypeFontResourceManager.ixx.
Reference glyph.
Public Member Functions
glyph()
| inline virtual |
Retrieves the cached glyph data for a character.
Returns the glyph metrics and texture ID for the specified character from the font's cache. The font must have been previously loaded via `loadFont()`.
- Parameters
-
c The character to retrieve the glyph for.
fontId The font identifier to use.
- Returns
The cached `Glyph` data for the character.
- Precondition
The font must already be loaded (asserts in debug builds).
Definition at line 197 of file FreeTypeFontResourceManager.ixx.
Referenced by ~FreeTypeFontResourceManager.
loadFont()
| inline virtual |
Loads a font from a file and caches its glyphs as OpenGL textures.
Uses FreeType to parse the font file and rasterize ASCII characters 0-127. Each glyph bitmap is uploaded to the GPU as a GL_R8 texture.
- Parameters
-
fontId Unique identifier for this font.
pixelHeight The height of the font, in pixels.
pathToFont File system path to the font file (e.g., `.ttf`).
- Exceptions
-
std::runtime_error If FreeType initialization fails.
std::runtime_error If the font file cannot be loaded.
std::runtime_error If a glyph cannot be loaded.
- Precondition
The font ID must not already be loaded (asserts in debug builds).
Definition at line 115 of file FreeTypeFontResourceManager.ixx.
Private Member Attributes
fontCache_
|
Map of font IDs to their cached glyph data.
Definition at line 77 of file FreeTypeFontResourceManager.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.