File: exdata.c

package info (click to toggle)
allegro4 2%3A4.0.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 17,052 kB
  • ctags: 12,972
  • sloc: ansic: 109,525; asm: 16,672; cpp: 3,221; sh: 1,761; makefile: 556; pascal: 105; perl: 73
file content (66 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 *    Example program for the Allegro library, by Shawn Hargreaves.
 *
 *    This program demonstrates how to access the contents of an
 *    Allegro datafile (created by the grabber utility).
 */


#include "allegro.h"


/* the grabber produces this header, which contains defines for the names
 * of all the objects in the datafile (BIG_FONT, SILLY_BITMAP, etc).
 */
#include "example.h"



int main(int argc, char *argv[])
{
   DATAFILE *datafile;
   char buf[256];

   allegro_init();
   install_keyboard(); 
   if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
      return 1;
   }

   /* we still don't have a palette => Don't let Allegro twist colors */
   set_color_conversion(COLORCONV_NONE);

   /* load the datafile into memory */
   replace_filename(buf, argv[0], "example.dat", sizeof(buf));
   datafile = load_datafile(buf);
   if (!datafile) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s!\n", buf);
      return 1;
   }

   /* select the palette which was loaded from the datafile */
   set_palette(datafile[THE_PALETTE].dat);

   /* aha, set a palette and let Allegro convert colors when blitting */
   set_color_conversion(COLORCONV_TOTAL);
   
   /* display the bitmap from the datafile */
   textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 255, 255));
   blit(datafile[SILLY_BITMAP].dat, screen, 0, 0, 64, 32, 64, 64);

   /* and use the font from the datafile */
   textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,
	   makecol(0, 255, 0));

   readkey();

   /* unload the datafile when we are finished with it */
   unload_datafile(datafile);

   return 0;
}

END_OF_MAIN();