Show exdbuf.c syntax highlighted
/*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This program demonstrates the use of double buffering.
* It moves a al_draw_circle across the al_screen, first just erasing and
* redrawing directly to the al_screen, then with a double buffer.
*/
#include "allegro.h"
int main()
{
AL_BITMAP *buffer;
int c;
allegro_init();
al_install_timer();
if (al_set_gfx_mode(AL_GFX_SAFE, 320, 200, 0, 0) != 0) {
al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
al_show_message("Unable to set any graphic mode\n%s\n", al_error);
return 1;
}
al_set_palette(al_desktop_palette);
al_text_mode(-1);
/* allocate the memory buffer */
buffer = al_create_bitmap(AL_SCREEN_W, AL_SCREEN_H);
/* First without any buffering...
* Note use of the global retrace_counter to control the speed. We also
* compensate al_screen size (AL_GFX_SAFE) with a virtual 320 al_screen width.
*/
c = al_retrace_count+32;
while (al_retrace_count-c <= 320+32) {
al_acquire_screen();
al_clear_to_color(al_screen, al_make_color(255, 255, 255));
al_draw_circle_fill(al_screen, (al_retrace_count-c)*AL_SCREEN_W/320, AL_SCREEN_H/2, 32, al_make_color(0, 0, 0));
al_printf_text(al_screen, al_font_8x8, 0, 0, al_make_color(0, 0, 0), "No buffering (%s)",
gfx_driver->name);
al_release_screen();
}
/* and now with a double buffer... */
c = al_retrace_count+32;
while (al_retrace_count-c <= 320+32) {
al_clear_to_color(buffer, al_make_color(255, 255, 255));
al_draw_circle_fill(buffer, (al_retrace_count-c)*AL_SCREEN_W/320, AL_SCREEN_H/2, 32, al_make_color(0, 0, 0));
al_printf_text(buffer, al_font_8x8, 0, 0, al_make_color(0, 0, 0), "Double buffered (%s)",
gfx_driver->name);
al_blit(buffer, al_screen, 0, 0, 0, 0, AL_SCREEN_W, AL_SCREEN_H);
}
al_destroy_bitmap(buffer);
return 0;
}
AL_END_OF_MAIN();
See more files for this project here