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?
image doesnt load.
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
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 !
do you know where it's not working ?
try ouputing the error with SDL_GetError() to see what isn't working.
hope that helps !
yes i debuged it
it jumped the IF part.
it doesnt load that "filename.c_str()" on "loadedimage" and i dont know why
it jumped the IF part.
it doesnt load that "filename.c_str()" on "loadedimage" and i dont know why
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement