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.

Great idea Elias, thanks. I updated my original posts code to reflect your suggestion. Works great.

Edit: I tried this out with a5_screenshot("Screenshots/DeluxePacman2"); and it saved it into the "Screenshots" folder as expected. Of course, the folder has to already exist, but it does work which is nice.

I assumed (based on manual) that there was no reliable cross-platform way to do that...

Even if there isn't, couldn't you bypass this by calling the screenshot function after drawing your current frame(and before flipping the screen)? At 60fps, there normally isn't too much difference between two frames, and the user won't notice the screenshot is one frame off.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Even if there isn't, couldn't you bypass this by calling the screenshot function after drawing your current frame(and before flipping the screen)? At 60fps, there normally isn't too much difference between two frames, and the user won't notice the screenshot is one frame off.

One problem is that there's no guarantee that the backbuffer even contains what you drew, or that theres only two pages, there could be many more.

One problem is that there's no guarantee that the backbuffer even contains what you drew, or that theres only two pages, there could be many more.

I meant taking a screenshot of the next frame instead of trying to get the current front buffer.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Or you could draw to a screen sized bitmap, and save that off.It seems like some games do that, as it takes them some time to actually create and save a screenshot.

You could easily redraw the current frame to that bitmap, instead of using the next frame as a screenshot. That's a less hackish way of doing it, I suppose.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates