![]() |
|
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. 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
![]() |
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
![]() |
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). -- |
Skax459
Member #8,290
February 2007
|
What does allegro load natively? Just bmp? |
Thomas Fjellstrom
Member #476
June 2000
![]() |
It does bmp, pcx, tga and I think thats it. -- |
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
![]() |
This is really bad coding style. If statements, for crying out loud! Indentation! -- |
Paul whoknows
Member #5,081
September 2004
![]() |
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
![]() |
You did convert the image to bitmap and not rename the extension to bmp ___________________________________ |
|