|
CGVIS Utils
|
OpenGL-based text drawer using per-character textures (or SDFs). More...
#include <FontRenderer.h>
Public Member Functions | |
| FontEngine () | |
| Create an empty engine and initialize shaders, quad geometry, and VBOs. | |
| virtual | ~FontEngine () |
| std::string | getAllCharsString () const |
| Return the available characters as a single concatenated string. | |
| void | setRenderAsSignedDistanceField (bool renderAsSignedDistanceField) |
| Enable/disable signed distance field rendering. | |
| bool | getRenderAsSignedDistanceField () const |
| Current SDF rendering flag. | |
Draw text | |
| void | render (const std::string &text, float winAspect, float height, const Vec2 &pos, Alignment a=Alignment::Center, const Vec4 &color=Vec4{1.0f, 1.0f, 1.0f, 1.0f}) |
| Render a UTF-8 string. | |
| void | renderFixedWidth (const std::string &text, float winAspect, float width, const Vec2 &pos, Alignment a=Alignment::Center, const Vec4 &color=Vec4{1.0f, 1.0f, 1.0f, 1.0f}) |
| Render with fixed total width (height adapts to keep aspect). | |
| void | render (uint32_t number, float winAspect, float height, const Vec2 &pos, Alignment a=Alignment::Center, const Vec4 &color=Vec4{1.0f, 1.0f, 1.0f, 1.0f}) |
| Convenience overloads rendering an integer number. | |
| void | renderFixedWidth (uint32_t number, float winAspect, float width, const Vec2 &pos, Alignment a=Alignment::Center, const Vec4 &color=Vec4{1.0f, 1.0f, 1.0f, 1.0f}) |
Layout helpers | |
| Vec2 | getSize (const std::string &text, float winAspect, float height) const |
Expected on-screen size of text for a given height. | |
| Vec2 | getSizeFixedWidth (const std::string &text, float winAspect, float width) const |
Expected on-screen size of text for a fixed width. | |
| Vec2 | getSize (uint32_t number, float winAspect, float height) const |
| Size helpers for integer numbers. | |
| Vec2 | getSizeFixedWidth (uint32_t number, float winAspect, float width) const |
Public Attributes | |
| std::map< char, CharTex > | chars |
| Per-character textures + transforms. | |
| std::map< char, CharTex > | sdChars |
| Per-character SDF textures + transforms. | |
OpenGL-based text drawer using per-character textures (or SDFs).
Builds a simple pipeline to render strings as textured quads. The map chars holds per-glyph textures; sdChars stores signed-distance variants for crisp scaling when renderAsSignedDistanceField is enabled.
| FontEngine::FontEngine | ( | ) |
Create an empty engine and initialize shaders, quad geometry, and VBOs.
|
inlinevirtual |
| std::string FontEngine::getAllCharsString | ( | ) | const |
Return the available characters as a single concatenated string.
|
inline |
Current SDF rendering flag.
| Vec2 FontEngine::getSize | ( | const std::string & | text, |
| float | winAspect, | ||
| float | height ) const |
Expected on-screen size of text for a given height.
| Vec2 FontEngine::getSize | ( | uint32_t | number, |
| float | winAspect, | ||
| float | height ) const |
Size helpers for integer numbers.
| Vec2 FontEngine::getSizeFixedWidth | ( | const std::string & | text, |
| float | winAspect, | ||
| float | width ) const |
Expected on-screen size of text for a fixed width.
| Vec2 FontEngine::getSizeFixedWidth | ( | uint32_t | number, |
| float | winAspect, | ||
| float | width ) const |
| void FontEngine::render | ( | const std::string & | text, |
| float | winAspect, | ||
| float | height, | ||
| const Vec2 & | pos, | ||
| Alignment | a = Alignment::Center, | ||
| const Vec4 & | color = Vec4{1.0f,1.0f,1.0f,1.0f} ) |
Render a UTF-8 string.
| text | String to draw (unknown chars are rendered as '_'). |
| winAspect | Window aspect ratio (width/height) used for pixel-correct scaling. |
| height | Normalized line height in NDC (Y span of one line). |
| pos | Anchor position in NDC ([-1,1]²). |
| a | Alignment relative to pos. |
| color | RGBA color multiplier. |
| void FontEngine::render | ( | uint32_t | number, |
| float | winAspect, | ||
| float | height, | ||
| const Vec2 & | pos, | ||
| Alignment | a = Alignment::Center, | ||
| const Vec4 & | color = Vec4{1.0f,1.0f,1.0f,1.0f} ) |
Convenience overloads rendering an integer number.
| void FontEngine::renderFixedWidth | ( | const std::string & | text, |
| float | winAspect, | ||
| float | width, | ||
| const Vec2 & | pos, | ||
| Alignment | a = Alignment::Center, | ||
| const Vec4 & | color = Vec4{1.0f,1.0f,1.0f,1.0f} ) |
Render with fixed total width (height adapts to keep aspect).
| void FontEngine::renderFixedWidth | ( | uint32_t | number, |
| float | winAspect, | ||
| float | width, | ||
| const Vec2 & | pos, | ||
| Alignment | a = Alignment::Center, | ||
| const Vec4 & | color = Vec4{1.0f,1.0f,1.0f,1.0f} ) |
|
inline |
Enable/disable signed distance field rendering.
| std::map<char,CharTex> FontEngine::chars |
Per-character textures + transforms.
| std::map<char,CharTex> FontEngine::sdChars |
Per-character SDF textures + transforms.