diff --git a/LearnOpenGL/ResourceLoader.cpp b/LearnOpenGL/ResourceLoader.cpp index 8a3dc450cb9257891cc769f5337b849bf54dfa98..36c0b4ce0836b051ac393b29d9e47084d5478521 100644 --- a/LearnOpenGL/ResourceLoader.cpp +++ b/LearnOpenGL/ResourceLoader.cpp @@ -106,6 +106,19 @@ bool openObj(const std::string fileName, std::vector<glm::vec3> &vertices, std:: sscanf_s(line.substr(0, charPos).c_str(), "%d%*[-//]%d", &vIndex, &vnIndex); line.erase(0, charPos + 1); } + + if (vIndex >= 1) + { + faceVertexIndicies.push_back(vIndex - 1); + } + if (uvIndex >= 1) + { + faceVertexTexCoordIndicies.push_back(uvIndex - 1); + } + if (vnIndex >= 1) + { + faceVertexNormalIndicies.push_back(vnIndex - 1); + } } if (line.size() > 0) @@ -206,30 +219,31 @@ bool openObj(const std::string fileName, std::vector<glm::vec3> &vertices, std:: log_warn(infoLog, fileName + " : " + "faceVertexNormalIndices.size() : " + std::to_string(faceVertexNormalIndicies.size())); } } - - ifs.close(); - - return true; } - Image *load_Image(std::string fileName, int *width, int *height, int *nrChannels) - { - fileName = "../Images/" + fileName; - stbi_set_flip_vertically_on_load(true); + ifs.close(); - unsigned char *data = stbi_load(fileName.c_str(), width, height, nrChannels, 0); - if (data == NULL) - { - std::cout << "Failed to load texture : " + fileName << std::endl; - } + return true; +} - Image *img = new Image(*width, *height, *nrChannels, data); +Image *load_Image(std::string fileName, int *width, int *height, int *nrChannels) +{ + fileName = "../Images/" + fileName; + stbi_set_flip_vertically_on_load(true); - return img; + unsigned char *data = stbi_load(fileName.c_str(), width, height, nrChannels, 0); + if (data == NULL) + { + std::cout << "Failed to load texture : " + fileName << std::endl; } - void free_image(Image *img) - { - stbi_image_free(img->getData()); - free(img); - } \ No newline at end of file + Image *img = new Image(*width, *height, *nrChannels, data); + + return img; +} + +void free_image(Image *img) +{ + stbi_image_free(img->getData()); + free(img); +} \ No newline at end of file