From 72f966b1184eec4fee04260cd2fedb544e80ee6a Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 3 Apr 2016 16:45:13 +1200 Subject: [PATCH] Fix for #738 Add one-pixel boundary and fix texture coordinates for font characters This should finally fix the issue of pixelated text --- src/graphics/engine/text.cpp | 15 ++++++++------- src/graphics/engine/text.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index c1317f1e..7ecf204c 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -944,10 +944,11 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P Math::Point p1(pos.x, pos.y); Math::Point p2(pos.x + charInterfaceSize.x, pos.y + charInterfaceSize.y); - Math::Point texCoord1(static_cast(tex.charPos.x) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y) / FONT_TEXTURE_SIZE.y); - Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x) / FONT_TEXTURE_SIZE.x, - static_cast(tex.charPos.y + tex.charSize.y) / FONT_TEXTURE_SIZE.y); + const float halfPixelMargin = 0.5f; + Math::Point texCoord1(static_cast(tex.charPos.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); + Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x, + static_cast(tex.charPos.y + tex.charSize.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); Math::Vector n(0.0f, 0.0f, -1.0f); // normal Vertex quad[4] = @@ -1061,8 +1062,9 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) return texture; } - Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w), - Math::NextPowerOfTwo(textSurface->h)); + const int pixelMargin = 1; + Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w) + pixelMargin, + Math::NextPowerOfTwo(textSurface->h) + pixelMargin); FontTexture* fontTexture = GetOrCreateFontTexture(tileSize); @@ -1075,7 +1077,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) texture.id = fontTexture->id; texture.charPos = GetNextTilePos(*fontTexture); texture.charSize = Math::IntPoint(textSurface->w, textSurface->h); - texture.tileSize = tileSize; ImageData imageData; imageData.surface = textSurface; diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 962c755f..6ee0a862 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -193,7 +193,6 @@ struct CharTexture unsigned int id = 0; Math::IntPoint charPos; Math::IntPoint charSize; - Math::IntPoint tileSize; }; // Definition is private - in text.cpp