1 /* 2 * File: gl_font.h 3 * Author: TeslaRus 4 * 5 * Created on January 16, 2015, 10:46 PM 6 */ 7 8 #ifndef GL_FONT_H 9 #define GL_FONT_H 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 #include <stdint.h> 16 #include <SDL2/SDL_platform.h> 17 #include <SDL2/SDL_opengl.h> 18 19 struct char_info_s; 20 21 typedef struct gl_tex_font_s 22 { 23 void *ft_face; // for internal usage only 24 struct char_info_s *glyphs; // for internal usage only 25 uint16_t font_size; 26 uint16_t glyphs_count; 27 uint16_t gl_tex_indexes_count; 28 uint16_t gl_real_tex_indexes_count; 29 GLuint *gl_tex_indexes; 30 GLint gl_max_tex_width; 31 GLint gl_tex_width; 32 GLfloat gl_font_color[4]; 33 }gl_tex_font_t, *gl_tex_font_p; 34 35 36 // Font struct contains additional field for font type which is 37 // used to dynamically create or delete fonts. 38 typedef struct gl_font_cont_s 39 { 40 uint16_t font_size; 41 struct gl_tex_font_s *gl_font; 42 }gl_font_cont_t, *gl_font_cont_p; 43 44 45 // Font style is different to font itself - whereas engine can have 46 // only three fonts, there could be unlimited amount of font styles. 47 // Font style management is done via font manager. 48 typedef struct gl_fontstyle_s 49 { 50 GLfloat font_color[4]; 51 GLfloat rect_color[4]; 52 GLfloat rect_border; 53 54 uint8_t shadowed; 55 uint8_t rect; 56 } gl_fontstyle_t, *gl_fontstyle_p; 57 58 #define GUI_FONT_FADE_SPEED 1.0 // Global fading style speed. 59 #define GUI_FONT_FADE_MIN 0.3 // Minimum fade multiplier. 60 61 #define GUI_FONT_SHADOW_TRANSPARENCY 0.7 62 #define GUI_FONT_SHADOW_VERTICAL_SHIFT -0.9 63 #define GUI_FONT_SHADOW_HORIZONTAL_SHIFT 0.7 64 65 66 void glf_init(); 67 void glf_destroy(); 68 69 gl_tex_font_p glf_create_font(const char *file_name, uint16_t font_size); 70 gl_tex_font_p glf_create_font_mem(void *face_data, size_t face_data_size, uint16_t font_size); 71 void glf_free_font(gl_tex_font_p glf); 72 void glf_resize(gl_tex_font_p glf, uint16_t font_size); 73 74 int32_t glf_get_string_len(gl_tex_font_p glf, const char *text, int n); // size in 1 / 64 px 75 char *glf_get_string_for_width(gl_tex_font_p glf, char *text, int32_t w_pt, int *n_sym); 76 int32_t glf_get_ascender(gl_tex_font_p glf); // size in 1 / 64 px 77 uint16_t glf_get_font_size(gl_tex_font_p glf); 78 void glf_get_string_bb(gl_tex_font_p glf, const char *text, int n, int32_t *x0, int32_t *y0, int32_t *x1, int32_t *y1); // size in 1 / 64 px 79 80 void glf_render_str(gl_tex_font_p glf, GLfloat x, GLfloat y, const char *text, int32_t n_sym); // UTF-8 81 82 83 #ifdef __cplusplus 84 } 85 #endif 86 87 #endif /* GL_FONT_H */ 88 89