Browse Source

Fill truetype font glyph atlases with transparent white instead of transparent black in the borders between glyphs. Fixes black fringes around text (resolves issue #1495) and reduces the appearance of flickering when text is moved at non-integer coordinates and gamma correct rendering isn't enabled (closes issue #1143).

Alex Szpakowski 6 years ago
parent
commit
02fa8b0b2b
1 changed files with 12 additions and 2 deletions
  1. 12 2
      src/modules/graphics/Font.cpp

+ 12 - 2
src/modules/graphics/Font.cpp

@@ -153,9 +153,19 @@ void Font::createTexture()
 	image->setFilter(filter);
 
 	{
-		// Initialize the texture with transparent black.
 		size_t bpp = getPixelFormatSize(pixelFormat);
-		std::vector<uint8> emptydata(size.width * size.height * bpp, 0);
+		size_t pixelcount = size.width * size.height;
+
+		// Initialize the texture with transparent white for Luminance-Alpha
+		// formats (since we keep luminance constant and vary alpha in those
+		// glyphs), and transparent black otherwise.
+		std::vector<uint8> emptydata(pixelcount * bpp, 0);
+
+		if (pixelFormat == PIXELFORMAT_LA8)
+		{
+			for (size_t i = 0; i < pixelcount; i++)
+				emptydata[i * 2 + 0] = 255;
+		}
 
 		Rect rect = {0, 0, size.width, size.height};
 		image->replacePixels(emptydata.data(), emptydata.size(), 0, 0, rect, false);