From 163fdd2e37945798d03ead3e8437cdb1fef54e28 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 12 Nov 2023 05:52:04 +0300 Subject: [PATCH] Inventory blocks render fix --- src/assets/AssetsLoader.cpp | 1 + src/frontend/hud.cpp | 4 ++-- src/graphics/Batch2D.cpp | 5 +++-- src/graphics/BlocksRenderer.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp index e360ab6a..eb40b6b8 100644 --- a/src/assets/AssetsLoader.cpp +++ b/src/assets/AssetsLoader.cpp @@ -106,6 +106,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader) { loader.add(ASSET_SHADER, "res/ui", "ui"); loader.add(ASSET_ATLAS, "res/block.png", "block"); + loader.add(ASSET_TEXTURE, "res/block.png", "block_tex"); loader.add(ASSET_TEXTURE, "res/slot.png", "slot"); loader.add(ASSET_FONT, "res/font", "normal"); diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 0d7708a0..515902c2 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -138,7 +138,7 @@ void HudRenderer::drawDebug(int fps, bool occlusion){ } void HudRenderer::drawInventory(Player* player) { - Texture* blocks = assets->getTexture("block"); + Texture* blocks = assets->getTexture("block_tex"); uint size = 48; uint step = 64; uint inv_cols = 10; @@ -229,7 +229,7 @@ void HudRenderer::draw(){ uishader->uniformMatrix("u_projview", uicamera->getProjection()*uicamera->getView()); // Chosen block preview - Texture* blocks = assets->getTexture("block"); + Texture* blocks = assets->getTexture("block_tex"); batch->texture(nullptr); batch->color = vec4(1.0f); diff --git a/src/graphics/Batch2D.cpp b/src/graphics/Batch2D.cpp index 4fbea3a9..e74a72a4 100644 --- a/src/graphics/Batch2D.cpp +++ b/src/graphics/Batch2D.cpp @@ -301,8 +301,9 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale; float uf = (index[0] % atlasRes) * scale; float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale; - // if (this->index + 18*VERTEX_SIZE >= capacity) - // render(); + + if (this->index + 18*VERTEX_SIZE >= capacity) + render(); float ar = 0.88f; float ox = x + (w * 0.5f); diff --git a/src/graphics/BlocksRenderer.cpp b/src/graphics/BlocksRenderer.cpp index 90944373..eedcf862 100644 --- a/src/graphics/BlocksRenderer.cpp +++ b/src/graphics/BlocksRenderer.cpp @@ -292,7 +292,7 @@ vec4 BlocksRenderer::pickSoftLight(int x, int y, int z, ivec3 right, ivec3 up) c // Get texture atlas UV region for block face inline UVRegion uvfor(const Block& def, uint face, int atlas_size) { float uvsize = 1.0f / (float)atlas_size; - float us = 0.0097; + float us = 0.0097; // TODO: replace with correct calculations (including 0.36) const uint id = def.textureFaces[face]; float u = (id % atlas_size) * uvsize; float v = 1.0f - (id / atlas_size + 1) * uvsize;