Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » PNG files?

Credits go to Edgar Reynaldo, LennyLen, Oscar Giner, and Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
PNG files?
David Sopala
Member #5,056
September 2004

Still failing to load image correctly - I did use one of your sprites. I know my working path is right because I have loaded a couple .bmps from the same folder. My test code follows maybe I am doing something wrong?

#SelectExpand
1#include <winalleg.h> 2#include <loadpng.h> 3#include <zlib.h> 4 5#include <fstream> 6 7#include <conio.h> 8#include <string.h> 9using namespace std; 10 11//FONT *big_font = NULL; 12int volume; 13const int scrx = 1024; 14const int scry = 768; 15BITMAP *target; 16BITMAP *BUFFER; 17bool insidecircle(int tx,int ty,int x,int y,int rad); 18void ini(); 19bool keyrel(int k); 20 21RGB* my_palette; 22COLOR_MAP global_trans_table; 23ofstream out; 24 25int main() 26{ 27 28 29 ini(); 30 target = NULL; 31 out<<"Loading png filetype"<<endl; 32 target = load_bitmap("0.png",NULL); 33 out<<"Target : "<<target<<endl 34 <<"Target &: "<<target<<endl; 35 if(!target)allegro_message("Failed to load image"); 36 while(!key[KEY_ESC]) 37 { 38 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); 39 set_alpha_blender(); 40 if(target)draw_trans_sprite(screen, target, 64, 64); 41 // ... draw more translucent bitmaps 42 solid_mode(); 43 //blit(BUFFER,screen,0,0,0,0,scrx,scry); 44 45 } 46 47 return 0; 48} 49END_OF_MAIN() 50 51void ini() 52{ 53 out.open("log.txt"); 54 if (allegro_init()) 55 { 56 allegro_message("Cannot initalize Allegro. Quiting\n"); 57 exit(101); 58 } 59 //Set the window title when in a GUI environment 60 set_window_title("PNG test draw"); 61 62 if (install_keyboard()) 63 { 64 allegro_message("ERROR: Cannot initalize keyboard input. Quiting\n"); 65 exit(102); 66 } 67 68 if (!install_mouse()) 69 { 70 allegro_message("ERROR: Cannot initalize mouse input. Quiting\n"); 71 exit(103); 72 } 73 install_timer(); 74 install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); 75 //DATAFILE * d=load_datafile("comic.dat"); 76 //if (d) 77 //{ 78 //big_font = (FONT*)d[0].dat; 79 //} 80 set_mouse_sprite(NULL); 81 //set graphics mode, trying all acceptable depths 1024x768 82 set_color_depth(32); 83 if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) { 84 set_color_depth(24); 85 if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) { 86 set_color_depth(16); 87 if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) { 88 set_color_depth(15); 89 if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) { 90 allegro_message("Video Error: %s.\n", allegro_error); 91 exit(1); 92 } 93 } 94 } 95 } 96 out<<"REGISTERING PNG FILETYPE"<<endl; 97 register_png_file_type(); 98 out<<"REGISTRATION SUCCESSFUL"<<endl; 99 100 out<<"Creating trans table"<<endl; 101 my_palette = new PALETTE; 102 create_trans_table(&global_trans_table, my_palette,128, 128, 128, NULL); 103 out<<"Color depth is "<<get_color_depth()<<endl; 104 if (get_color_depth() == 8) 105 { 106 color_map = &global_trans_table; 107 } 108 109 else 110 { 111 set_trans_blender(128, 128, 128, 128); 112 } 113 out<<"Leaving ini()"<<endl; 114 115}

OUTPUT:

REGISTERING PNG FILETYPE
REGISTRATION SUCCESSFUL
Creating trans table
Color depth is 32
Leaving ini()
Loading png filetype
Target  : 0
Target &: 0

GullRaDriel
Member #3,861
September 2003
avatar

/* That line means that 0.png is in the same directory as the executable trying to laod it*/

target = load_bitmap("0.png",NULL);

/* these two one will print the same thing two times no matter what the value is.*/
out<<"Target  : "<<target<<endl
   <<"Target &: "<<target<<endl;

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

LennyLen
Member #5,313
December 2004
avatar

Try the most basic test example and see if that produces the same result.

eg:

#SelectExpand
1#include <allegro.h> 2#include <loadpng.h> 3 4int main() { 5 6 allegro_init(); 7 install_keyboard(); 8 set_color_depth(32); 9 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); 10 11 register_png_file_type(); 12 BITMAP *bmp = load_bitmap("0.png", NULL); 13 if(!bmp) { 14 allegro_message("Error opening image."); 15 exit(-1); 16 } 17 18 blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h); 19 20 readkey(); 21 22 return 0; 23 24} 25END_OF_MAIN()

