Show exflip.c syntax highlighted
/*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This program moves a al_draw_circle across the al_screen, first with a
* double buffer and then using page flips.
*/
#include "allegro.h"
int main()
{
AL_BITMAP *buffer;
AL_BITMAP *page1, *page2;
AL_BITMAP *active_page;
int c;
allegro_init();
al_install_timer();
/* Some platforms do page flipping by making one large al_screen that you
* can then scroll, while others give you several smaller, unique
* surfaces. If you use the al_create_video_bitmap() function, the same
* code can work on either kind of platform, but you have to be careful
* how you set the video mode in the first place. We want two pages of
* 320x200 video memory, but if we just ask for that, on DOS Allegro
* might use a VGA driver that won't later be able to give us a second
* page of vram. But if we ask for the full 320x400 virtual al_screen that
* we want, the call will fail when using DirectX drivers that can't do
* this. So we try two different mode sets, first asking for the 320x400
* size, and if that doesn't work, for 320x200.
*/
if (al_set_gfx_mode(AL_GFX_AUTODETECT, 320, 200, 0, 400) != 0) {
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 with a double buffer... */
c = al_retrace_count+32;
while (al_retrace_count-c <= AL_SCREEN_W+32) {
al_clear_to_color(buffer, al_make_color(255, 255, 255));
al_draw_circle_fill(buffer, al_retrace_count-c, 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);
/* now create two video memory bitmaps for the page flipping */
page1 = al_create_video_bitmap(AL_SCREEN_W, AL_SCREEN_H);
page2 = al_create_video_bitmap(AL_SCREEN_W, AL_SCREEN_H);
if ((!page1) || (!page2)) {
al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
al_show_message("Unable to create two video memory pages\n");
return 1;
}
active_page = page2;
/* do the animation using page flips... */
for (c=-32; c<=AL_SCREEN_W+32; c++) {
al_clear_to_color(active_page, al_make_color(255, 255, 255));
al_draw_circle_fill(active_page, c, AL_SCREEN_H/2, 32, al_make_color(0, 0, 0));
al_printf_text(active_page, al_font_8x8, 0, 0, al_make_color(0, 0, 0),
"Page flipping (%s)", gfx_driver->name);
al_show_video_bitmap(active_page);
if (active_page == page1)
active_page = page2;
else
active_page = page1;
}
al_destroy_bitmap(page1);
al_destroy_bitmap(page2);
return 0;
}
AL_END_OF_MAIN();
See more files for this project here