From 0ded4ac7fb2c5347ace7dc7edc5eff853b8e742e Mon Sep 17 00:00:00 2001 From: maelstrom Date: Sun, 13 Jul 2025 17:42:18 +0200 Subject: [PATCH] fix(rendering): stroked message --- core/src/rendering/font.cpp | 4 ++-- core/src/rendering/font.h | 2 +- core/src/rendering/renderer.cpp | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/rendering/font.cpp b/core/src/rendering/font.cpp index ef87423..9db06c7 100644 --- a/core/src/rendering/font.cpp +++ b/core/src/rendering/font.cpp @@ -194,12 +194,12 @@ void drawText(std::shared_ptr font, std::string text, float x, float y, fl glBindTexture(GL_TEXTURE_2D, 0); } -float calcTextWidth(std::shared_ptr font, std::string text, float scale) { +float calcTextWidth(std::shared_ptr font, std::string text, float scale, bool stroke) { float x = 0; // iterate through all characters for (size_t i = 0; i < text.size(); i++) { unsigned char c = text[i]; - Character ch = font->characters[c]; + Character ch = stroke ? font->strokeCharacters[c] : font->characters[c]; x += (ch.advance >> 6) * scale; } diff --git a/core/src/rendering/font.h b/core/src/rendering/font.h index e2ca9ca..64c7cad 100644 --- a/core/src/rendering/font.h +++ b/core/src/rendering/font.h @@ -23,4 +23,4 @@ void fontInit(); void fontFinish(); std::shared_ptr loadFont(std::string fontName); void drawText(std::shared_ptr font, std::string text, float x, float y, float scale=1.f, glm::vec3 color = glm::vec3(1,1,1), bool drawStroke = false); -float calcTextWidth(std::shared_ptr font, std::string text, float scale = 1.f); \ No newline at end of file +float calcTextWidth(std::shared_ptr font, std::string text, float scale = 1.f, bool stroke = false); \ No newline at end of file diff --git a/core/src/rendering/renderer.cpp b/core/src/rendering/renderer.cpp index 660e61c..392113e 100644 --- a/core/src/rendering/renderer.cpp +++ b/core/src/rendering/renderer.cpp @@ -673,8 +673,10 @@ void renderMessages() { // Don't draw if text is empty if (message->text == "") continue; + float strokedTextWidth = calcTextWidth(sansSerif, message->text, true); drawRect(0, 0, viewportWidth, viewportHeight, glm::vec4(0.5)); - drawText(sansSerif, message->text, ((float)viewportWidth - textWidth) / 2, ((float)viewportHeight - sansSerif->height) / 2); + drawText(sansSerif, message->text, ((float)viewportWidth - textWidth) / 2, ((float)viewportHeight - sansSerif->height) / 2, 1.f, glm::vec3(0), true); + drawText(sansSerif, message->text, ((float)viewportWidth - strokedTextWidth) / 2, ((float)viewportHeight - sansSerif->height) / 2, 1.f, glm::vec3(1), false); } } }