From a582ddc51952632dc70217e09b853008eee1d199 Mon Sep 17 00:00:00 2001 From: sebastian Date: Sun, 15 Feb 2026 19:54:34 +0100 Subject: [PATCH] FIX: Handle required texture flipping sometimes --- src/engine/renderer/loader/Loader.cpp | 8 ++++---- src/engine/renderer/loader/Loader.h | 4 ++-- src/engine/renderer/loader/OBJLoader.cpp | 4 ++-- src/engine/renderer/loader/TextureLoader.cpp | 4 ++-- src/engine/renderer/loader/TextureLoader.h | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/engine/renderer/loader/Loader.cpp b/src/engine/renderer/loader/Loader.cpp index c22dc41..f7d5a1e 100644 --- a/src/engine/renderer/loader/Loader.cpp +++ b/src/engine/renderer/loader/Loader.cpp @@ -55,8 +55,8 @@ void Loader::cleanUp() { } } -ModelTexture Loader::loadTextureFromFile(const std::string &path) { - return ModelTexture(loadTexture(path)); +ModelTexture Loader::loadTextureFromFile(const std::string &path, bool flipVertically) { + return ModelTexture(loadTexture(path, flipVertically)); } TextQuadModel Loader::loadTextModel() { @@ -77,8 +77,8 @@ TextQuadModel Loader::loadTextModel() { return {vaoID, vboID, 4}; } -GLuint Loader::loadTexture(const std::string &path) { - Texture2D texture = TextureLoader::loadTexture(path); +GLuint Loader::loadTexture(const std::string &path, bool flipVertically) { + Texture2D texture = TextureLoader::loadTexture(path, flipVertically); textureIDs.push_back(texture.id); return texture.id; } diff --git a/src/engine/renderer/loader/Loader.h b/src/engine/renderer/loader/Loader.h index 9d59c2c..063bc40 100644 --- a/src/engine/renderer/loader/Loader.h +++ b/src/engine/renderer/loader/Loader.h @@ -27,11 +27,11 @@ public: ~Loader(); void cleanUp(); - ModelTexture loadTextureFromFile(const std::string& path); + ModelTexture loadTextureFromFile(const std::string& path, bool flipVertically = true); TextQuadModel loadTextModel(); private: GLuint createVAO(); - GLuint loadTexture(const std::string &path); + GLuint loadTexture(const std::string &path, bool flipVertically); void storeDataInAttributeList(int attributeNumber, int coordinateSize, const std::vector &data); void bindIndicesBuffer(const std::vector &indices); void unbindVAO(); diff --git a/src/engine/renderer/loader/OBJLoader.cpp b/src/engine/renderer/loader/OBJLoader.cpp index 6564b22..87e12a6 100644 --- a/src/engine/renderer/loader/OBJLoader.cpp +++ b/src/engine/renderer/loader/OBJLoader.cpp @@ -72,13 +72,13 @@ std::shared_ptr OBJLoader::loadModel(const std::string &modelPath if (!mat.diffuse_texname.empty()) { std::string texFile = mat.diffuse_texname; std::filesystem::path fullTexPath = std::filesystem::path(baseDir) / std::filesystem::path(texFile); - texture = std::make_shared(loader.loadTextureFromFile(fullTexPath.string())); + texture = std::make_shared(loader.loadTextureFromFile(fullTexPath.string(), false)); } } } if (!texture) { - texture = std::make_shared(loader.loadTextureFromFile(texturePath)); + texture = std::make_shared(loader.loadTextureFromFile(texturePath, false)); } subModels.emplace_back( diff --git a/src/engine/renderer/loader/TextureLoader.cpp b/src/engine/renderer/loader/TextureLoader.cpp index 09bb3e9..00d3045 100644 --- a/src/engine/renderer/loader/TextureLoader.cpp +++ b/src/engine/renderer/loader/TextureLoader.cpp @@ -9,10 +9,10 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" -Texture2D TextureLoader::loadTexture(const std::string &path) { +Texture2D TextureLoader::loadTexture(const std::string &path, bool flipVertically) { Texture2D texture; - stbi_set_flip_vertically_on_load(true); + stbi_set_flip_vertically_on_load(flipVertically); texture.pixels = stbi_load( path.c_str(), diff --git a/src/engine/renderer/loader/TextureLoader.h b/src/engine/renderer/loader/TextureLoader.h index a58227a..5f259c5 100644 --- a/src/engine/renderer/loader/TextureLoader.h +++ b/src/engine/renderer/loader/TextureLoader.h @@ -12,7 +12,7 @@ class TextureLoader { public: - static Texture2D loadTexture(const std::string& path); + static Texture2D loadTexture(const std::string& path, bool flipVertically= true); static void free(Texture2D& texture); };