Skip to content

Commit

Permalink
Fixed miss texture
Browse files Browse the repository at this point in the history
  • Loading branch information
CracklyBody committed Jul 25, 2020
1 parent f8de513 commit c88aabc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,25 @@ 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);
//SOIL_load_image(filename.c_str(), &W, &H, 0, SOIL_LOAD_RGBA); //using SOIL to load the RGBA image

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);
Expand Down
4 changes: 2 additions & 2 deletions src/SMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c88aabc

Please sign in to comment.