I just whipped up this screenshot function for my Allegro 5 project I thought I would share if anyone wants it. It doesn't have all the bells and whistles, it basically saves a screenshot in the same folder as your executable. It can be easily modified to save elsewhere, just provide the path as part of the gamename you send to it I suppose.
It saves with the date + the time, so if you supply a game name like my "DeluxePacman" it would save it as "DeluxePacman_20130905_144600.png" for example. It uses 24hour time and the full year. The order is "YYYYMMDD_HHMMSS" so it will be listed in the folder in order that it was taken. This also easily allows you to take multiple screenshots with no limits, one per second.
If you prefer another format, just change PNG to JPG or BMP or whatever Allegro supports. I tested it and it works for me just fine.
I don't know if there is a way to automatically detect physfs and perhaps have the function automatically call `al_set_standard_file_interface()` and `al_set_physfs_file_interface()` or not, I just whipped this up quickly, but it would be nice if that functionality could be added. I suppose it should probably be left up to the person though.
Edit: I just updated this code and used Elias' suggestion to store the current file interface state, then switch to standard file interface, save the bitmap and restore the old state to what it was. Great solution. Works perfectly.
a5_screenshot(const char *
timeinfo = localtime(&
, gamename, timestr);
saved = al_save_bitmap(
saved) return false;
27 return true;
bool a5_screenshot(const char *gamename);