aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-03-30 21:50:39 +0200
committerGitHub <noreply@github.com>2021-03-30 21:50:39 +0200
commit0d90ed6d921baefbb1a969df69f7b86e702e962f (patch)
treedafff1cbc6e9e262a4e1622ccf2aa2ea088e1852
parent88d1fcfe237470b6eaed079f95a048e5f39b1861 (diff)
downloadminetest-0d90ed6d921baefbb1a969df69f7b86e702e962f.tar.gz
minetest-0d90ed6d921baefbb1a969df69f7b86e702e962f.tar.bz2
minetest-0d90ed6d921baefbb1a969df69f7b86e702e962f.zip
Draw items as 2D images (instead of meshes) when possible
-rw-r--r--src/client/hud.cpp42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index 74c1828e3..e5c7a4cfd 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -945,10 +945,16 @@ void drawItemStack(
return;
}
+ const static thread_local bool enable_animations =
+ g_settings->getBool("inventory_items_animations");
+
const ItemDefinition &def = item.getDefinition(client->idef());
- ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client);
- if (imesh && imesh->mesh) {
+ // Render as mesh if animated or no inventory image
+ if ((enable_animations && rotation_kind < IT_ROT_NONE) || def.inventory_image.empty()) {
+ ItemMesh *imesh = client->idef()->getWieldMesh(def.name, client);
+ if (!imesh || !imesh->mesh)
+ return;
scene::IMesh *mesh = imesh->mesh;
driver->clearBuffers(video::ECBF_DEPTH);
s32 delta = 0;
@@ -992,9 +998,6 @@ void drawItemStack(
core::matrix4 matrix;
matrix.makeIdentity();
- static thread_local bool enable_animations =
- g_settings->getBool("inventory_items_animations");
-
if (enable_animations) {
float timer_f = (float) delta / 5000.f;
matrix.setRotationDegrees(v3f(
@@ -1039,16 +1042,27 @@ void drawItemStack(
driver->setTransform(video::ETS_VIEW, oldViewMat);
driver->setTransform(video::ETS_PROJECTION, oldProjMat);
driver->setViewPort(oldViewPort);
+ } else { // Otherwise just draw as 2D
+ video::ITexture *texture = client->idef()->getInventoryTexture(def.name, client);
+ if (!texture)
+ return;
+ video::SColor color =
+ client->idef()->getItemstackColor(item, client);
+ const video::SColor colors[] = { color, color, color, color };
- // draw the inventory_overlay
- if (def.type == ITEM_NODE && def.inventory_image.empty() &&
- !def.inventory_overlay.empty()) {
- ITextureSource *tsrc = client->getTextureSource();
- video::ITexture *overlay_texture = tsrc->getTexture(def.inventory_overlay);
- core::dimension2d<u32> dimens = overlay_texture->getOriginalSize();
- core::rect<s32> srcrect(0, 0, dimens.Width, dimens.Height);
- draw2DImageFilterScaled(driver, overlay_texture, rect, srcrect, clip, 0, true);
- }
+ draw2DImageFilterScaled(driver, texture, rect,
+ core::rect<s32>({0, 0}, core::dimension2di(texture->getOriginalSize())),
+ clip, colors, true);
+ }
+
+ // draw the inventory_overlay
+ if (def.type == ITEM_NODE && def.inventory_image.empty() &&
+ !def.inventory_overlay.empty()) {
+ ITextureSource *tsrc = client->getTextureSource();
+ video::ITexture *overlay_texture = tsrc->getTexture(def.inventory_overlay);
+ core::dimension2d<u32> dimens = overlay_texture->getOriginalSize();
+ core::rect<s32> srcrect(0, 0, dimens.Width, dimens.Height);
+ draw2DImageFilterScaled(driver, overlay_texture, rect, srcrect, clip, 0, true);
}
if (def.type == ITEM_TOOL && item.wear != 0) {