0

I am following a tutorial and I think I have done everything right, but it continues saying "Unsupported image format".

The code:

SDL_Texture *LoadTexture(string filePath, SDL_Renderer *renderTarget)
{
    SDL_Texture *texture = nullptr;
    SDL_Surface *surface = IMG_Load(filePath.c_str());

    if (surface == NULL)
    {
        cout << "Error: " << IMG_GetError() << endl;
    }
    else
    {
        texture = SDL_CreateTextureFromSurface(renderTarget, surface);

        if (texture == NULL)
        {
            cout << "Error: " << SDL_GetError() << endl;
        }
    }

    SDL_FreeSurface(surface);

    return texture;
}

The surface stays NULL after it accepts the result of IMG_Load();

Also, my includes:

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL/SDL_image.h>

And, my initialization:

SDL_Init(SDL_INIT_VIDEO);

int image_flags = IMG_INIT_PNG;

if (IMG_Init(image_flags) != image_flags)
{
    cout << "Error: " << IMG_GetError() << endl;
}

Also, in case it matters, I am doing this in Ubuntu and I recently switched from Windows, so I may not be doing something with the libraries correctly.

Edit: If you would ask, I am trying to work with a PNG, so I am not using a format that I haven't initialized

1 Answer 1

2

Change this :

#include <SDL/SDL_image.h> 

to

#include <SDL2/SDL_image.h>

You are currently using SDL_image (from SDL1) header with SDL2, I think your problem is there. Maybe you will need to install SDL2_image-dev, if it not installed.

1
  • OMG. Stupid mistake. Thank you very much! Commented Feb 5, 2015 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.