CGVIS Utils
Loading...
Searching...
No Matches
FontEngine Class Reference

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ FontEngine()

FontEngine::FontEngine ( )

Create an empty engine and initialize shaders, quad geometry, and VBOs.

◆ ~FontEngine()

virtual FontEngine::~FontEngine ( )
inlinevirtual

Member Function Documentation

◆ getAllCharsString()

std::string FontEngine::getAllCharsString ( ) const

Return the available characters as a single concatenated string.

◆ getRenderAsSignedDistanceField()

bool FontEngine::getRenderAsSignedDistanceField ( ) const
inline

Current SDF rendering flag.

◆ getSize() [1/2]

Vec2 FontEngine::getSize ( const std::string & text,
float winAspect,
float height ) const

Expected on-screen size of text for a given height.

Here is the caller graph for this function:

◆ getSize() [2/2]

Vec2 FontEngine::getSize ( uint32_t number,
float winAspect,
float height ) const

Size helpers for integer numbers.

Here is the call graph for this function:

◆ getSizeFixedWidth() [1/2]

Vec2 FontEngine::getSizeFixedWidth ( const std::string & text,
float winAspect,
float width ) const

Expected on-screen size of text for a fixed width.

Here is the caller graph for this function:

◆ getSizeFixedWidth() [2/2]

Vec2 FontEngine::getSizeFixedWidth ( uint32_t number,
float winAspect,
float width ) const
Here is the call graph for this function:

◆ render() [1/2]

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.

Parameters
textString to draw (unknown chars are rendered as '_').
winAspectWindow aspect ratio (width/height) used for pixel-correct scaling.
heightNormalized line height in NDC (Y span of one line).
posAnchor position in NDC ([-1,1]²).
aAlignment relative to pos.
colorRGBA color multiplier.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render() [2/2]

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.

Here is the call graph for this function:

◆ renderFixedWidth() [1/2]

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).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ renderFixedWidth() [2/2]

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} )
Here is the call graph for this function:

◆ setRenderAsSignedDistanceField()

void FontEngine::setRenderAsSignedDistanceField ( bool renderAsSignedDistanceField)
inline

Enable/disable signed distance field rendering.

Member Data Documentation

◆ chars

std::map<char,CharTex> FontEngine::chars

Per-character textures + transforms.

◆ sdChars

std::map<char,CharTex> FontEngine::sdChars

Per-character SDF textures + transforms.


The documentation for this class was generated from the following files: