diff options
author | Nikolas <nikolas@boutalas.com> | 2024-10-27 12:52:55 +0200 |
---|---|---|
committer | Nikolas <nikolas@boutalas.com> | 2024-10-27 12:52:55 +0200 |
commit | 43394c8a8908442982e3a7e25975c31b3c952923 (patch) | |
tree | 2facd563e29f48fe3b0653ac5c113998940b4d5e /graphics/fonts.h |
Diffstat (limited to 'graphics/fonts.h')
-rw-r--r-- | graphics/fonts.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/graphics/fonts.h b/graphics/fonts.h new file mode 100644 index 0000000..2ddcd43 --- /dev/null +++ b/graphics/fonts.h @@ -0,0 +1,54 @@ +#pragma once +#include <ft2build.h> +#include FT_FREETYPE_H +#include "GL/glew.h" +#include "shader.h" +#include <string> +#include <vector> +#include <unordered_map> + +struct Font +{ + std::string fontname; + FT_Face face; + GLuint font_tex; +}; + +struct TextRecord +{ + glm::vec2 pos; + glm::vec2 size; + std::string text; + glm::vec4 color1; + glm::vec4 color2; + glm::vec2 gradient; + bool use_gradient; + glm::mat4 mv; + glm::mat4 proj; +}; + + +class FontLib +{ + static FT_Library m_ft; + std::unordered_map<std::string, Font>::iterator m_curr_font; + std::unordered_map<std::string, Font> m_fonts; + Shader m_font_shader; + GLuint m_font_vbo; + GLuint m_font_vao; + GLuint m_font_res = 64; + std::vector<TextRecord> m_content; + + glm::vec2 m_canvas; + + void drawText(TextRecord entry); + +public: + bool init(); + void submitText(const TextRecord & text); + void commitText(); + void setCanvas(glm::vec2 sz); + bool setCurrentFont(std::string fontname); + +}; + |