diff options
Diffstat (limited to 'src/render/gl_2d_font.h')
| -rw-r--r-- | src/render/gl_2d_font.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/render/gl_2d_font.h b/src/render/gl_2d_font.h new file mode 100644 index 0000000..71154c0 --- /dev/null +++ b/src/render/gl_2d_font.h @@ -0,0 +1,52 @@ +#pragma once +#include <ft2build.h> +#include FT_FREETYPE_H + +#include "gl.h" +#include "../util/thread.h" + +extern THREAD_MUTEX font_mutex; + +typedef struct { + F32 offset_x; + F32 offset_y; + U32 width; + U32 height; + F32 advance_x; + F32 advance_y; + U32 bearing; +} FONT_GLYPH; + +const I32 GL_FONT_MAX_GLYPHS = 256; +typedef struct GL_FONT { + FT_Face face; + I32 size; + + U32* bitmap; + U32 bitmap_width; + U32 bitmap_height; + U32 char_width; + U32 char_height; + + GL_TEX2D* atlas; + const char* name; + + FONT_GLYPH glyphs[GL_FONT_MAX_GLYPHS]; +} *PGL_FONT; + +GL_FONT* gl_font_create( GL_DATA* gl, const char* path, I32 size ); +void gl_font_destroy( GL_DATA* gl, GL_FONT* font ); + +void gl_font_draw( GL_FONT* font, GL_SHADER_PROGRAM* shader, VEC2 pos, const char* text, CLR color, F32 scale = 1.0f ); +void gl_font_textured( + GL_FONT* font, + GL_SHADER_PROGRAM* shader, + VEC2 pos, + const char* text, + GL_TEX2D* tex, + CLR color = (CLR){1.f, 1.f, 1.f, 1.f}, + F32 scale = 1.0f +); + +VEC2 gl_font_dim( GL_FONT* font, const char* text, F32 scale = 1.0f ); +void gl_font_fit_into_box( GL_FONT* font, const char* source, char* out, F32 box_width, F32 box_height, F32 scale ); |
