Brenta Engine 1.2
Loading...
Searching...
No Matches
brenta::text Class Reference

Text subsystem. More...

#include <text.hpp>

Inheritance diagram for brenta::text:
brenta::subsystem

Data Structures

class  builder
 
struct  config
 

Public Member Functions

std::expected< void, subsystem::error > initialize () override
 Initialize the text subsystem.
 
std::expected< void, subsystem::error > terminate () override
 Cleaup resources.
 
std::string name () override
 Returns the name of the sybsystem.
 
bool is_initialized () override
 Returns true if the subsystem is initialized.
 
- Public Member Functions inherited from brenta::subsystem

Static Public Member Functions

static textinstance ()
 
static void load (std::string font_name, int font_size=48)
 Load a font.
 
static void render_text (std::string text, float x, float y, float scale, glm::vec3 color)
 Render text.
 

Static Public Attributes

static std::map< char, types::charactercharacters
 Map of characters.
 
static const std::string subsystem_name = "text"
 
static const text::config default_config
 
static text::config init_config = default_config
 

Additional Inherited Members

- Public Types inherited from brenta::subsystem
using error = std::string
 

Detailed Description

Text subsystem.

This class is used to render text on the screen. The text is rendered using the FreeType library to load the font and the characters, and OpenGL to render the text on the screen.

Definition at line 54 of file text.hpp.

Member Function Documentation

◆ initialize()

std::expected< void, subsystem::error > text::initialize ( )
overridevirtual

Initialize the text subsystem.

This method initializes the text subsystem by loading the shader, the VAO, and the VBO. The shader is loaded from the file text.vs and text.fs, and the VAO and VBO are created using the data from the characters map.

Note: opengl context must be created before calling this method.

Implements brenta::subsystem.

Definition at line 33 of file text.cpp.

◆ instance()

text & text::instance ( )
static

Definition at line 71 of file text.cpp.

◆ is_initialized()

bool text::is_initialized ( )
overridevirtual

Returns true if the subsystem is initialized.

Implements brenta::subsystem.

Definition at line 62 of file text.cpp.

◆ load()

void text::load ( std::string font_name,
int font_size = 48 )
static

Load a font.

This method loads a font from the given file and size. The font is loaded using the FreeType library, and the characters are stored in the characters map.

Parameters
font_nameName of the font file
font_sizeThe size of the font

Definition at line 77 of file text.cpp.

◆ name()

std::string text::name ( )
overridevirtual

Returns the name of the sybsystem.

Implements brenta::subsystem.

Definition at line 57 of file text.cpp.

◆ render_text()

void text::render_text ( std::string text,
float x,
float y,
float scale,
glm::vec3 color )
static

Render text.

This method renders the given text on the screen at the given position, with the given scale and color. The text is rendered using the shader, VAO, and VBO that are initialized in the Init method.

Parameters
textText to render
xX position of the text
yY position of the text
scaleScale of the text
colorColor of the text

Definition at line 164 of file text.cpp.

◆ terminate()

std::expected< void, subsystem::error > text::terminate ( )
overridevirtual

Cleaup resources.

Implements brenta::subsystem.

Definition at line 48 of file text.cpp.

Field Documentation

◆ characters

std::map< char, types::character > text::characters
static

Map of characters.

Map an ascii character to a Character struct

Definition at line 63 of file text.hpp.

◆ default_config

const text::config text::default_config
static
Initial value:
= {
"examples/assets/fonts/arial.ttf",
48,
}

Definition at line 69 of file text.hpp.

◆ init_config

text::config text::init_config = default_config
static

Definition at line 70 of file text.hpp.

◆ subsystem_name

const std::string text::subsystem_name = "text"
static

Definition at line 68 of file text.hpp.


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