Code Search for Developers
 
 
  

exdbuf.c from Allegro game programming library at Krugle


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

Allegro game programming library

Allegro is a cross-platform library intended for use in computer games and other types of multimedia programming.

Project homepage: http://sourceforge.net/projects/alleg
Programming language(s): Assembly,C,Shell Script
License: other

  allegro.pcx
  ex12bit.c
  ex3buf.c
  ex3d.c
  exaccel.c
  exalpha.c
  example.dat
  example.h
  examples.txt
  exbitmap.c
  exblend.c
  excamera.c
  excolmap.c
  excustom.c
  exdata.c
  exdbuf.c
  exdodgy.c
  exexedat.c
  exfixed.c
  exflame.c
  exflip.c
  exgui.c
  exhello.c
  exjoy.c
  exkeys.c
  exlights.c
  exmem.c
  exmidi.c
  exmouse.c
  expal.c
  expat.c
  exquat.c
  exrgbhsv.c
  exsample.c
  exscale.c
  exscn3d.c
  exscroll.c
  exshade.c
  exspline.c
  exsprite.c
  exstars.c
  exstream.c
  exswitch.c
  extimer.c
  extrans.c
  extruec.c
  exunicod.c
  exupdate.c
  exxfade.c
  exzbuf.c
  mysha.pcx
  planet.pcx
  running.dat
  running.h
  unifont.dat