ANSWER
After using SOIL_last_result()
, as dcook
had suggested, I found out two things:
1) It couldn't find the image, as PaulMcKenzie
said, so my working directory was indeed incorrect as genpfault
mentioned.
2) After I set a full path, it mentioned that my jpeg format(progressive), was not supported. I set the image to the standard jpeg format and it worked.
Thanks for the help!
ORIGINAL QUESTION
I am currently trying to load an image using SOIL to use with OpenGL. However, it seems to fail to properly load the image as the variable it is assigned to ends up being null. I've tried looking at this but it seems the guy just put the wrong layout position when he set the attribute. I have it check for errors(glGetError()
) after every line but I omitted that here for readability.
The OpenGL error occurs after glTexImage2D()
with a GL_INVALID_VALUE
. This is more than likely because imgWidth
/imgHeight
are bigger than GL_MAX_TEXTURE_SIZE
due to the null image.
Output:
null: 1
Max size: 3379
Width: 4298563
Height: 2686488
Obj: 1
GL_INVALID_VALUE - ../src/polygon.cpp:222
Code:
// Generate the texture object and binds it.
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
// Texture image data
int imgWidth, imgHeight;
// Load the texture image.
unsigned char* image = SOIL_load_image("potato.jpg",
&imgWidth,
&imgHeight,
0,
SOIL_LOAD_RGB);
std::cout << "null: " << !image << std::endl;
std::cout << "Max size: " << GL_MAX_TEXTURE_SIZE << std::endl;
std::cout << "Width: " << imgWidth << std::endl;
std::cout << "Height: " << imgHeight << std::endl;
std::cout << "Obj: " << m_texture << std::endl;
// Generate the texture to the currently bound texture object.
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGB,
imgWidth,
imgHeight,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
image);
// Generate the mipmap to the currently bound texture object.
glGenerateMipmap(GL_TEXTURE_2D);
// Unbind and free image data.
SOIL_free_image_data(image);
glBindTexture(GL_TEXTURE_2D, 0);
Let me know if any more data is needed. Thanks!
EDIT 1: Yes, the image is in the correct location:
Also, I tried using a full path, it did not help.
Since it seems to be an issue with SOIL rather than GL, check the last SOIL error with SOIL_last_result
after calling SOIL_load_image
. This should give you a better clue as to what's actually going wrong.