diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-19 03:43:27 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-19 03:43:27 +0100 |
commit | 6da1df6204ae118ceada0eff08a0ac7d42b3548a (patch) | |
tree | 527886112ec361058c63a43ee8f2286c9a60edb7 /src | |
parent | f4833afa1afa56def5a6d54fa8ce22d3a9b4eb55 (diff) |
Slightly improve font rendering quality
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics/font.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/graphics/font.c b/src/graphics/font.c index aa349a6..b6ceaf5 100644 --- a/src/graphics/font.c +++ b/src/graphics/font.c @@ -7,6 +7,7 @@ /* Need padding so filtering doesn't touch pixels in another glyphs area */ #define GLYPH_PADDING 2 #define GLYPH_UPSAMPLE 1 +#define GLYPH_SHIFT 0.5f int mgl_font_load_from_file(mgl_font *self, const mgl_memory_mapped_file *mapped_file, unsigned int character_size) { self->texture.id = 0; @@ -167,7 +168,7 @@ int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph const float glyph_advance = font_scale * advance; int x0, y0, x1, y1; - stbtt_GetGlyphBitmapBox(self->font_info, glyph_index, font_scale, font_scale, &x0, &y0, &x1, &y1); + stbtt_GetGlyphBitmapBoxSubpixel(self->font_info, glyph_index, font_scale, font_scale, GLYPH_SHIFT, GLYPH_SHIFT, &x0, &y0, &x1, &y1); int width = x1 - x0; int height = y1 - y0; @@ -181,7 +182,7 @@ int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph unsigned char *pixels = calloc(pixels_size, 1); if(pixels) { const int top_padding = GLYPH_PADDING; - stbtt_MakeGlyphBitmap(self->font_info, pixels + pixels_width * top_padding + GLYPH_PADDING, width, height, pixels_width, font_scale, font_scale, glyph_index); + stbtt_MakeGlyphBitmapSubpixel(self->font_info, pixels + pixels_width * top_padding + GLYPH_PADDING, width, height, pixels_width, font_scale, font_scale, GLYPH_SHIFT, GLYPH_SHIFT, glyph_index); } mgl_vec2i render_offset; |