summaryrefslogtreecommitdiff
path: root/graphics/fonts.h
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/fonts.h')
-rw-r--r--graphics/fonts.h54
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);
+
+};
+