#pragma once #include #include #include #include #include #include "render/Renderer.h" namespace ZL { struct GlyphInfo { unsigned int texID = 0; // GL texture for glyph Eigen::Vector2f size; // glyph size in pixels Eigen::Vector2f bearing; // offset from baseline unsigned int advance = 0; // advance.x in 1/64 pixels }; class TextRenderer { public: TextRenderer() = default; ~TextRenderer(); bool init(Renderer& renderer, const std::string& ttfPath, int pixelSize); void drawText(const std::string& text, float x, float y, float scale, bool centered); private: bool loadGlyphs(const std::string& ttfPath, int pixelSize); Renderer* r = nullptr; std::unordered_map glyphs; // OpenGL objects for a dynamic quad unsigned int vao = 0; unsigned int vbo = 0; std::string shaderName = "text2d"; }; } // namespace ZL