diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-15 08:20:13 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-15 08:20:13 +0100 |
commit | a3c6774f211ee765f910df76837548bdadd4e959 (patch) | |
tree | 499b29166c04fa62cb946c7d395f8a5299c78fbf /src/graphics/text.c | |
parent | c4f84e1969f4c856a5bf0352e99fcb73a4cf56cf (diff) |
Add dynamic font atlas creation (not finished)
Diffstat (limited to 'src/graphics/text.c')
-rw-r--r-- | src/graphics/text.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/graphics/text.c b/src/graphics/text.c index d330dc0..ea60b6a 100644 --- a/src/graphics/text.c +++ b/src/graphics/text.c @@ -4,6 +4,8 @@ #include "../../include/mgl/mgl.h" #include <stdio.h> +/* TODO: Cache mgl_font_get_glyph */ + #define TAB_WIDTH 4 static float max_float(float a, float b) { @@ -95,7 +97,7 @@ mgl_vec2f mgl_text_get_bounds(const mgl_text *self) { return self->bounds; } -static void mgl_text_draw_glyph(mgl_context *context, mgl_font_glyph *glyph, mgl_vec2f position) { +static void mgl_text_draw_glyph(mgl_context *context, mgl_font_glyph *glyph, mgl_vec2i position) { context->gl.glTexCoord2f(glyph->texture_position.x, glyph->texture_position.y); context->gl.glVertex3f(position.x + glyph->position.x, position.y + glyph->position.y, 0.0f); @@ -116,11 +118,11 @@ void mgl_text_draw(mgl_context *context, mgl_text *text) { return; mgl_font_glyph glyph; - mgl_vec2f position = text->position; + mgl_vec2i position = (mgl_vec2i){ text->position.x, text->position.y }; position.y += text->font->character_size; context->gl.glColor4ub(text->color.r, text->color.g, text->color.b, text->color.a); - context->gl.glBindTexture(GL_TEXTURE_2D, text->font->texture.id); + mgl_texture_use(&text->font->texture); context->gl.glBegin(GL_QUADS); for(size_t i = 0; i < text->text_size;) { unsigned char *cp = (unsigned char*)&text->text[i]; @@ -147,5 +149,5 @@ void mgl_text_draw(mgl_context *context, mgl_text *text) { i += clen; } context->gl.glEnd(); - context->gl.glBindTexture(GL_TEXTURE_2D, 0); + mgl_texture_use(NULL); } |