Hi there.
I just recently switched to Linux and am having some issues running some code that has Allegro 5 in it. Below is my code.
I compile the file as such: "g++ -o mygame game.cpp $(pkg-config --libs allegro-5 allegro_image-5)". It compiles without error. When I go to run my game (./mygame), it returns... "mygame: /home/pi/Desktop/allegro/src/bitmap_draw.c:137: al_draw_tinted_bitmap: Assertion `bitmap' failed."
I'm guessing it means that I am pointing to a NULL bitmap, but I'm not! My "object.png" resides on my desktop just as "game.cpp" does. Any ideas?
Well, check for NULL in code then you will know if it's really not NULL.
All the info he needs is already in his previous threads.
I checked if my bitmap was NULL, and if it was, I'd end the game; it ended the game. I don't understand why though, because it's right there. I feel like I'm telling an old dog to fetch a stick that's two feet from it, yet it won't.
Anyway, I decided to check out some of the examples that were found in the examples folder within Allegro 5. I ran the ex_draw_bitmap, but it returned this to the terminal: "Error loading data/mysha256x256.png". I checked the corresponding folder, and it was there; it exists, yet it cannot be procured.
Thoughts?
My "object.png" resides on my desktop just as "game.cpp" does.
If you're using that path thing I showed you, the data (or relative path) has to be the same as the executable, not the source file.
I am slightly confused by your message.
Let's say that all of my game data is located under /home/pi/Desktop/game. Within that directory, I have a sub-directory called "data" (/home/pi/Desktop/game/data). In code, let's say that I load up a bitmap called "player"... ALLEGRO_BITMAP *player = al_load_bitmap("data/player.png");
Now let's assume that I compile my game and am left with "mygame" under home/pi/Desktop/game. I'd run ./mygame (within the directory of my game) to execute it. Are you saying that mygame (the executable) must reside within the same directory as all of my sources? So within /home/pi/Desktop/game, I would have mygame and /data?
Edit
Does this look right?
ALLEGRO_PATH *path; path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); al_change_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); ALLEGRO_BITMAP *player = al_load_bitmap("data/player.png");
Is that how I'd use the path code?
Yes, that looks right.
BTW, try this
Hi again.
I tried that, and it said that the current directory is "/home/pi/Desktop", which is right. Alas, it still won't load my images.
I tried that, and it said that the current directory is "/home/pi/Desktop", which is right. Alas, it still won't load my images.
That's because you're in the wrong directory! Pay attention dude! That was the whole point of Arthur's test. You're trying to load from data/player.png when the relative path from /home/pi/Desktop is /game/data/player.png.
Which directory did you run Arthur's test program from? I'm just curious is all.
I used data/player.png as an example. In reality, all of my files are on /home/pi/Desktop: game.cpp, object.png, etc.
I ran his test program from the Desktop. In the terminal, I went there (cd /home/pi/Desktop).
If you use Arthur's code, the current working directory will be the directory where your executable is. If you do not, the cwd will likely be the directory you ran the program from.
I don't care where your stuff is as long as you're using the proper path. If it is in game/data/test.png then use that.
And, it makes zero difference where your source files are. What matters is where your exe is, where you run the program from, and what the relative or absolute paths are.
There is an entry on the wiki titled troubleshooting resources. It's in the A5 tutorial somewhere. You should read it.
I honestly do not know why any of this is not working; it's quite troublesome. I am constantly returned with NULL for my resources.
I found an article on the wiki and followed its instructions. Here's what I now have...
al_init_image_addon(); al_install_keyboard(); al_install_mouse(); ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); al_append_path_component(path, "data"); al_change_directory(al_path_cstr(path, '/')); al_destroy_path(path); std::cout << al_get_current_directory() << endl; ALLEGRO_BITMAP *player = al_load_bitmap("player.png");
I compile and run it, and am still returned with "al_draw_tinted_bitmap: Assertion `bitmap' failed." My current directory (from running in the terminal) is (pwd) /home/pi/Desktop/game. The game itself tells the console that it is in /home/pi/Desktop/game/data (from line 10).
You shouldn't be getting any more 'assertion 'blah' failed' because you should be checking for NULL returns yourself, and taking action appropriately before that even happens.
Okay. It looks like your directory was data, like you wanted it to be. And player.png is in the data directory right? Well, if it still isn't loading then maybe png support wasn't built into your version of allegro. Did you install zlib and libpng before building allegro?
Yes, player.png is within the data directory. No, I do not believe I did install those prior to building Allegro 5, nor after... Perhaps that's my issue (how stupid of me).
Okay, so I'll need to install these. Should I purge Allegro 5 from my system first, then run through its installation again, or could I just build it again now, thus overwriting what I did before?
Why don't you try loading a .bmp first, to be sure.
Eureka (ha ha)! I placed a bitmap called "test.bmp" within the data directory, then referenced it in code... It works wonderfully! So then, it appears that .png files are the issue.
Don't uninstall anything.
Just sudo apt-get zlibdevel whatever and libpng and then rebuild allegro and reinstall it.
I sincerely appreciate the assistance, truly I do.
I'll try this out in a bit. I guess I'll have to redo CMake in my build directory, then make, then ultimately make install. Awesome.
Update
That worked wonderfully. Allegro 5 is working just fine now on my machine, as are .png images! Thanks everyone!