From 1f68fe78e84f25c8ddacdc37a293a5de31725bab Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 1 Jan 2022 13:01:08 +0000 Subject: First iteration with font/text support --- ui/font.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ui/font.h (limited to 'ui/font.h') 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 +#include +#include +#include +#include +#include +#include +#include +#include + +class Font { +public: + Font(const char * const path, unsigned int height); + + using Quad = std::array; + using Quads = std::vector; + using TextureQuads = std::map; + 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 charsData; + mutable std::vector fontTextures; +}; + +#endif -- cgit v1.2.3