From 7cc901bb7fd78e954c786e32f3743b83b63b1084 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 19 May 2024 18:39:26 +0200 Subject: [PATCH] Fixed an issue where updating font textures caused random glyph artifacts --- es-core/src/resources/Font.cpp | 20 +++++++++----------- es-core/src/resources/Font.h | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index 5e6c3e00c..345f6e0bf 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// ES-DE +// ES-DE Frontend // Font.h // // Loading, unloading, caching and rendering of fonts. @@ -639,18 +639,16 @@ void Font::rebuildTextures() // Load the glyph bitmap through FT. FT_Load_Char(face, it->first, FT_LOAD_RENDER); - FontTexture* tex {it->second.texture}; + const glm::ivec2 glyphSize {glyphSlot->bitmap.width, glyphSlot->bitmap.rows}; + const glm::ivec2 cursor { + static_cast(it->second.texPos.x * it->second.texture->textureSize.x), + static_cast(it->second.texPos.y * it->second.texture->textureSize.y)}; - // Find the position/size. - glm::ivec2 cursor {static_cast(it->second.texPos.x * tex->textureSize.x), - static_cast(it->second.texPos.y * tex->textureSize.y)}; - glm::ivec2 glyphSize {static_cast(it->second.texSize.x * tex->textureSize.x), - static_cast(it->second.texSize.y * tex->textureSize.y)}; - - // Upload to texture. + // Upload glyph bitmap to texture. if (glyphSize.x > 0 && glyphSize.y > 0) { - mRenderer->updateTexture(tex->textureId, 0, Renderer::TextureType::RED, cursor.x, - cursor.y, glyphSize.x, glyphSize.y, glyphSlot->bitmap.buffer); + mRenderer->updateTexture(it->second.texture->textureId, 0, Renderer::TextureType::RED, + cursor.x, cursor.y, glyphSize.x, glyphSize.y, + glyphSlot->bitmap.buffer); } } } diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index b46d37290..f0802da2a 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// ES-DE +// ES-DE Frontend // Font.h // // Loading, unloading, caching and rendering of fonts.