diff --git a/src/ModelLoader.cpp b/src/ModelLoader.cpp index 5f6a62b..59b7dd5 100644 --- a/src/ModelLoader.cpp +++ b/src/ModelLoader.cpp @@ -263,7 +263,7 @@ unsigned int ModelLoader::textureFromFile(const char* path) unsigned int textureID; glGenTextures(1, &textureID); //gen texture, opengl function - glBindTexture(GL_TEXTURE_2D, textureID); //bind the texture + //glBindTexture(GL_TEXTURE_2D, textureID); //bind the texture int W, H, comp; //width and height unsigned char* image = stbi_load(filename.c_str(), &W, &H, &comp, 4); @@ -271,8 +271,17 @@ unsigned int ModelLoader::textureFromFile(const char* path) if (image) //if the image is fine { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); //fill the texture with image data - glGenerateMipmap(GL_TEXTURE_2D); //generate mipmaps + GLenum format; + if (comp == 1) + format = GL_RED; + else if (comp == 3) + format = GL_RGB; + else if (comp == 4) + format = GL_RGBA; + + glBindTexture(GL_TEXTURE_2D, textureID); + glTexImage2D(GL_TEXTURE_2D, 0, format, W, H, 0, format, GL_UNSIGNED_BYTE, image);//fill the texture with image data + glGenerateMipmap(GL_TEXTURE_2D);//generate mipmaps glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); diff --git a/src/SMesh.cpp b/src/SMesh.cpp index 8560f1b..c75c1b6 100644 --- a/src/SMesh.cpp +++ b/src/SMesh.cpp @@ -30,7 +30,7 @@ void SMesh::setupSMesh() glEnableVertexAttribArray(1); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(smesh::Vertex), (void*)offsetof(smesh::Vertex,texCoords)); - glEnableVertexAttribArray(0); + glEnableVertexAttribArray(2); for (int i = 0; i < BONES_AMOUNT; i++) { @@ -66,7 +66,7 @@ void SMesh::draw(ShaderLoader* ShaderLoader) number = std::to_string(specularNR); specularNR++; } - glUniform1i(glGetUniformLocation(ShaderLoader->ID, ("material." + textures[i].type + number).c_str()), i); + glUniform1f(glGetUniformLocation(ShaderLoader->ID, ("material." + textures[i].type).c_str()), i); glBindTexture(GL_TEXTURE_2D, textures[i].id); } glBindVertexArray(VAO);