1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-26 18:21:04 +00:00
This commit is contained in:
sfan5 2025-06-17 17:31:48 +02:00
parent b139d0baf5
commit 98296fd8b4

View file

@ -655,13 +655,25 @@ void Camera::drawNametags()
} }
if (font_size <= 1) if (font_size <= 1)
continue; continue;
// TODO: This is quite primitive. It would be better to draw the font once // TODO: This is quite primitive. It would be better to let the GPU handle
// at its maximum size to an RTT and let normal scaling happen. // scaling (draw to RTT first?).
{
// Because the current approach puts a high load on the font engine
// we quantize the font size and set and arbitrary maximum...
font_size = MYMIN(font_size, 256);
if (font_size > 128)
font_size &= ~(1|2|4);
else if (font_size > 64)
font_size &= ~(1|2);
else if (font_size > 32)
font_size &= ~1;
}
auto *font = g_fontengine->getFont(font_size); auto *font = g_fontengine->getFont(font_size);
assert(font); assert(font);
std::wstring real_text = translate_string(utf8_to_wide(nametag->text)); const auto wtext = utf8_to_wide(nametag->text);
core::dimension2d<u32> textsize = font->getDimension(real_text.c_str()); // Measure dimensions with escapes removed
core::dimension2du textsize = font->getDimension(unescape_translate(wtext).c_str());
v2s32 screen_pos; v2s32 screen_pos;
screen_pos.X = screensize.X * screen_pos.X = screensize.X *
(0.5f + transformed_pos[0] * zDiv * 0.5f) - textsize.Width / 2; (0.5f + transformed_pos[0] * zDiv * 0.5f) - textsize.Width / 2;
@ -675,7 +687,8 @@ void Camera::drawNametags()
driver->draw2DRectangle(bgcolor, bg_size + screen_pos); driver->draw2DRectangle(bgcolor, bg_size + screen_pos);
} }
font->draw(real_text.c_str(), // but draw text with escapes
font->draw(translate_string(wtext).c_str(),
size + screen_pos, nametag->textcolor); size + screen_pos, nametag->textcolor);
} }
} }