1 /*
2  *    Example program for the Allegro library, by Shawn Hargreaves.
3  *
4  *    This program demonstrates how to load and display a bitmap
5  *    file.  You have to use this example from the command line to
6  *    specify as first parameter a graphic file in one of Allegro's
7  *    supported formats.  If the file is loaded successfully,
8  *    it will be displayed until you press a key.
9  */
10 
11 
12 #include <allegro.h>
13 
14 
15 
main(int argc,char * argv[])16 int main(int argc, char *argv[])
17 {
18    BITMAP *the_image;
19    PALETTE the_palette;
20 
21    if (allegro_init() != 0)
22       return 1;
23 
24    if (argc != 2) {
25       allegro_message("Usage: 'exbitmap filename.[bmp|lbm|pcx|tga]'\n");
26       return 1;
27    }
28 
29    install_keyboard();
30 
31    if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
32       if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
33 	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
34 	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
35 	 return 1;
36       }
37    }
38 
39    /* read in the bitmap file */
40    the_image = load_bitmap(argv[1], the_palette);
41    if (!the_image) {
42       set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
43       allegro_message("Error reading bitmap file '%s'\n", argv[1]);
44       return 1;
45    }
46 
47    /* select the bitmap palette */
48    set_palette(the_palette);
49 
50    /* blit the image onto the screen */
51    blit(the_image, screen, 0, 0, (SCREEN_W-the_image->w)/2,
52 	(SCREEN_H-the_image->h)/2, the_image->w, the_image->h);
53 
54    /* destroy the bitmap */
55    destroy_bitmap(the_image);
56 
57    readkey();
58    return 0;
59 }
60 
61 END_OF_MAIN()
62