Sign in to follow this  

image doesnt load.

Recommended Posts

hello guys. i am been following lazy foo's tutorials at SDL on C++ there is a problem, lesson number 7 and 8 doesnt load the image, i did the debug, and the image doesnt load at

SDL_Surface *load_image( std::string filename ) 
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;
    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;
    //Load the image
    loadedImage = IMG_Load( filename.c_str() );
    //If the image loaded
    if( loadedImage != NULL )
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );
        //Free the old surface
        SDL_FreeSurface( loadedImage );
        //If the surface was optimized
        if( optimizedImage != NULL )
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
    //Return the optimized surface
    return optimizedImage;

i have everything right on link, dll's and stuff, but i dont know why it doesnt load :S is there something that i am not watching?

Share this post

Link to post
Share on other sites
did you debug it ?

do you know where it's not working ?

try ouputing the error with SDL_GetError() to see what isn't working.

hope that helps !

Share this post

Link to post
Share on other sites
If IMG_Load returns NULL, use IMG_GetError to get a human readable string describing the problem. The usual suspects are:

1) File doesn't exist or has a different name (check on filesystem)
2) File exists, but path is incorrect (try using an absolute path)
3) File has wrong format (E.G. without libpng.dll PNG files will not load)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this