[Resolved] IMG_Load won't load a PNG

Started by
2 comments, last by matrisking 13 years, 11 months ago
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]
Advertisement
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.
This man made my day: http://www.gamedev.net/community/forums/topic.asp?topic_id=523021
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.
That did the trick, I forgot all about those.

Thanks!

This topic is closed to new replies.

Advertisement