#pragma once #include #include #include FT_FREETYPE_H #include "shader.h" #include "types.h" struct TextVertex { float x, y, s, t, r, g, b; }; /* State of a single charactrer glyph. */ struct character { int size[2]; int bearing[2]; unsigned int advance; float tx, ty; /* x and y offset of glyph in texture atlas. */ float tw, th; /* width and height of glyph in texture atlas. */ }; const int MAX_GLYPHS_PER_BATCH = 10000; const int VERTICES_PER_GLYPH = 6; const int MAX_VERTICES = MAX_GLYPHS_PER_BATCH * VERTICES_PER_GLYPH; class TextRenderer { public: TextRenderer(unsigned int screen_width, unsigned int screen_height); ~TextRenderer(void); void load_font(const char* font_path, unsigned int font_size); void render_text(const char* text, float x, float y, const Color& color); float get_text_width(const char* text, float scale); void begin(void); void flush(void); private: Shader* _txt_shader; unsigned int _vao, _vbo; unsigned int _atlas_texture_id; character _chars[128]; std::vector _vertices; float _projecton[16]; };