Sign in to follow this  
matrisking

[Resolved] IMG_Load won't load a PNG

Recommended Posts

matrisking    282
Hi, I worked through a number of lazy_foo's SDL tutorials and have wrote some code based on them. However, I'm having difficulty with the IMG_Load function that's part of SDL_image. It displays .bmp files without any issues, but when I try to load a .png file, nothing happens. In the following two lines: loadedImage = IMG_Load( tempFileName.c_str() ); if ( loadedImage != NULL ) loadedImage is NULL after the assignment whenever I use a png file. I thought the whole point of IMG_Load was that it could handle multiple image file types. Am I missing something? Is there more code I could paste to shed more light on the issue? Thanks! [Edited by - matrisking on April 27, 2010 9:02:30 AM]

Share this post


Link to post
Share on other sites
ShinkaFudan    100
Did you try following the code through to where it checks if different image types are enabled? I had this problem before... and the documentation doesn't talk much about it, so I'm guessing you are having the same problem I ran into a long time ago.

Open up SDL_image.h. At the top is the following code:


#ifndef _SDL_IMAGE_H
#define _SDL_IMAGE_H

#define LOAD_BMP



Add in #define LOAD_PNG to make it like this


#ifndef _SDL_IMAGE_H
#define _SDL_IMAGE_H

#define LOAD_BMP
#define LOAD_PNG



Each file type that SDL_Image loads has a different value that needs to be defined. Look through the code to find them.

Share this post


Link to post
Share on other sites
Kylotan    9879
I thought that was only the case if you built the library yourself. If not, make sure you have the relevant 2 extra DLLs - libpng and zlib, I believe.

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