From 3552537fc492ec23f5240c49c815c6b4e3bc5911 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall <82708541+grorp@users.noreply.github.com> Date: Mon, 17 Jul 2023 20:45:56 +0200 Subject: [PATCH] Fix that transparent text still draws a text shadow (#13649) Makes fade out animations of text more pleasant to look at. --- src/irrlicht_changes/CGUITTFont.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/irrlicht_changes/CGUITTFont.cpp b/src/irrlicht_changes/CGUITTFont.cpp index 842f0f2f7..ac3a20524 100644 --- a/src/irrlicht_changes/CGUITTFont.cpp +++ b/src/irrlicht_changes/CGUITTFont.cpp @@ -678,13 +678,6 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect& positio CGUITTGlyphPage* page = it->second; ++it; - if (shadow_offset) { - for (size_t i = 0; i < page->render_positions.size(); ++i) - page->render_positions[i] += core::vector2di(shadow_offset, shadow_offset); - Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, video::SColor(shadow_alpha,0,0,0), true); - for (size_t i = 0; i < page->render_positions.size(); ++i) - page->render_positions[i] -= core::vector2di(shadow_offset, shadow_offset); - } // render runs of matching color in batch size_t ibegin; video::SColor colprev; @@ -700,6 +693,19 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect& positio if (!use_transparency) colprev.color |= 0xff000000; + + if (shadow_offset) { + for (size_t i = 0; i < tmp_positions.size(); ++i) + tmp_positions[i] += core::vector2di(shadow_offset, shadow_offset); + + u32 new_shadow_alpha = core::clamp(core::round32(shadow_alpha * colprev.getAlpha() / 255.0f), 0, 255); + video::SColor shadow_color = video::SColor(new_shadow_alpha, 0, 0, 0); + Driver->draw2DImageBatch(page->texture, tmp_positions, tmp_source_rects, clip, shadow_color, true); + + for (size_t i = 0; i < tmp_positions.size(); ++i) + tmp_positions[i] -= core::vector2di(shadow_offset, shadow_offset); + } + Driver->draw2DImageBatch(page->texture, tmp_positions, tmp_source_rects, clip, colprev, true); } }