Saturday, September 26, 2015

OpenGL - SOIL_load_image() returns null ; image/texture not being loaded

If you have been working with SOIL library for loading OpenGL textures, and have troubles with SOIL_load_image() function, this might help.

SOIL_load_image() should return 1 if image (texture for example) was loaded correctly, and 0 if there was as an error in image loading.

If you get 0 as return value, you can check the actual error being generated by examing the result of SOIL_last_result().

Just place this code below the line where you use SOIL_load_image():


const char* errX = SOIL_last_result();

Stop the debugger at this line and check the contents of errX.

If you see it having "Unable to open file", please note that SOIL by default reads the image paths relative to current working directory.

And that is not always the same directory as the one where your .EXE resides.

In case of Visual Studio, you can change the working directory when debugging by going to :

Project Properties ->Debugging->Working Directory



Please note that this change might affect other parts of your code as well!



No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...