Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How can I load png files with Allegro?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
How can I load png files with Allegro?
Tibor Fober
Member #9,791
May 2008

Hello. What should I do to load png?
I have allegro 4.2.2(last stable version) and I downloaded libpng,and zlib.
I link to alleg.lib, loadpng.lib, zdll.lib. But if I only write after initialize allegro BITMAP *png = load_png("name.png",NULL);
The Compiler (msvc2008 c++ express) said he cant find:
Verweis auf nicht aufgelöstes externes Symbol "_png_error" in Funktion "_read_data".
Verweis auf nicht aufgelöstes externes Symbol "_png_get_io_ptr" in Funktion "_read_data".
and so on... Had I link some false?
I hope someone can help me.

Greetz,
Tibo

Erin Maus
Member #7,537
July 2006
avatar

Link with this: alleg.lib loadpng.lib <zlib> <libpng> (where zlib/libpng are the correct names; I don't know what they are, since I don't use LoadPNG with MSVC).

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Tibor Fober
Member #9,791
May 2008

my problem is... i havent got a data named loadpng.lib only have zdll.lib and libpng.lib.... where do i get support for MSVC... i only find linux and unix support...
If i download loadpng from here:
http://tjaden.strangesoft.net/loadpng/
ldpng15.zip (90.8k)
there are only some make files examples and headers but no library....
please help me guys.

Best Regards,
Tibo

Erin Maus
Member #7,537
July 2006
avatar

For MSVC, try and directly add the LoadPNG files (all the C source files and header files) to your project and see what happens (linking with libpng and zlib, too).

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Tibor Fober
Member #9,791
May 2008

Here see the code:

#include <WinAllegro.h>
#include "loadpng.h"
#include <png.h>
#include <zlib.h>

int main(int argc, char **argv)
{
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);



BITMAP *bmp;
register_png_file_type();

return 0;
} END_OF_MAIN()

and I link to alleg.lib, zdll.lib, and libpng.lib

here is the error message only for register_png_file_type()

1>main.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_register_png_file_type".
1>C:\Users\Tibo\pngtest\pngtest\Debug\pngtest.exe : fatal error LNK1120: 1 nicht aufgelöste externe Verweise.

nicht aufgelöste externe verweise = unresolved extern symbol... so he cant find the function... but if i write the function in msvc he find the function...

ah and I found out that register_png_file() is only declared not defined... where is the definition of register_png_file() usually?

Tibo

Peter Wang
Member #23
April 2000

regpng.c

Tibor Fober
Member #9,791
May 2008

and if i include regpng.c he said:
Verweis auf nicht aufgelöstes externes Symbol "_load_png" in Funktion "_register_png_file_type".
Verweis auf nicht aufgelöstes externes Symbol "_save_png" in Funktion "_register_png_file_type".
Verweis auf nicht aufgelöstes externes Symbol "_load_memory_png" in Funktion ""void * __cdecl load_datafile_png(struct PACKFILE *,long)" (?load_datafile_png@@YAPAXPAUPACKFILE@@J@Z)".

I dont know... do loadpng really work?....

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Are you sure that all the loadpng files are being compiled? It sounds like the .o files haven't been made or they are not being linked against.

Tibor Fober
Member #9,791
May 2008

whats a .o file? I found a libpng-bcc.lib data and i linked to it.. but my compiler said this data is damaged or not valid...
I downloaded libpng from here
http://gnuwin32.sourceforge.net/packages/libpng.htm
i downloaded the complete package without sources...

Tibo

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Tibor Fober
Member #9,791
May 2008

does nobody know the problem?
Nobody use loadpng with MSVC?

Timorg
Member #2,028
March 2002

I made a wrapper that used gd to load images, at the moment its licensed under gpl, but I am in the process of getting the next release together and moving it to either lgpl or the gd licence so it can be used more easily in peoples projects.

It has project files for msvc 2005 and not so great instructions for v6, it allows you to also load gif and jpegs. :)

http://www.timorg.net/gdalleg/

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

Milan Mimica
Member #3,877
September 2003
avatar

Quote:

These are probably not for MSVC.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Are you planning to use the win32 API in your program?

#include <WinAllegro.h>
#include "loadpng.h"
#include <png.h>
#include <zlib.h>

If you want to use the win32 API with Allegro you need to include winalleg.h after allegro.h , which I don't see there and you've also misspelled 'winalleg.h' as WinAllegro.h.

Quote:

and if i include regpng.c he said:

So you've added all of loadpng's source files to your project right?

Tibor Fober
Member #9,791
May 2008

I'd make WinAllegro.h on my self... without WinAllegro allegro doesnt work with MSVC. Allegro havent got much support for windows... thats very bad. I'm not a windows fan but the IDE is very good...

Yes i added all loadpng sources. regpng savepng and so on...

To Milan Mimica:
So there arent any loadpng libpng files for MSVC?...

Vanneto
Member #8,643
May 2007

Quote:

I'd make WinAllegro.h on my self... without WinAllegro allegro doesnt work with MSVC. Allegro havent got much support for windows... thats very bad. I'm not a windows fan but the IDE is very good...

Hehe, that made my day. ;D

Anyway, why make it yourself? Can't you read?

#include "WinAllegro.h" // WRONG! Even if you make it yourself...
#include <winalleg.h> // Correct.

In capitalist America bank robs you.

Milan Mimica
Member #3,877
September 2003
avatar

Quote:

So there arent any loadpng libpng files for MSVC?

Compile them yourself. A C programmer should be used to compile things.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

Allegro havent got much support for windows...

That's really not true. Check the manual.

From Allegro manual - Windows Specifics

Quote:

A Windows program that uses the Allegro library is only required to include one or more header files from the include/allegro tree, or allegro.h; however, if it also needs to directly call non portable Win32 API functions, it must include the Windows-specific header file winalleg.h after the Allegro headers, and before any Win32 API header file. By default winalleg.h includes the main Win32 C API header file windows.h. If instead you want to use the C++ interface to the Win32 API (a.k.a. the Microsoft Foundation Classes), define the preprocessor symbol ALLEGRO_AND_MFC before including any Allegro header so that afxwin.h will be included. Note that, in this latter case, the Allegro debugging macros ASSERT() and TRACE() are renamed AL_ASSERT() and AL_TRACE() respectively.

So if you want to use the Win32 API , include allegro.h and then winalleg.h.

#include <allegro.h>
#include <winalleg.h>

As far as the unresolved external symbol errors you've been getting , I think it's from linking in the wrong order. You need to have linked against zlib and libpng for any png functions to work and for 'register_png_file_type' to work you should need to link against allegro and the loadpng object files.

So I'm guessing that the correct order to link in is : zlib , libpng , and then allegro.

Tibor Fober
Member #9,791
May 2008

what should i compile? the regpng loadpng savepng sources?
WTF? Without my code allegro doesnt work... and I dont use Winapi:
See whats written in my code:
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 312)
#include "allegro.h"
#pragma warning(pop)
#else
#include "allegro.h"
#endif

And winalleg including doesnt work right. I tried everything but without this code allegro doesnt work by me.

Hey guys... its working now.... thank you soo much for help. I dont know what was my fault but after i installed all allegro and libpng zlib again it works fine.
Thanks

Greetz,
Tibo

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

So that's the only code in your "WinAllegro.h" file?
Did you have to do that because using #include <allegro.h> in your main.c file didn't work? (Notice that it should be #include <allegro.h> and not #include "allegro.h"). You had me confused because you called your preprocessor defines file WinAllegro.h and I'd never heard of it before.

Quote:

what should i compile? the regpng loadpng savepng sources?

Yes , along with the other source files in your project and then link them all together.

Tibor Fober
Member #9,791
May 2008

ya without the WinAllegro.h allegro doesnt work^^ I only have to include loadpng.h
If I include the others error message appear^^ so thanks for your help Edgar and the others. It's working fine now.

Edit: Omfg sry next problem. Why does transparency doesnt work?
I only can use alpha blending on pngs? or is there a special method to do png transparent.

Greetz,
Tibo

Evert
Member #794
November 2000
avatar

Quote:

Without my code allegro doesnt work...
[...]
ya without the WinAllegro.h allegro doesnt work

This is blatently not true. Post whatever error message you get and we'll tell you how to fix it, or point you in the right direction.

Quote:

Why does transparency doesnt work?

Clarify "doesn't work".
However, I'm going to make a guess and tell you you're either not using magic pink (max red and blue, no green) for a true or high colour image, or not using colour 0 for an 8-bit palette image as your mask colour.

Tibor Fober
Member #9,791
May 2008

I'm dumb! brother I have 2 gfx in my project folder both are the same images only the format isnt the same. One is .bmp and the other is .png if I draw them both using draw_sprite the bmp is transparent but the png isnt transparent....
So its not my fault...

Here is the error code without WinAllegro.h and with allegro.h

1>d:\lib\allegro v4.2.2\include\allegro\internal\alconfig.h(397) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned char *'
1>d:\lib\allegro v4.2.2\include\allegro\internal\alconfig.h(404) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned char *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(421) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned char *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(435) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned char *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(446) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned short *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(460) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned short *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(471) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned short *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(485) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned short *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(521) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned int *'
1>d:\lib\allegro v4.2.2\include\allegro\inline\draw.inl(535) : warning C4312: 'Typumwandlung': Konvertierung von 'unsigned int' in größeren Typ 'unsigned int *'

have fun^^.

Konvertierung von 'unsigned int' in größeren Typ 'unsigned int * =
Convert from unsigned int in bigger type unsigned int*.

Thanks for help.

Matthew Leverton
Supreme Loser
January 1999
avatar

Those are warnings, not errors, and can be disabled by unselecting the "Detect 64-bit compatibility problems" in the settings.

Evert
Member #794
November 2000
avatar

Quote:

One is .bmp and the other is .png if I draw them both using draw_sprite the bmp is transparent but the png isnt transparent....
So its not my fault...

One way or the other, it is your fault, because both are Allegro BITMAPs after they've been loaded. At that time, the on-disk format is no longer relevant.
Attach both images so we can have a look at them.

Quote:

Here is the error code

I see no errors, just warnings.

 1   2 


Go to: