summaryrefslogtreecommitdiff
path: root/ui/font.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-01-01 13:01:08 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-01-01 14:40:06 +0000
commit1f68fe78e84f25c8ddacdc37a293a5de31725bab (patch)
tree4537db483391b579387c1bcc00c3f1e3b6adc106 /ui/font.h
parentAdd glm::vec concatenation operator|| (diff)
downloadilt-1f68fe78e84f25c8ddacdc37a293a5de31725bab.tar.bz2
ilt-1f68fe78e84f25c8ddacdc37a293a5de31725bab.tar.xz
ilt-1f68fe78e84f25c8ddacdc37a293a5de31725bab.zip
First iteration with font/text support
Diffstat (limited to 'ui/font.h')
-rw-r--r--ui/font.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/ui/font.h b/ui/font.h
new file mode 100644
index 0000000..c9d834a
--- /dev/null
+++ b/ui/font.h
@@ -0,0 +1,48 @@
+#ifndef FONT_H
+#define FONT_H
+
+#include <GL/glew.h>
+#include <array>
+#include <cstddef>
+#include <cstdint>
+#include <glm/glm.hpp>
+#include <map>
+#include <string>
+#include <string_view>
+#include <vector>
+
+class Font {
+public:
+ Font(const char * const path, unsigned int height);
+
+ using Quad = std::array<glm::vec4, 4>;
+ using Quads = std::vector<Quad>;
+ using TextureQuads = std::map<GLuint /*textureId*/, Quads>;
+ TextureQuads render(const std::string_view text) const;
+
+ struct CharData {
+ size_t textureIdx;
+ glm::uvec2 size;
+ glm::uvec2 position;
+ glm::ivec2 bearing;
+ long advance;
+ };
+ struct FontTexture {
+ GLuint texture;
+ unsigned int used;
+ };
+
+ static glm::uvec3 getTextureSize(unsigned int height);
+
+protected:
+ void generateChars(const std::string_view text) const;
+ const CharData getChar(char) const;
+ std::size_t getTextureWithSpace(unsigned int adv) const;
+
+ std::string path;
+ glm::uvec3 size;
+ mutable std::map<uint32_t, CharData> charsData;
+ mutable std::vector<FontTexture> fontTextures;
+};
+
+#endif