File: exxfade.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 (115 lines) | stat: -rw-r--r-- 2,469 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 *    Example program for the Allegro library, by Shawn Hargreaves.
 *
 *    This program demonstrates how to load and display bitmap files
 *    in truecolor video modes, and how to crossfade between them.
 */


#include "allegro.h"



int show(char *name)
{
   BITMAP *bmp, *buffer;
   PALETTE pal;
   int alpha;

   /* load the file */
   bmp = load_bitmap(name, pal);
   if (!bmp)
      return -1;

   buffer = create_bitmap(SCREEN_W, SCREEN_H);
   blit(screen, buffer, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

   set_palette(pal);

   /* fade it in on top of the previous picture */
   for (alpha=0; alpha<256; alpha+=8) {
      set_trans_blender(0, 0, 0, alpha);
      draw_trans_sprite(buffer, bmp, (SCREEN_W-bmp->w)/2, (SCREEN_H-bmp->h)/2);
      vsync();
      blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
      if (keypressed()) {
	 destroy_bitmap(bmp);
	 destroy_bitmap(buffer);
	 if ((readkey() & 0xFF) == 27)
	    return 1;
	 else
	    return 0;
      }
   }

   blit(bmp, screen, 0, 0, (SCREEN_W-bmp->w)/2, (SCREEN_H-bmp->h)/2, bmp->w, bmp->h);

   destroy_bitmap(bmp);
   destroy_bitmap(buffer);

   if ((readkey() & 0xFF) == 27)
      return 1;
   else
      return 0;
}



int main(int argc, char *argv[])
{
   int i;

   allegro_init();

   if (argc < 2) {
      allegro_message("Usage: 'exxfade files.[bmp|lbm|pcx|tga]'\n");
      return 1;
   }

   install_keyboard(); 

   /* set the best color depth that we can find */
   set_color_depth(16);
   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      set_color_depth(15);
      if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
	 set_color_depth(32);
	 if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
	    set_color_depth(24);
	    if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
	       set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	       allegro_message("Error setting graphics mode\n%s\n", allegro_error);
	       return 1;
	    }
	 }
      }
   }

   /* load all images in the same color depth as the display */
   set_color_conversion(COLORCONV_TOTAL);

   /* process all the files on our command line */
   for (i=1; i<argc; i++) {
      switch (show(argv[i])) {

	 case -1:
	    /* error */
	    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	    allegro_message("Error loading image file '%s'\n", argv[i]);
	    return 1;

	 case 0:
	    /* ok! */
	    break;

	 case 1:
	    /* quit */
	    allegro_exit();
	    return 0;
      }
   }

   return 0;
}

END_OF_MAIN();