I couldn't check that code myself as there isn't even a compiler installed on this machine.

David Sopala
Member #5,056
September 2004

@GullRaDriel I already said it was in the directory. Please read all the posts before quick posting bs that still has no bearing on the situation.

#SelectExpand
1Directory of C:\Users\XXXXX\Desktop\png test draws\png test draw\bin\Debug 2 309/22/2011 06:23 AM <DIR> . 409/22/2011 06:23 AM <DIR> .. 504/10/2010 11:04 AM 3,503 0.png 604/09/2010 11:24 PM 2,354,267 alld42.dll 704/09/2010 11:24 PM 566,399 alleg42.dll 808/27/2011 09:23 PM 989,740 allegro-4.4.2-md.dll 904/09/2010 11:24 PM 1,062,974 allp42.dll 1009/20/2011 10:09 PM 43,008 libgcc_s_dw2-1.dll 1108/27/2011 09:23 PM 258,796 loadpng-1.5-md.dll 1209/22/2011 06:23 AM 155 log.txt 1309/22/2011 06:23 AM 925,206 png test draw.exe 1409/20/2011 06:40 PM 16,889,526 sidewalk_pavement_texture_01.bmp 1509/19/2011 04:18 PM 6,182 spider.png 1609/20/2011 06:27 PM 12,342 spider256_magic_pink.bmp 17 12 File(s) 23,112,098 bytes 18 2 Dir(s) 280,725,102,592 bytes free

@LennyLen

Yea, still have it with your code... not sure whats going on. Perhaps something isn't linked correctly somewhere.

linker settings
-lloadpng-1.5-mt -lpng -lz

linker libs
..\..\..\..\..\Program Files (x86)\GnuWin32\lib\libpng.lib
..\..\..\..\..\Program Files (x86)\GnuWin32\lib\zlib.lib
..\..\..\..\..\Program Files (x86)\CodeBlocks\MinGW\lib\liballeg.a

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Right click on your 0.png file and look at it's properties. It might have a clue. After that, try loading it in an image editor and see if that works. If it does, try saving it again under a different name. See if there are any properties about it that you can change.

David Sopala
Member #5,056
September 2004

Nothing I can change other than make it hidden or read-only, windows says it is ready for archiving, and Allow this file to have contents indexed in addition to file properties. Pulled it straight from the zip I got off lenny(which worked for him).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

David Sopala
Member #5,056
September 2004

It is correct because if I load an actual .bmp file it loads and displays just fine. Only having issues with the .png extention.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

David Sopala
Member #5,056
September 2004

There yea go.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

David Sopala
Member #5,056
September 2004

Binarys from a.cc only place I go for allegro's distribution.

I have allegro 4.4 I believe I will need to check
zlib 1.2.3
libpng 1.2.37

Just did a reinstall of all the updated versions of everything(to my knowledge)

Code::blocks 10.5

zlib-1.2.3
(only find zlib1.dll under bin.)

libpng-1.2.37
(only have 2 headers) png.h and pngconf.h

allegro-5.0.4-mingw-4.5.2

So, I have installed the packages from sourceforge.com....
Allegro's old header is no more it seems... (alleg.h) so I am going to go figure out what includes/libs I will need with the new allegro. Back in a bit.

Oscar Giner
Member #2,207
April 2002
avatar

Allegro 5 is a completely different lib. So unless you want to learn it and port your current project to it, use the latest Allegro 4.

David Sopala
Member #5,056
September 2004

Yea I noticed, at the same time I also understand it has png built in correct? One hell of a static link list though... although the walkthrough I found on it gave a good list I seem to be missing one fule, but thats for another topic. Since my server does not use any allegro code at all I think I can manage to code the client in allegro 5 and take advantage of the new hardware acceleration.

GullRaDriel
Member #3,861
September 2003
avatar

David said:

@GullRaDriel I already said it was in the directory. Please read all the posts before quick posting bs that still has no bearing on the situation.

I didn't said BullShit. All I did was spotting 2 evidences. Obvious for the first maybe.
But for the second, even if I'm no C++ guru, it'll for sure NOT print the address value of target since you're not passing it the &target parameter.

What else ? Keep cool when you talk to guys trying to help you. I also would have kicked your back, but you're too far away, bullshiter !

Else, have a nice day.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

 1   2 


Go to: