Commit: e1a7bae479960e5c64543c691955941fb1e05c6d
Parent: 2976aa5264988d49f819abbb5e7f1e828122f986
Author: Randy Palamar
Date: Mon, 26 Aug 2024 10:01:06 -0600
fix blurry font rendering
The last time I fixed this I clearly didn't understand the problem
so I made the mistake again. FreeType already includes subpixel
rendering so if you try to draw a non-pixel aligned glyph
everything will get smeared and look awful.
Diffstat:
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/frag_render.glsl b/frag_render.glsl
@@ -17,7 +17,7 @@ void main()
vec4 fg = unpackUnorm4x8(u_texcolour[fs_in.index].x).wzyx;
vec4 bg = unpackUnorm4x8(u_texcolour[fs_in.index].y).wzyx;
- vec3 tex_coord = vec3(fs_in.tex_coord.xy, u_charmap[fs_in.index]);
+ vec3 tex_coord = vec3(fs_in.tex_coord, u_charmap[fs_in.index]);
tex_coord.xy *= u_texscale[fs_in.index];
float a = u_texscale[fs_in.index].x == 0 ? 0 : texture(u_texslot, tex_coord).a;
diff --git a/vtgl.c b/vtgl.c
@@ -82,7 +82,9 @@ get_terminal_top_left(Term *t)
{
v2 os = get_occupied_size(t);
v2 delta = {.x = t->gl.window_size.w - os.w, .y = t->gl.window_size.h - os.h};
- v2 result = {.x = delta.x / 2, .y = t->gl.window_size.h - delta.y / 2};
+ /* NOTE: IMPORTANT: freetype fonts already have subpixel rendering so cells must
+ * be aligned on pixels. If they are not glyphs will look like crap */
+ v2 result = {.x = (u32)(delta.x / 2), .y = (u32)(t->gl.window_size.h - delta.y / 2)};
return result;
}