Fix that transparent text still draws a text shadow (#13649)

Makes fade out animations of text more pleasant to look at.
This commit is contained in:
Gregor Parzefall 2023-07-17 20:45:56 +02:00 committed by GitHub
parent f41e9e3e0f
commit 3552537fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -678,13 +678,6 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
CGUITTGlyphPage* page = it->second; CGUITTGlyphPage* page = it->second;
++it; ++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 // render runs of matching color in batch
size_t ibegin; size_t ibegin;
video::SColor colprev; video::SColor colprev;
@ -700,6 +693,19 @@ void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& positio
if (!use_transparency) if (!use_transparency)
colprev.color |= 0xff000000; 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); Driver->draw2DImageBatch(page->texture, tmp_positions, tmp_source_rects, clip, colprev, true);
} }
} }