Browse Source

Extrude font glyph quads by 1 pixel to add some antialiasing at the edges of the glyphs.

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
76a7d30f1a
2 changed files with 13 additions and 5 deletions
  1. 9 4
      src/modules/graphics/Font.cpp
  2. 4 1
      src/modules/graphics/Font.h

+ 9 - 4
src/modules/graphics/Font.cpp

@@ -258,15 +258,20 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
 
 
 		Color c(255, 255, 255, 255);
 		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
 		// 0---2
 		// | / |
 		// | / |
 		// 1---3
 		// 1---3
 		const GlyphVertex verts[4] =
 		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.
 		// Copy vertex data to the glyph and set proper bearing.

+ 4 - 1
src/modules/graphics/Font.h

@@ -238,7 +238,10 @@ private:
 	// ID which is incremented when the texture cache is invalidated.
 	// ID which is incremented when the texture cache is invalidated.
 	uint32 textureCacheID;
 	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.
 	// This will be used if the Rasterizer doesn't have a tab character itself.
 	static const int SPACES_PER_TAB = 4;
 	static const int SPACES_PER_TAB = 4;