Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [4.9.12] Making a screenshot

This thread is locked; no one can reply to it. rss feed Print
[4.9.12] Making a screenshot
Michael Faerber
Member #4,800
July 2004
avatar

Hi!

In SpeedHack I tried to save a screenshot of the screen (after having drawn to it), but I failed - it seemed that only white got saved to my temporary bitmap.

The following code was used to test if my method of grabbing the screen was correct. It should basically draw the current screen image to a bitmap and then draw it back on the screen. However, the screen was all white afterwards.

ALLEGRO_BITMAP *scrshot = al_create_bitmap(800, 600);
al_set_target_bitmap(scrshot);
al_clear_to_color(al_map_rgb_f(0, 0, 0));
al_draw_bitmap(al_get_backbuffer(), 0, 0, 0);
al_set_target_bitmap(al_get_backbuffer());
al_draw_bitmap(scrshot, 0, 0, 0);

Does anybody know what's going on here?

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

Matthew Leverton
Supreme Loser
January 1999
avatar

I just tested on Windows.

Direct 3D

  • al_get_backbuffer() before al_flip_display(): works

  • al_get_backbuffer() after al_flip_display(): works

  • al_get_frontbuffer() before al_flip_display(): crashes

OpenGL

  • al_get_backbuffer() before al_flip_display(): works

  • al_get_backbuffer() after al_flip_display(): black screen

  • al_get_frontbuffer() before al_flip_display(): black screen

(Each of the above was passed directly to al_save_bitmap().)

Accessing the front buffer isn't guaranteed to work at all, so no surprises there.

Milan Mimica
Member #3,877
September 2003
avatar

Keep in mind backbuffer is undefined after al_flip_display().

Go to: