Add one-pixel boundary and fix texture coordinates for font characters
This should finally fix the issue of pixelated text
dev-time-step
Piotr Dziwinski 2016-04-03 16:45:13 +12:00
parent 3a3653d47e
commit 72f966b118
2 changed files with 8 additions and 8 deletions

View File

@ -944,10 +944,11 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
Math::Point p1(pos.x, pos.y); Math::Point p1(pos.x, pos.y);
Math::Point p2(pos.x + charInterfaceSize.x, pos.y + charInterfaceSize.y); Math::Point p2(pos.x + charInterfaceSize.x, pos.y + charInterfaceSize.y);
Math::Point texCoord1(static_cast<float>(tex.charPos.x) / FONT_TEXTURE_SIZE.x, const float halfPixelMargin = 0.5f;
static_cast<float>(tex.charPos.y) / FONT_TEXTURE_SIZE.y); Math::Point texCoord1(static_cast<float>(tex.charPos.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x,
Math::Point texCoord2(static_cast<float>(tex.charPos.x + tex.charSize.x) / FONT_TEXTURE_SIZE.x, static_cast<float>(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y);
static_cast<float>(tex.charPos.y + tex.charSize.y) / FONT_TEXTURE_SIZE.y); Math::Point texCoord2(static_cast<float>(tex.charPos.x + tex.charSize.x + halfPixelMargin) / FONT_TEXTURE_SIZE.x,
static_cast<float>(tex.charPos.y + tex.charSize.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y);
Math::Vector n(0.0f, 0.0f, -1.0f); // normal Math::Vector n(0.0f, 0.0f, -1.0f); // normal
Vertex quad[4] = Vertex quad[4] =
@ -1061,8 +1062,9 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
return texture; return texture;
} }
Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w), const int pixelMargin = 1;
Math::NextPowerOfTwo(textSurface->h)); Math::IntPoint tileSize(Math::NextPowerOfTwo(textSurface->w) + pixelMargin,
Math::NextPowerOfTwo(textSurface->h) + pixelMargin);
FontTexture* fontTexture = GetOrCreateFontTexture(tileSize); FontTexture* fontTexture = GetOrCreateFontTexture(tileSize);
@ -1075,7 +1077,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
texture.id = fontTexture->id; texture.id = fontTexture->id;
texture.charPos = GetNextTilePos(*fontTexture); texture.charPos = GetNextTilePos(*fontTexture);
texture.charSize = Math::IntPoint(textSurface->w, textSurface->h); texture.charSize = Math::IntPoint(textSurface->w, textSurface->h);
texture.tileSize = tileSize;
ImageData imageData; ImageData imageData;
imageData.surface = textSurface; imageData.surface = textSurface;

View File

@ -193,7 +193,6 @@ struct CharTexture
unsigned int id = 0; unsigned int id = 0;
Math::IntPoint charPos; Math::IntPoint charPos;
Math::IntPoint charSize; Math::IntPoint charSize;
Math::IntPoint tileSize;
}; };
// Definition is private - in text.cpp // Definition is private - in text.cpp