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.
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).
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).
What does allegro load natively? Just bmp?
EDIT: I changed everything to bmp (the code, the picture) and it still won't load.
It does bmp, pcx, tga and I think thats it.
Its all in BMP but it still isnt working. Do you think its a location problem or a code problem?
This is really bad coding style. If statements, for crying out loud! Indentation!
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!
You did convert the image to bitmap and not rename the extension to bmp