Code Search for Developers
 
 
  

expat.c from Allegro game programming library at Krugle


Show expat.c syntax highlighted

/*
 *    Example program for the Allegro library, by Shawn Hargreaves.
 *
 *    This program demonstrates the use of patterned drawing and sub-bitmaps.
 */


#include "allegro.h"



void draw_pattern(AL_BITMAP *bitmap, char *message, int color)
{
   AL_BITMAP *pattern;

   al_acquire_bitmap(bitmap);

   /* create a pattern bitmap */
   pattern = al_create_bitmap(al_text_length(al_font_8x8, message), al_text_height(al_font_8x8));
   al_clear_to_color(pattern, al_bitmap_mask_color(pattern));
   al_put_text(pattern, al_font_8x8, message, 0, 0, al_palette_color[255]);

   /* cover the bitmap with the pattern */
   al_drawing_mode(DRAW_MODE_MASKED_PATTERN, pattern, 0, 0);
   al_draw_rect_fill(bitmap, 0, 0, bitmap->w, bitmap->h, al_palette_color[color]);
   al_drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);

   /* destroy the pattern bitmap */
   al_destroy_bitmap(pattern);

   al_release_bitmap(bitmap);
}



int main()
{
   AL_BITMAP *bitmap;

   allegro_init();
   al_install_keyboard();
   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_clear_to_color(al_screen, al_make_color(255, 255, 255));
   al_text_mode(al_bitmap_mask_color(al_screen));
   
   /* first cover the whole al_screen with a pattern */
   draw_pattern(al_screen, "<al_screen>", 255);

   /* draw the pattern onto a memory bitmap and then al_blit it to the al_screen */
   bitmap = al_create_bitmap(128, 32);
   al_clear_to_color(bitmap, al_make_color(255, 255, 255));
   draw_pattern(bitmap, "<memory>", 1);
   al_blit_masked(bitmap, al_screen, 0, 0, 32, 32, 128, 32);
   al_destroy_bitmap(bitmap);

   /* or we could use a sub-bitmap. These share video memory with their
    * parent, so the drawing will be visible without us having to al_blit it
    * across onto the al_screen.
    */
   bitmap = al_create_sub_bitmap(al_screen, 224, 64, 64, 128);
   al_draw_rect_fill(al_screen, 224, 64, 286, 192, al_make_color(255, 255, 255));
   draw_pattern(bitmap, "<subbmp>", 4);
   al_destroy_bitmap(bitmap);

   al_read_key();
   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