From 43394c8a8908442982e3a7e25975c31b3c952923 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Sun, 27 Oct 2024 12:52:55 +0200 Subject: root --- graphics/fonts.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 graphics/fonts.h (limited to 'graphics/fonts.h') 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 +#include FT_FREETYPE_H +#include "GL/glew.h" +#include "shader.h" +#include +#include +#include + +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::iterator m_curr_font; + std::unordered_map m_fonts; + Shader m_font_shader; + GLuint m_font_vbo; + GLuint m_font_vao; + GLuint m_font_res = 64; + std::vector 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); + +}; + -- cgit v1.2.3