From a25f066a05e8dfb54d0fd359d6422c1833799c76 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sat, 30 Apr 2022 10:52:55 -0700 Subject: [PATCH] fnl: eliminate text halo Fill fully-transparent pixels on the destination texture with the text color before rendering to it. This eliminates halos around text caused by the invisible texture color (usually black) being blended with the text. --- src/draw.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/draw.c b/src/draw.c index 3edfd85..e2760e5 100644 --- a/src/draw.c +++ b/src/draw.c @@ -790,11 +790,22 @@ void gfx_copy_stretch_with_alpha_map(Texture *dst, int dx, int dy, int dw, int d // XXX: Not an actual DrawGraph function; used for rendering text void gfx_draw_glyph(Texture *dst, float dx, int dy, Texture *glyph, SDL_Color color, float scale_x, float bold_width) { + dx = roundf(dx); + + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ONE); + struct copy_data fill_data = COPY_DATA(dx, dy, dx, dy, glyph->w * scale_x, glyph->h); + fill_data.r = color.r / 255.0; + fill_data.g = color.g / 255.0; + fill_data.b = color.b / 255.0; + fill_data.a = 0.0; + fill_data.threshold = 0.001; + run_copy_shader(&fill_amap_under_border_shader.s, dst, dst, &fill_data); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); struct copy_data data = STRETCH_DATA( - roundf(dx), dy, glyph->w * scale_x, glyph->h, - 0, 0, glyph->w, glyph->h); + dx, dy, glyph->w * scale_x, glyph->h, + 0, 0, glyph->w, glyph->h); data.r = color.r / 255.0; data.g = color.g / 255.0; data.b = color.b / 255.0;