fix(rendering): stroked message

This commit is contained in:
maelstrom 2025-07-13 17:42:18 +02:00
parent a75119a8c2
commit 0ded4ac7fb
3 changed files with 6 additions and 4 deletions

View file

@ -194,12 +194,12 @@ void drawText(std::shared_ptr<Font> font, std::string text, float x, float y, fl
glBindTexture(GL_TEXTURE_2D, 0);
}
float calcTextWidth(std::shared_ptr<Font> font, std::string text, float scale) {
float calcTextWidth(std::shared_ptr<Font> 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;
}

View file

@ -23,4 +23,4 @@ void fontInit();
void fontFinish();
std::shared_ptr<Font> loadFont(std::string fontName);
void drawText(std::shared_ptr<Font> 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> font, std::string text, float scale = 1.f);
float calcTextWidth(std::shared_ptr<Font> font, std::string text, float scale = 1.f, bool stroke = false);

View file

@ -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);
}
}
}