From 76a7d30f1a2e4a55e1500ab429dba211ae5a47e0 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 19 May 2017 20:28:37 -0300 Subject: [PATCH] Extrude font glyph quads by 1 pixel to add some antialiasing at the edges of the glyphs. --HG-- branch : minor --- src/modules/graphics/Font.cpp | 13 +++++++++---- src/modules/graphics/Font.h | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/Font.cpp b/src/modules/graphics/Font.cpp index e0cbb9e9a..7efd00246 100644 --- a/src/modules/graphics/Font.cpp +++ b/src/modules/graphics/Font.cpp @@ -258,15 +258,20 @@ const Font::Glyph &Font::addGlyph(uint32 glyph) Color c(255, 255, 255, 255); + // Extrude the quad borders by 1 pixel. We have an extra pixel of + // transparent padding in the texture atlas, so the quad extrusion will + // add some antialiasing at the edges of the quad. + int o = 1; + // 0---2 // | / | // 1---3 const GlyphVertex verts[4] = { - {0.0f, 0.0f, normToUint16((tX+0)/tWidth), normToUint16((tY+0)/tHeight), c}, - {0.0f, h/pixelDensity, normToUint16((tX+0)/tWidth), normToUint16((tY+h)/tHeight), c}, - {w/pixelDensity, 0.0f, normToUint16((tX+w)/tWidth), normToUint16((tY+0)/tHeight), c}, - {w/pixelDensity, h/pixelDensity, normToUint16((tX+w)/tWidth), normToUint16((tY+h)/tHeight), c} + {float(-o), float(-o), normToUint16((tX-o)/tWidth), normToUint16((tY-o)/tHeight), c}, + {float(-o), (h+o)/pixelDensity, normToUint16((tX-o)/tWidth), normToUint16((tY+h+o)/tHeight), c}, + {(w+o)/pixelDensity, float(-o), normToUint16((tX+w+o)/tWidth), normToUint16((tY-o)/tHeight), c}, + {(w+o)/pixelDensity, (h+o)/pixelDensity, normToUint16((tX+w+o)/tWidth), normToUint16((tY+h+o)/tHeight), c} }; // Copy vertex data to the glyph and set proper bearing. diff --git a/src/modules/graphics/Font.h b/src/modules/graphics/Font.h index df5559de1..154d5eb9c 100644 --- a/src/modules/graphics/Font.h +++ b/src/modules/graphics/Font.h @@ -238,7 +238,10 @@ private: // ID which is incremented when the texture cache is invalidated. uint32 textureCacheID; - static const int TEXTURE_PADDING = 1; + // 1 pixel of transparent padding between glyphs (so quads won't pick up + // other glyphs), plus one pixel of transparent padding that the quads will + // use, for edge antialiasing. + static const int TEXTURE_PADDING = 2; // This will be used if the Rasterizer doesn't have a tab character itself. static const int SPACES_PER_TAB = 4;