Sign in to follow this  
h0ts0up

SDL_Image

Recommended Posts

I'm having trouble loading a '*.png' file to my surface. I was using lazy foo's tutorials and I've also checked other sources and the code seems pretty sound, I don't know why the image isn't loading onto the surface. I even copy pasted from his tutorial, and it still doesn't seem to load. Can someone help me figure out what's wrong? Here is the code snippet: //The headers #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include <string> //The surfaces SDL_Surface *image = NULL; SDL_Surface *screen = NULL; SDL_Surface *load_image( string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image using SDL_image loadedImage = IMG_Load(filename.c_str()); //If the image loaded if( loadedImage != NULL ) { cout<<"Image load successful"<<endl; //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; }

Share this post


Link to post
Share on other sites
Are the bitmaps that you can load located in the same directory as the pngs you cannot load? Have you tried using an absolute path?

If that fails, can you include the exact error message that IMG_GetError() returns. Also, can you tell us what DLLs you have in your executable directory.

Share this post


Link to post
Share on other sites
everything is all in one folder, including the .dlls such as SDL.dll and SDL_image.dll.Everything compiles and it runs, but I have the program set to close if anything goes wrong. I've checked all problems like initialization problems and syntax problems and everything seems to be fine except that the image doesn't load properly.

"Failed loading libpng12-0.dll: The specified module could not be found."
^that's the error message

Share this post


Link to post
Share on other sites
You should have libpng<version>.dll when you downloaded SDL_Image. If not, download it again. SDL_Image supports lots of formats, but it relies on the DLLs for the formats you want to support being present.

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