From f8b92ce3aa08b1445c9f956d8166830946562d12 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 3 Sep 2025 20:10:09 +0200 Subject: a --- src/render/gl_2d_font.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/render/gl_2d_font.h (limited to 'src/render/gl_2d_font.h') 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 +#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 ); -- cgit v1.2.3