FIX: Handle required texture flipping sometimes

This commit is contained in:
sebastian 2026-02-15 19:54:34 +01:00
parent 1908b5e4b7
commit a582ddc519
5 changed files with 11 additions and 11 deletions

View File

@ -55,8 +55,8 @@ void Loader::cleanUp() {
} }
} }
ModelTexture Loader::loadTextureFromFile(const std::string &path) { ModelTexture Loader::loadTextureFromFile(const std::string &path, bool flipVertically) {
return ModelTexture(loadTexture(path)); return ModelTexture(loadTexture(path, flipVertically));
} }
TextQuadModel Loader::loadTextModel() { TextQuadModel Loader::loadTextModel() {
@ -77,8 +77,8 @@ TextQuadModel Loader::loadTextModel() {
return {vaoID, vboID, 4}; return {vaoID, vboID, 4};
} }
GLuint Loader::loadTexture(const std::string &path) { GLuint Loader::loadTexture(const std::string &path, bool flipVertically) {
Texture2D texture = TextureLoader::loadTexture(path); Texture2D texture = TextureLoader::loadTexture(path, flipVertically);
textureIDs.push_back(texture.id); textureIDs.push_back(texture.id);
return texture.id; return texture.id;
} }

View File

@ -27,11 +27,11 @@ public:
~Loader(); ~Loader();
void cleanUp(); void cleanUp();
ModelTexture loadTextureFromFile(const std::string& path); ModelTexture loadTextureFromFile(const std::string& path, bool flipVertically = true);
TextQuadModel loadTextModel(); TextQuadModel loadTextModel();
private: private:
GLuint createVAO(); 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<float> &data); void storeDataInAttributeList(int attributeNumber, int coordinateSize, const std::vector<float> &data);
void bindIndicesBuffer(const std::vector<int> &indices); void bindIndicesBuffer(const std::vector<int> &indices);
void unbindVAO(); void unbindVAO();

View File

@ -72,13 +72,13 @@ std::shared_ptr<TexturedModel> OBJLoader::loadModel(const std::string &modelPath
if (!mat.diffuse_texname.empty()) { if (!mat.diffuse_texname.empty()) {
std::string texFile = mat.diffuse_texname; std::string texFile = mat.diffuse_texname;
std::filesystem::path fullTexPath = std::filesystem::path(baseDir) / std::filesystem::path(texFile); std::filesystem::path fullTexPath = std::filesystem::path(baseDir) / std::filesystem::path(texFile);
texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(fullTexPath.string())); texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(fullTexPath.string(), false));
} }
} }
} }
if (!texture) { if (!texture) {
texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(texturePath)); texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(texturePath, false));
} }
subModels.emplace_back( subModels.emplace_back(

View File

@ -9,10 +9,10 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.h"
Texture2D TextureLoader::loadTexture(const std::string &path) { Texture2D TextureLoader::loadTexture(const std::string &path, bool flipVertically) {
Texture2D texture; Texture2D texture;
stbi_set_flip_vertically_on_load(true); stbi_set_flip_vertically_on_load(flipVertically);
texture.pixels = stbi_load( texture.pixels = stbi_load(
path.c_str(), path.c_str(),

View File

@ -12,7 +12,7 @@
class TextureLoader { class TextureLoader {
public: public:
static Texture2D loadTexture(const std::string& path); static Texture2D loadTexture(const std::string& path, bool flipVertically= true);
static void free(Texture2D& texture); static void free(Texture2D& texture);
}; };