I'm trying to make a context loader in OpenGL and I can't get SOIL to load an image.
Here is the code:
Texture2D TextureLoader::loadSprite(const char* path)
{
int width, height;
GLuint texture = SOIL_load_OGL_texture(path, SOIL_LOAD_RGBA, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
if (texture == 0)
{
Texture2D failedTexture;
return failedTexture;
}
glBindTexture(GL_TEXTURE_2D, texture);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
Texture2D texture2d(texture, width, height);
return texture2d;
}
It always fails at the texture == 0 check. The image file is in the same directory as the executable that is generated when the project is built. I've tried both PNG and JPG and it won't work with either.