Search code examples
c++macosopenglpngjpeg

How to load JPG/PNG Textures in an SDL/OpenGL App under OSX


i am writing an SDL / OpenGL application that runs under OSX. I have to use existing code which uses the DevIL library for loading JPG and PNG textures. Unfortunately, this works very bad under OS X, so i decided not to use DevIL at all, and rewrite the respective parts of the application using another library. I want to keep it flexible (DevIL can handle a lot of image formats) and easy to use. Is there a good replacement for DevIL that you can recommend? The application is entirely written in C++.


Solution

  • Have a look at the SDL_image library. It offers functions like IMG_LoadPNG that load your picture "as an" SDL_Surface. Since you already work with SDL this should fit quite well in your program.

    Sample taken from the SDL_image documentation:

    // Load sample.png into image
    SDL_Surface* image = IMG_Load("sample.png");
    if (image == nullptr) {
        std::cout << "IMG_Load: " << IMG_GetError() << "\n";
    }