1 /*
2  *    Example program for the Allegro library, by Shawn Hargreaves.
3  *
4  *    This program shows how to specify colors in the various different
5  *    truecolor pixel formats. The example shows the same screen (a few
6  *    text lines and three coloured gradients) in all the color depth
7  *    modes supported by your video card. The more color depth you have,
8  *    the less banding you will see in the gradients.
9  */
10 
11 
12 #include <allegro.h>
13 
14 
15 
test(int colordepth)16 void test(int colordepth)
17 {
18    PALETTE pal;
19    int x;
20 
21    /* set the screen mode */
22    set_color_depth(colordepth);
23 
24    if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0)
25       return;
26 
27    /* in case this is a 256 color mode, we'd better make sure that the
28     * palette is set to something sensible. This function generates a
29     * standard palette with a nice range of different colors...
30     */
31    generate_332_palette(pal);
32    set_palette(pal);
33 
34    acquire_screen();
35 
36    clear_to_color(screen, makecol(0, 0, 0));
37 
38    textprintf_ex(screen, font, 0, 0, makecol(255, 255, 255), -1,
39 		 "%d bit color...", colordepth);
40 
41    /* use the makecol() function to specify RGB values... */
42    textout_ex(screen, font, "Red",     32, 80,  makecol(255, 0,   0  ), -1);
43    textout_ex(screen, font, "Green",   32, 100, makecol(0,   255, 0  ), -1);
44    textout_ex(screen, font, "Blue",    32, 120, makecol(0,   0,   255), -1);
45    textout_ex(screen, font, "Yellow",  32, 140, makecol(255, 255, 0  ), -1);
46    textout_ex(screen, font, "Cyan",    32, 160, makecol(0,   255, 255), -1);
47    textout_ex(screen, font, "Magenta", 32, 180, makecol(255, 0,   255), -1);
48    textout_ex(screen, font, "Grey",    32, 200, makecol(128, 128, 128), -1);
49 
50    /* or we could draw some nice smooth color gradients... */
51    for (x=0; x<256; x++) {
52       vline(screen, 192+x, 112, 176, makecol(x, 0, 0));
53       vline(screen, 192+x, 208, 272, makecol(0, x, 0));
54       vline(screen, 192+x, 304, 368, makecol(0, 0, x));
55    }
56 
57    textout_centre_ex(screen, font, "<press a key>", SCREEN_W/2, SCREEN_H-16,
58 		     makecol(255, 255, 255), -1);
59 
60    release_screen();
61 
62    readkey();
63 }
64 
65 
66 
main(void)67 int main(void)
68 {
69    if (allegro_init() != 0)
70       return 1;
71    install_keyboard();
72 
73    /* try each of the possible possible color depths... */
74    test(8);
75    test(15);
76    test(16);
77    test(24);
78    test(32);
79 
80    return 0;
81 }
82 
83 END_OF_MAIN()
84