1 #ifndef FREE_GLYPH_H_ 2 #define FREE_GLYPH_H_ 3 4 #include <stdlib.h> 5 #include "./la.h" 6 7 #define GLEW_STATIC 8 #include <GL/glew.h> 9 10 #define GL_GLEXT_PROTOTYPES 11 #include <SDL2/SDL_opengl.h> 12 13 #include <ft2build.h> 14 #include FT_FREETYPE_H 15 16 #include "simple_renderer.h" 17 18 #define FREE_GLYPH_FONT_SIZE 64 19 20 // https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_02 21 22 typedef struct { 23 float ax; // advance.x 24 float ay; // advance.y 25 26 float bw; // bitmap.width; 27 float bh; // bitmap.rows; 28 29 float bl; // bitmap_left; 30 float bt; // bitmap_top; 31 32 float tx; // x offset of glyph in texture coordinates 33 } Glyph_Metric; 34 35 #define GLYPH_METRICS_CAPACITY 128 36 37 typedef struct { 38 FT_UInt atlas_width; 39 FT_UInt atlas_height; 40 GLuint glyphs_texture; 41 Glyph_Metric metrics[GLYPH_METRICS_CAPACITY]; 42 } Free_Glyph_Atlas; 43 44 void free_glyph_atlas_init(Free_Glyph_Atlas *atlas, FT_Face face); 45 float free_glyph_atlas_cursor_pos(const Free_Glyph_Atlas *atlas, const char *text, size_t text_size, Vec2f pos, size_t col); 46 void free_glyph_atlas_measure_line_sized(Free_Glyph_Atlas *atlas, const char *text, size_t text_size, Vec2f *pos); 47 void free_glyph_atlas_render_line_sized(Free_Glyph_Atlas *atlas, Simple_Renderer *sr, const char *text, size_t text_size, Vec2f *pos, Vec4f color); 48 49 #endif // FREE_GLYPH_H_
