FIX: Handle required texture flipping sometimes
This commit is contained in:
parent
1908b5e4b7
commit
a582ddc519
@ -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;
|
||||
}
|
||||
|
||||
@ -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<float> &data);
|
||||
void bindIndicesBuffer(const std::vector<int> &indices);
|
||||
void unbindVAO();
|
||||
|
||||
@ -72,13 +72,13 @@ std::shared_ptr<TexturedModel> 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<ModelTexture>(loader.loadTextureFromFile(fullTexPath.string()));
|
||||
texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(fullTexPath.string(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!texture) {
|
||||
texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(texturePath));
|
||||
texture = std::make_shared<ModelTexture>(loader.loadTextureFromFile(texturePath, false));
|
||||
}
|
||||
|
||||
subModels.emplace_back(
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user