[4.9.12] Making a screenshot
Michael Faerber

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?

Matthew Leverton

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

Keep in mind backbuffer is undefined after al_flip_display().

Thread #600955. Printed from Allegro.cc