Then maybe it would help to post the code where you are loading the file (what format?) and you draw call to open gl.
Here is the way I am loading the texture (using FreeImage and JPEG files):
FIBITMAP *loadedImage = NULL;
FREE_IMAGE_FORMAT CurrentFormat = FIF_UNKNOWN;
CurrentFormat = FreeImage_GetFileType(MaterialFile.c_str(), 0);
if (CurrentFormat == FIF_UNKNOWN) {
FREE_IMAGE_FORMAT CurrentFormat = FreeImage_GetFIFFromFilename(MaterialFile.c_str());
}
if (CurrentFormat == FIF_UNKNOWN) {
return false;
}
if (FreeImage_FIFSupportsReading(CurrentFormat)) {
loadedImage = FreeImage_Load(CurrentFormat, MaterialFile.c_str());
}
if (!loadedImage) {
return false;
}
BYTE* bytesDataPointer = FreeImage_GetBits(loadedImage);
WidthOfTexture = FreeImage_GetWidth(loadedImage);
HeightOfTexture = FreeImage_GetHeight(loadedImage);
BytesPerPixel = FreeImage_GetBPP(loadedImage);
if (WidthOfTexture == 0 || HeightOfTexture == 0 || BytesPerPixel == 0) {
return false;
}
glGenTextures(1, &TextureObject_ID); // section being edited by CKoeber to pull in material files
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, TextureObject_ID);
GLsizei iFormat = BytesPerPixel == 24 ? GL_BGR : BytesPerPixel == 8 ? GL_LUMINANCE : 0;
GLsizei iInternalFormat = BytesPerPixel == 24 ? GL_RGB : GL_DEPTH_COMPONENT;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
WidthOfTexture, HeightOfTexture, 0, iFormat,
GL_UNSIGNED_BYTE, bytesDataPointer);
glGenerateMipmap(GL_TEXTURE_2D);
FreeImage_Unload(loadedImage);
glGenSamplers(1, &TextureSamplerObject_ID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
setFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP);
HasMipsBeenGenerated = true;
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, NULL);
And here is the way I am drawing the OpenGL quad with materials:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(g_StandardShaderProgram_ID);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glUniform1i(GetEnableWireframeID(), 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (GLuint i = 0; i < CurrentMeshCache.size(); i++) {
/*
Inside my object that has my mesh/quad/material data...
/*
glBindVertexArray(Pointer_VAO);
for (int i = 0; i < ModelMatrixInstances.size(); i++) {
glm::mat4 ModelViewMatrix = CurrentOpenGLController->GetViewMatrix() * ModelMatrixInstances[i];
glm::mat3 NormalMatrix = glm::transpose(glm::inverse(glm::mat3(ModelViewMatrix)));
glm::mat4 ModelViewProjectionMatrix = CurrentOpenGLController->GetProjectionViewMatrix() * ModelMatrixInstances[i];
glBindBuffer(GL_ARRAY_BUFFER, MVP_VBO);
glBufferSubData(GL_ARRAY_BUFFER, (i * (sizeof(glm::mat4))), sizeof(glm::mat4), glm::value_ptr(ModelViewProjectionMatrix));
glBindBuffer(GL_ARRAY_BUFFER, NormalMatrix_VBO);
glBufferSubData(GL_ARRAY_BUFFER, (i * (sizeof(glm::mat3))), sizeof(glm::mat3), glm::value_ptr(NormalMatrix));
}
glUniform4fv(CurrentOpenGLController->GetMaterialColorID(), 1, Materials[0].ObjectColor);
glUniform4fv(CurrentOpenGLController->GetAmbientMeshColorID(), 1, Materials[0].AmbientColor);
glUniform4fv(CurrentOpenGLController->GetEmmissiveMeshColorID(), 1, Materials[0].EmissiveColor);
glUniform4fv(CurrentOpenGLController->GetSpecularMeshColorID(), 1, Materials[0].SpecularColor);
glUniform4fv(CurrentOpenGLController->GetDiffuseMeshColorID(), 1, Materials[0].DiffuseColor);
glUniform1fv(CurrentOpenGLController->GetMeshShininessID(), 1, &Materials[0].Shininess);
if (Materials[0].HasMaterialFile == true) {
GLfloat ObjectHasMaterial = 1.0f;
glUniform1fv(CurrentOpenGLController->GetObjectHasMaterialFileID(), 1, &ObjectHasMaterial);
glUniform1i(CurrentOpenGLController->GetMainTextureID(), 1);
Materials[0].bindTexture(1);
}
else {
GLfloat ObjectDoesNotHaveMaterial = 0.0f;
glUniform1fv(CurrentOpenGLController->GetObjectHasMaterialFileID(), 1, &ObjectDoesNotHaveMaterial);
glBindTexture(GL_TEXTURE_2D, NULL);
}
glDrawElementsInstanced(GL_TRIANGLES, TotalVertexCount,
GL_UNSIGNED_INT, NULL, NumberOfChildItems + 1);
if (Materials[0].HasMaterialFile == true) {
glActiveTexture(GL_TEXTURE0 + NULL);
glBindTexture(GL_TEXTURE_2D, NULL);
}
/*
Now out of my object...
*/
}
glBindVertexArray(0);