Search code examples
c++openglopengl-3soildds-format

opengl SOIL library only loads uncompressed dds images


I am working on an OpenGL application and for that purpose I want to texture a rectangle. I have a .dds file and use the SOIL library.

If I load the image into my project

 void setTexture( const std::string& t_filename )
 {
     GLuint m_TEX = SOIL_load_OGL_texture(
         t_filename.c_str(),
         SOIL_LOAD_AUTO,
         SOIL_CREATE_NEW_ID,
         SOIL_FLAG_DDS_LOAD_DIRECT);

     [...]
 }

my application crashes immediately if the image is compressed (DXT3, DXT5). If it is uncompressed, everything works as expected.

What could be the reason for that? SOIL should support compressed .dds files according to the official website.

EDIT 1: Okay I tried to debug my progamm using gdb and valgrind. It looks like an segfault caused by the SOIL_load_OGL_texture() function as soon as you use a compressed .dds file. But I can barely imagine that I am the only one who ever used compressed images.

GDB output:

 Program received signal SIGSEGV, Segmentation fault.
 0x00007f469cd03197 in __strstr_sse2 () from /usr/lib/libc.so.6

 #0  0x00007f469cd03197 in __strstr_sse2 () from /usr/lib/libc.so.6
 #1  0x00007f469d8daa2d in query_DXT_capability () from /usr/lib/libSOIL.so.1
 #2  0x00007f469d8dc19f in SOIL_direct_load_DDS_from_memory () from /usr/lib/libSOIL.so.1
 #3  0x00007f469d8dcaad in SOIL_direct_load_DDS () from /usr/lib/libSOIL.so.1
 #4  0x00007f469d8dcb66 in SOIL_load_OGL_texture () from /usr/lib/libSOIL.so.1

Solution

  • I had the same problem once. Since the error occurs in SOIL_load_OGL_texture() it's most likely caused by glGetString(GL_EXTENSIONS) which SOIL uses internally but which has been deprecated with OpenGL 3.0. You can find a fixed version of SOIL here: https://github.com/njcrawford/Simple-OpenGL-Image-Library/tree/issue-8-attempt2

    However, I would advise against using SOIL since it hasn't been updated in almost a decade now. I'm using stb_image which works well and supports the same formats as SOIL: https://github.com/nothings/stb