DEV Community

Discussion on: Using SDL2: Optimizing Surface Blitting

Collapse
 
akariiinnn profile image
Akariiinnn

I have an issue as my Window does not show anymore when i use a PNG image, it works when switching back to BMP tho...

Here's the function :

SDL_Surface *load_pngjpg(char const *path)
{
    int flags = IMG_INIT_PNG | IMG_INIT_JPG;
    int initiated_flags = IMG_Init(flags);

    if((initiated_flags & flags) != flags)
    {
        std::cout << "Failed to initialize all image loaders\n";
        std::cout << "IMG Error: " << IMG_GetError() << "\n";
    }

    SDL_Surface *image_surface = IMG_Load(path);

    if(!image_surface)
    {
        std::cout << "Failed to open image\n";
        std::cout << "IMG Error: " << IMG_GetError() << "\n";
    }

    SDL_FreeSurface(image_surface);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
akariiinnn profile image
Akariiinnn

I did include SDL_Image.h and added the dlls and libs to my project and to my CMakeLists.txt

Collapse
 
akariiinnn profile image
Akariiinnn • Edited

Replacing SDL_FreeSurface(image_surface) to return image_surface worked.

If that can help someone.