Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Load a .png File

This thread is locked; no one can reply to it. rss feed Print
Load a .png File
Skax459
Member #8,290
February 2007

I'm trying to load a .png into a game called Labyrinth, the file is called map1.png

The code I have to load it is:

char *filename = "map1.png";
    BITMAP *image;
    image = load_bitmap(filename, NULL);
    if (!image){set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);allegro_message("Error loading %s", filename);return 1;}
  for(int y_y = 0; y_y < 64; y_y++){
    for(int x_x = 0; x_x < 48; x_x++){
      (getpixel(image, x_x, y_y)==makecol(0,0,0))?(board[x_x][y_y] = 'x'):(board[x_x][y_y]);
    }
  }

The indenting is a little weird because I didn't want to put in the whole main function.
(The getpixel is just to take the picture and load it into a character array)

Allegro gets initialized all nice, the project works fine without this code. It puts up the error message "Error loading map1.png" which means its not a code problem (or is it?) but instead where I put the file. I'm using Visual C++ 8.0.

There is the main folder Labyrinth with two folders in it, Labyrinth and release; along with the solution and the intellisense thing. Inside Labyrinth (the second one) is the project itself, the .cpp file and a .h, along with another folder called Release (capitalized unlike the other release folder) Inside the Release folder are some files, a manifest, but not the exe. Inside release (lowercase) is solely the exe.

Anyone know where I should put the PNG?

EDIT: I tried running the program with map1.png in every single folder and it still didn't load properly. ???

BAF
Member #2,981
December 2002
avatar

Do you have loadpng setup and working correctly? Allegro can't load PNG natively, you need the loadpng addon.

The map1.png file should be in the working directory of the program (usually, the same folder as the exe).

Thomas Fjellstrom
Member #476
June 2000
avatar

Allegro doesn't support PNG out of the box. If you're not using loadpng you probably want to. It lets load_bitmap load png images. it also requires you to link to libpng and libz (zlib).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Skax459
Member #8,290
February 2007

What does allegro load natively? Just bmp?
EDIT: I changed everything to bmp (the code, the picture) and it still won't load.

Thomas Fjellstrom
Member #476
June 2000
avatar

It does bmp, pcx, tga and I think thats it.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Skax459
Member #8,290
February 2007

Its all in BMP but it still isnt working. Do you think its a location problem or a code problem?

X-G
Member #856
December 2000
avatar

This is really bad coding style. If statements, for crying out loud! Indentation!

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Paul whoknows
Member #5,081
September 2004
avatar

Quote:

I changed everything to bmp (the code, the picture) and it still won't load.

If you need alpha channel TGA is the best option with allegro, otherwise just use PCX, but avoid BMP at any cost!

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Steve Terry
Member #1,989
March 2002
avatar

You did convert the image to bitmap and not rename the extension to bmp :P

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Go to: