SDL_image

damn this .h it gives me a lot of probs lately.

load_image func
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SDL_Surface *load_image( string filename ){
    SDL_Surface* loadedImage = NULL;

    SDL_Surface* optimizedImage = NULL;

    loadedImage = IMG_Load( filename.c_str() );

    if( loadedImage!=NULL ){
        optimizedImage = SDL_DisplayFormat( loadedImage );

        SDL_FreeSurface( loadedImage );
    }

    return optimizedImage;
}


i have a load_files func shown below
1
2
3
4
5
6
7
8
9
bool load_files(){
    image = load_image( "x.png" );

    if( image == NULL ){
        return false;
    }

    return true;
}


and here is the check at main func
1
2
3
if( load_files() == false ){
        return 2;
    }


and error output
1
2
3
Checking for existence: C:\Users\Ceset\Desktop\Game\3\bin\Debug\3.exe
Executing: "C:\Users\Ceset\Desktop\Game\3\bin\Debug\3.exe"  (in C:\Users\Ceset\Desktop\Game\3\.)
Process terminated with status 2 (0 minutes, 0 seconds)


the prob is when i try it with x.bmp it works fine so no prob with the func. compiler doesnt giving any error about not finding SDL_image or such. So what the prob is. IMG_Load func is used for loading other types of images it shouldnt be. Does SDL_image sucks that giving all the troubles to me last few days(of course not). help me pls.
thx in advance
closed account (Dy7SLyTq)
sdl_image works fine with me. your code must not be right
closed account (S6k9GNh0)
Or there just isn't an x.png.
yes it seems as though your code cant find "x.png" just a wild guess, try x.png.png because sometimes windows does shit! make sure the picture is in the same folder as the project, and ofcoarse make sure the picture is a png picture.

if all else failes, try giving full path. something like
" C:\Users\ppcompany\Desktop\folder\x.png"

and sometimes you need a backslash to escape a backslash. which means you need two backslashes \\ or // in linux i believe. whetever its a bunch of fundge that has nothing to do with being a good programer.
well there is a x.png and i checked it sure is .png file

and i tried it as load_image( "C:\\Users\\Ceset\\Desktop\\Game\\3\\x.png" ); which is still fine with .bmp but doesnt works with .png

is IMG_Load func not for loading .png, .jpg and such files

EDIT : might that be a bug about SDL_image??
Last edited on
well i recopy the .dll files to the folder where .exe exist. and it worked is this something about my hardware or i did something wrong when copying dont know maybe i need some fresh air.
I'm guessing you don't have libpng.dll and/or zlib.dll.

Same mistake I had.
closed account (Dy7SLyTq)
just an fyi... the zlib from the ttf library and the sdl_image library are exactly the same
Topic archived. No new replies allowed.