Textogl  1.1.2
OpenGL Text renderer
Public Member Functions | List of all members
textogl::Font_sys Class Reference

Container for font and text rendering. More...

#include <font.hpp>

Public Member Functions

 Font_sys (const std::string &font_path, const unsigned int font_size)
 Load a font file at a specified size. More...
 
 Font_sys (const unsigned char *font_data, const std::size_t font_data_size, const unsigned int font_size)
 Load a font at a specified size from memory. More...
 
void resize (const unsigned int font_size)
 Resize font. More...
 
void render_text (const std::string &utf8_input, const Color &color, const Vec2< float > &win_size, const Vec2< float > &pos, const int align_flags=0)
 Render given text. More...
 
void render_text_rotate (const std::string &utf8_input, const Color &color, const Vec2< float > &win_size, const Vec2< float > &pos, const float rotation, const int align_flags=0)
 Render given text, with rotatation. More...
 
void render_text_mat (const std::string &utf8_input, const Color &color, const Mat4< float > &model_view_projection)
 Render given text, using a model view projection matrix. More...
 

Detailed Description

Container for font and text rendering.

Contains everything needed for rendering from the specified font at the specified size. Unicode is supported for all glyphs provided by the specified font.

Rendering data is created by unicode code page (block of 256 code-points), as it is used. Only those pages that are used are built. The 1st page (Basic Latin and Latin-1 Supplement) is always created.

Constructor & Destructor Documentation

◆ Font_sys() [1/2]

textogl::Font_sys::Font_sys ( const std::string &  font_path,
const unsigned int  font_size 
)

Load a font file at a specified size.

Parameters
font_pathPath to font file to use
font_sizeFont size (in pixels)

◆ Font_sys() [2/2]

textogl::Font_sys::Font_sys ( const unsigned char *  font_data,
const std::size_t  font_data_size,
const unsigned int  font_size 
)

Load a font at a specified size from memory.

data is not copied, so the client is responsible for maintaining the data for the lifetime of this object

Parameters
font_dataFont file data (in memory)
font_data_sizeFont file data's size in memory
font_sizeFont size (in pixels)

Member Function Documentation

◆ render_text()

void textogl::Font_sys::render_text ( const std::string &  utf8_input,
const Color color,
const Vec2< float > &  win_size,
const Vec2< float > &  pos,
const int  align_flags = 0 
)

Render given text.

Renders the text supplied in utf8_input parameter

Note
This will rebuild the OpenGL primitives each call. If the text will not change frequently, use a Static_text object instead
Parameters
utf8_inputText to render, in UTF-8 encoding. For best performance, normalize the string before rendering
colorText Color
win_sizeWindow dimensions. A Vec2 with X = width and Y = height
posRender position, in screen pixels
align_flagsText Alignment. Should be Text_origin flags bitwise-OR'd together

◆ render_text_mat()

void textogl::Font_sys::render_text_mat ( const std::string &  utf8_input,
const Color color,
const Mat4< float > &  model_view_projection 
)

Render given text, using a model view projection matrix.

Renders the text supplied in utf8_input parameter, using a model view projection matrix

Note
This will rebuild the OpenGL primitives each call. If the text will not change frequently, use a Static_text object instead
Parameters
utf8_inputText to render, in UTF-8 encoding. For best performance, normalize the string before rendering
colorText Color
model_view_projectionModel view projection matrix. The text will be rendered as quads, one for each glyph, with vertex coordinates centered on the baselines and sized in pixels. This matrix will be used to transform that geometry

◆ render_text_rotate()

void textogl::Font_sys::render_text_rotate ( const std::string &  utf8_input,
const Color color,
const Vec2< float > &  win_size,
const Vec2< float > &  pos,
const float  rotation,
const int  align_flags = 0 
)

Render given text, with rotatation.

Renders the text supplied in utf8_input parameter

Note
This will rebuild the OpenGL primitives each call. If the text will not change frequently, use a Static_text object instead
Parameters
utf8_inputText to render, in UTF-8 encoding. For best performance, normalize the string before rendering
colorText Color
win_sizeWindow dimensions. A Vec2 with X = width and Y = height
posRender position, in screen pixels
rotationClockwise text rotation (in radians) around origin as defined in align_flags. 0 is vertical
align_flagsText Alignment. Should be Text_origin flags bitwise-OR'd together

◆ resize()

void textogl::Font_sys::resize ( const unsigned int  font_size)

Resize font.

Resizes the font without destroying it

Note
This will require rebuilding font textures
Any Static_text objects tied to this Font_sys will need to have Static_text::set_font_sys called
Parameters
font_sizeFont size (in pixels)

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