Brenta Engine 1.2
Loading...
Searching...
No Matches
text.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/buffer.hpp>
9#include <brenta/shader.hpp>
10#include <brenta/vao.hpp>
11#include <brenta/subsystem.hpp>
12
13#include <ft2build.h>
14#include <glm/glm.hpp>
15#include <glm/gtc/matrix_transform.hpp>
16#include <glm/gtc/type_ptr.hpp>
17
18#include <map>
19#include <string>
20
21#include FT_FREETYPE_H
22
23namespace brenta
24{
25
26namespace types
27{
28
38{
39 unsigned int texture_id; // ID handle of the glyph texture
40 glm::ivec2 size; // Size of glyph
41 glm::ivec2 bearing; // Offset from baseline to left/top of glyph
42 unsigned int advance; // Offset to advance to next glyph
43};
44
45} // namespace types
46
54class text : public subsystem
55{
56public:
57
63 static std::map<char, types::character> characters;
64
65 class config;
66 class builder;
67
68 static const std::string subsystem_name;
69 static const text::config default_config;
70 static text::config init_config;
71
72 // Subsystem interface
84 std::expected<void, subsystem::error> initialize() override;
85
89 std::expected<void, subsystem::error> terminate() override;
90 std::string name() override;
91 bool is_initialized() override;
92
93 // Constructors / destructors
94 text() = default;
95 ~text() = default;
96
97 // Member functions
98
99 static text &instance();
100
111 static void load(std::string font_name, int font_size = 48);
112
127 static void render_text(std::string text, float x, float y,
128 float scale, glm::vec3 color);
129
130private:
131
132 static types::shader_name_t shader;
133 static types::vao vao;
134 static types::buffer vbo;
135 static bool initialized;
136
137};
138
140{
141 std::string font_path;
142 int font_size;
143};
144
146{
147private:
148
149 text::config conf = text::default_config;
150
151public:
152
153 builder() = default;
154 ~builder() = default;
155
156 builder &font(const std::string &font_path);
157 builder &size(int font_size);
158
159 brenta::subsystem &build() override;
160
161};
162
163
164} // namespace brenta
Shader class.
Definition shader.hpp:43
Builder interface.
Definition subsystem.hpp:49
Subsystem interface.
Definition subsystem.hpp:22
Text subsystem.
Definition text.hpp:55
std::expected< void, subsystem::error > terminate() override
Cleaup resources.
Definition text.cpp:48
bool is_initialized() override
Returns true if the subsystem is initialized.
Definition text.cpp:62
static void render_text(std::string text, float x, float y, float scale, glm::vec3 color)
Render text.
Definition text.cpp:164
std::string name() override
Returns the name of the sybsystem.
Definition text.cpp:57
static void load(std::string font_name, int font_size=48)
Load a font.
Definition text.cpp:77
static std::map< char, types::character > characters
Map of characters.
Definition text.hpp:63
std::expected< void, subsystem::error > initialize() override
Initialize the text subsystem.
Definition text.cpp:33
Buffer wrapper around OpenGL buffer objects.
Definition buffer.hpp:30
Vertex Array Object (VAO)
Definition vao.hpp:23
Character struct.
Definition text.hpp:38