From 2e267e0b3998782c75c5e2a5ab7bc4eeb3a74c9f Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 23 Jun 2022 21:15:43 +0000 Subject: [PATCH] ... --- source/engine/font.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/source/engine/font.c b/source/engine/font.c index 0814c75..b4b49b3 100755 --- a/source/engine/font.c +++ b/source/engine/font.c @@ -8,8 +8,6 @@ #include #include - - #include static uint32_t VBO = 0; @@ -34,17 +32,23 @@ struct sFont *MakeFont(const char *fontfile, int height) snprintf(fontpath, 256, "fonts/%s", fontfile); stbtt_fontinfo fontinfo = { 0 }; - int ascent = 0; + int ascent, descent, linegap; - fread(ttf_buffer, 1, 1<<25, fopen(fontpath, "rb")); + fread(ttf_buffer, 1, 1<<25, fopen(fontpath, "rb")); - stbtt_InitFont(&fontinfo, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0)); + if (!stbtt_InitFont(&fontinfo, ttf_buffer, 0)) { + printf("failed\n"); + } - stbtt_GetFontVMetrics(&fontinfo, &ascent, 0, 0); + float scale = stbtt_ScaleForPixelHeight(&fontinfo, 64); + + stbtt_GetFontVMetrics(&fontinfo, &ascent, &descent, &linegap); + ascent = roundf(ascent*scale); + descent=roundf(descent*scale); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - for (unsigned char c = 0; c < 128; c++) { + for (unsigned char c = 32; c < 128; c++) { unsigned char *bitmap; int advance, lsb, w, h; stbtt_GetCodepointHMetrics(&fontinfo, c, &advance, &lsb);