Singleton that loads fonts and renders text via FreeType.
More...
#include <text_renderer.hpp>
|
| void | clearGlyphCache (Font *font) |
| | Clears the cached glyphs for a font.
|
| |
| Font * | loadFont (std::string path, int height=40) |
| | Loads a font from disk (or returns the cached one).
|
| |
| void | setFontHeight (Font *font, int heightIn) |
| | Changes a font's pixel height and clears its glyph cache.
|
| |
| bool | loadGlyph (Font *font, uint32_t cp) |
| | Rasterizes and caches a single glyph.
|
| |
| void | renderText (Font *font, const std::string &text, Vector3 pos, float scale, const Color &color) |
| | Draws a text string at a position.
|
| |
| Vector2 | measureText (Font *font, const std::string &text, float scale) |
| | Measures the rendered size of a text string.
|
| |
| | TextRenderer () |
| | Constructs the renderer and initializes FreeType.
|
| |
| | ~TextRenderer () |
| | Releases FreeType resources.
|
| |
|
| bool | valid |
| | Whether the renderer initialized successfully.
|
| |
|
| FT_Library | ft |
| | FreeType library handle.
|
| |
| std::unordered_map< std::string, std::unique_ptr< Font > > | fonts |
| | Loaded fonts keyed by path.
|
| |
Singleton that loads fonts and renders text via FreeType.
Rasterizes glyphs on demand, caches them per Font, and draws text as textured quads.
◆ TextRenderer()
| cangine::TextRenderer::TextRenderer |
( |
| ) |
|
Constructs the renderer and initializes FreeType.
◆ ~TextRenderer()
| cangine::TextRenderer::~TextRenderer |
( |
| ) |
|
Releases FreeType resources.
◆ clearGlyphCache()
| void cangine::TextRenderer::clearGlyphCache |
( |
Font * |
font | ) |
|
Clears the cached glyphs for a font.
- Parameters
-
| font | Font whose glyph cache should be emptied. |
◆ getInstance()
Returns the singleton instance.
- Returns
- Pointer to the TextRenderer instance.
◆ init_freetype()
| bool cangine::TextRenderer::init_freetype |
( |
| ) |
|
|
private |
Initializes the FreeType library.
- Returns
true on success, false on failure.
◆ loadFont()
| Font * cangine::TextRenderer::loadFont |
( |
std::string |
path, |
|
|
int |
height = 40 |
|
) |
| |
Loads a font from disk (or returns the cached one).
- Parameters
-
| path | Path to the font file. |
| height | Pixel height to render the font at. |
- Returns
- Pointer to the loaded font, or
nullptr on failure.
◆ loadGlyph()
| bool cangine::TextRenderer::loadGlyph |
( |
Font * |
font, |
|
|
uint32_t |
cp |
|
) |
| |
Rasterizes and caches a single glyph.
- Parameters
-
| font | Font to load the glyph for. |
| cp | Unicode codepoint of the glyph. |
- Returns
true if the glyph was loaded successfully.
◆ measureText()
| Vector2 cangine::TextRenderer::measureText |
( |
Font * |
font, |
|
|
const std::string & |
text, |
|
|
float |
scale = 1.0f |
|
) |
| |
Measures the rendered size of a text string.
- Parameters
-
| font | Font that would render the text. |
| text | UTF-8 text to measure. |
| scale | Scale factor applied to the glyphs. |
- Returns
- The width and height the text would occupy.
◆ renderText()
| void cangine::TextRenderer::renderText |
( |
Font * |
font, |
|
|
const std::string & |
text, |
|
|
Vector3 |
pos, |
|
|
float |
scale, |
|
|
const Color & |
color |
|
) |
| |
Draws a text string at a position.
- Parameters
-
| font | Font to render with. |
| text | UTF-8 text to draw. |
| pos | Baseline position (z is the layer). |
| scale | Scale factor applied to the glyphs. |
| color | Text color. |
◆ setFontHeight()
| void cangine::TextRenderer::setFontHeight |
( |
Font * |
font, |
|
|
int |
heightIn |
|
) |
| |
Changes a font's pixel height and clears its glyph cache.
- Parameters
-
| font | Font to modify. |
| heightIn | New pixel height. |
◆ fonts
| std::unordered_map<std::string, std::unique_ptr<Font> > cangine::TextRenderer::fonts |
|
private |
Loaded fonts keyed by path.
◆ ft
| FT_Library cangine::TextRenderer::ft |
|
private |
◆ instance
◆ valid
| bool cangine::TextRenderer::valid |
Whether the renderer initialized successfully.
The documentation for this class was generated from the following files: