SDL_Image and PNG support

I’m attempting to add PNG support to SDL_Image, but have so far been unsuccessful. Got the lpng155 package from the libpng page (http://www.libpng.org/pub/png/libpng.html), and modified the SDL_Image 1.2.10 (http://www.libsdl.org/projects/SDL_image/) Visual Studio project to have this linker flag:

LOAD_PNG_DYNAMIC=“libpng15.dll”

That is because the DLL produced by the png155 package is named as above. I recompile the SDL_Image.dll and copy it to my project’s Visual Studio Release and Debug folders.

However, my test program still fails to load .png images, while .bmp load fine. (IMG_Load_RW returns NULL, while SDL_RWFromFile does indeed have a file pointer.) This seems to indicate that SDL_Image is still does not “know” it has PNG support available to it via libpng15.dll.

Am I doing something wrong, in the way I’m trying to give SDL_Image access to PNG loading?

…huh?? SDL_Image has had PNG support for years.________________________________
From: vern@actionsoft.com (VernJensen)
Subject: [SDL] SDL_Image and PNG support

I’m attempting to add PNG support to SDL_Image, but have so far been unsuccessful. Got the lpng155 package from the libpng page (http://www.libpng.org/pub/png/libpng.html), and modified the SDL_Image 1.2.10 (http://www.libsdl.org/projects/SDL_image/) Visual Studio project to have this linker flag:

LOAD_PNG_DYNAMIC=“libpng15.dll”

That is because the DLL produced by the png155 package is named as above. I recompile the SDL_Image.dll and copy it to my project’s Visual Studio Release and Debug folders.

However, my test program still fails to load .png images, while .bmp load fine. (IMG_Load_RW returns NULL, while SDL_RWFromFile does indeed have a file pointer.) This seems to indicate that SDL_Image is still does not “know” it has PNG support available to it via libpng15.dll.

Am I doing something wrong, in the way I’m trying to give SDL_Image access to PNG loading?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Mason Wheeler wrote:

…huh? SDL_Image has had PNG support for years.

Hmm, you’re right. Any thoughts on why it won’t load PNGs then? If I modify the testsprite2 demo to use SDL_Image to load the file like so:

LoadSprite(char *file)
{
int i;
SDL_Surface *temp = NULL;
SDL_RWops *ops;

// Load the sprite image

// temp = SDL_LoadBMP(file); // original way

ops = SDL_RWFromFile(file, "rb");	// new way
if (ops != NULL)
{
	temp = IMG_Load_RW(ops, 0);
	SDL_RWclose(ops);
}

then it works fine as long as *file is “icon.bmp” but it fails when it’s “icon.png”. (And yes, I put an icon.png file in the Release and Debug directories.)

Something that’s made this difficult to debug for me though is that even with “icon.bmp” it won’t find the file if I launch from within Visual Studio – it only finds the file if I launch by double-clicking the executable directly. Likely this is because the default “home directory” is different when launched from within Visuual Studio. Any thoughts on what I need to do to correct this? Would be handy to have it work while running from within the debugger…

-Vern

Side question: the SDL_Image distribution contains a folder called “Graphics” that contains:

jpeg.dll
libtiff-3.dll
libpng12-0.dll
zlib1.dll

Do these need to be included in my app’s distribution if I want access to those features, or are they “compiled into” the SDL_image.dll so that only SDL_image.dll is needed?

You’ll need these files as well. The easiest way to determine what files
are needed would be to run depends.exe on your game executable. I also use
the OUTPUT window to see what DLLs are loaded and from what location.

-Vijay

On Wed, 02 Nov 2011 11:58:08 -0700, “VernJensen” wrote: Side
question: the SDL_Image distribution contains a folder called "Graphics"
that contains:

jpeg.dll
libtiff-3.dll
libpng12-0.dll
zlib1.dll

Do
these need to be included in my app’s distribution if I want access to
those features, or are they “compiled into” the SDL_image.dll so that only
SDL_image.dll is needed?–


Vijay Varadan
Skype:
vijayvaradan | USA: +1-206-849-3710 ©
India: +1-425-956-3326 (VOIP) |
India: +91-99400-13652 ©
LinkedIn: http://linkd.in/qTORH7 [1] | Blog:
http://bit.ly/oQBwNl [2]
Google+: http://bit.ly/vijayplus [3] | Facebook:
http://on.fb.me/oF7dq9 [4]
Twitter: http://bit.ly/qsiqrp [5]

AXHAM
CORPORATION | Axham Technologies, LLP
LinkedIn: http://linkd.in/nL9wNX [6]
| LinkedIn: http://linkd.in/odgEc9 [7]
Website: http://axham.com [8] |
Facebook: http://on.fb.me/axhamgames [9]
Twitter: http://bit.ly/mPaDwB
[10]

Links:

[1] http://linkd.in/qTORH7
[2]
http://bit.ly/oQBwNl
[3] http://bit.ly/vijayplus
[4]
http://on.fb.me/oF7dq9
[5] http://bit.ly/qsiqrp
[6]
http://linkd.in/nL9wNX
[7] http://linkd.in/odgEc9
[8] http://axham.com/
[9]
http://on.fb.me/axhamgames
[10] http://bit.ly/mPaDwB

Thanks Vijay. Just figured that out, as I got it working by re-installing an unmodified SDL_Image with its origianl PNG support. My PNGs are finally loading! Yeay. :slight_smile:

Only question remaining then is why it works when launching the .exe directly, but not when running from within Visual Studio. How do I “fix the path” when running from within Visual Studio so it finds the data files in the correct location? (Well I guess that’s kinda off-topic…)

You’re looking for the so-called “Working Directory”. It is an option in
Project Properties->Debugging.On Wed, Nov 2, 2011 at 2:07 PM, VernJensen wrote:

**
Thanks Vijay. Just figured that out, as I got it working by re-installing
an unmodified SDL_Image with its origianl PNG support. My PNGs are finally
loading! Yeay. [image: Smile]

Only question remaining then is why it works when launching the .exe
directly, but not when running from within Visual Studio. How do I “fix the
path” when running from within Visual Studio so it finds the data files in
the correct location? (Well I guess that’s kinda off-topic…)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Why not just use IMG_Load( file )?

Also, when you run the application
in the debugger, the default VS behavior is to set the working directory to
be the base project directory. I think it’s coz the typical layout will be
like this for a distributed app:

app.exe
|- subdir1

- resource1

resource2
|- subdir1
|- resource1
|- resource2
To get the same
effect, simply run the game executable from the project directory like
this: C:MyGameSolutionMyGameProject>.debugmygame.exe That way you don’t
have to keep copying files from the project root or its subdirectories into
the output directory. This is better than either of the 2 alternatives of
copying files into the debug directory or copying the game.exe to the
project directory. Ideally, you’d change your project to build
intermediates and final output files to directories outside your source
tree and as a post build step copy your assets to the final output
location. -VijayOn Wed, 02 Nov 2011 11:53:01 -0700, “VernJensen” wrote:

	Mason Wheeler wrote:

	...huh? SDL_Image has had PNG

support for years.

Hmm, you’re right. Any thoughts on why it won’t load
PNGs then? If I modify the testsprite2 demo to use SDL_Image to load the
file like so:

LoadSprite(char *file)
{
int i;
SDL_Surface *temp =
NULL;
SDL_RWops *ops;

// Load the sprite image
// temp =
SDL_LoadBMP(file); // original way

ops = SDL_RWFromFile(file, “rb”); //
new way
if (ops != NULL)
{
temp = IMG_Load_RW(ops, 0);

SDL_RWclose(ops);
}

then it works fine as long as *file is "icon.bmp"
but it fails when it’s “icon.png”. (And yes, I put an icon.png file in the
Release and Debug directories.)

Something that’s made this difficult to
debug for me though is that even with “icon.bmp” it won’t find the file if
I launch from within Visual Studio – it only finds the file if I launch by
double-clicking the executable directly. Likely this is because the default
"home directory" is different when launched from within Visuual Studio. Any
thoughts on what I need to do to correct this? Would be handy to have it
work while running from within the debugger…

-Vern

Patrick Baggett wrote:

You’re looking for the so-called “Working Directory”. It is an option in Project Properties->Debugging.

Thanks! Fixed the working directory, and now it works like a charm. Yeay. :slight_smile:

Vijay Varadan wrote:

Why not just use IMG_Load( file )?

It has to do with an SDL-based game engine I’m attempting to get up and running on Windows. It uses the other method for various reasons, hence why I wanted my test program to use the same exact method.

Thanks so much for the help everyone!

-Vern