Home > Blockchain >  SOIL_load_OGL_texture returning NULL, possibly a working directory issue (XCode 6)
SOIL_load_OGL_texture returning NULL, possibly a working directory issue (XCode 6)

Time:12-09

Ok, so I'm trying to use SOIL to load a .png file that's in a "textures" folder. The textures folder is located in the same directory as the code. I've gone into the scheme settings on the XCode project and changed the working directory to the one where the folder is located. However, when I do this simple test, it always indicates that the GLUint texture is NULL.

GLuint texture = SOIL_load_OGL_texture
(
 "textures/image.png",
 SOIL_LOAD_AUTO,
 SOIL_CREATE_NEW_ID,
 SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
 );

if (texture == 0){
    std::cout << "Texture not found!\n";
    return 0;
}

I'm not sure if I'm doing something wrong in regards to SOIL but my hunch is that the file is simply not being read. As I said, I changed the working directory in XCode but that doesn't change anything.

CodePudding user response:

OK, figured it out. Problem was that the PNG file was 16-bit instead of 8-bit. Also, the SOIL_load_OGL_texture function needed to be called after glfwCreateWindow() and glfwMakeContextCurrent().

Here's the answer that helped me: SOIL: 'Unable to open file' in C and OpenGL with Xcode

  • Related