Show extruec.c syntax highlighted
/*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This program shows how to specify colors in the various different
* truecolor pixel formats.
*/
#include "allegro.h"
void test(int colordepth)
{
AL_PALETTE pal;
int x;
/* set the al_screen mode */
al_set_color_depth(colordepth);
if (al_set_gfx_mode(AL_GFX_AUTODETECT, 640, 480, 0, 0) != 0)
return;
/* in case this is a 256 color mode, we'd better make sure that the
* palette is set to something sensible. This function generates a
* standard palette with a nice range of different colors...
*/
al_generate_332_palette(pal);
al_set_palette(pal);
al_acquire_screen();
al_clear_to_color(al_screen, al_make_color(0, 0, 0));
al_text_mode(-1);
al_printf_text(al_screen, al_font_8x8, 0, 0, al_make_color(255, 255, 255), "%d bit color...", colordepth);
/* use the al_make_color() function to specify AL_RGB values... */
al_put_text(al_screen, al_font_8x8, "Red", 32, 80, al_make_color(255, 0, 0 ));
al_put_text(al_screen, al_font_8x8, "Green", 32, 100, al_make_color(0, 255, 0 ));
al_put_text(al_screen, al_font_8x8, "Blue", 32, 120, al_make_color(0, 0, 255));
al_put_text(al_screen, al_font_8x8, "Yellow", 32, 140, al_make_color(255, 255, 0 ));
al_put_text(al_screen, al_font_8x8, "Cyan", 32, 160, al_make_color(0, 255, 255));
al_put_text(al_screen, al_font_8x8, "Magenta", 32, 180, al_make_color(255, 0, 255));
al_put_text(al_screen, al_font_8x8, "Grey", 32, 200, al_make_color(128, 128, 128));
/* or we could draw some nice smooth color gradients... */
for (x=0; x<256; x++) {
al_draw_vline(al_screen, 192+x, 112, 176, al_make_color(x, 0, 0));
al_draw_vline(al_screen, 192+x, 208, 272, al_make_color(0, x, 0));
al_draw_vline(al_screen, 192+x, 304, 368, al_make_color(0, 0, x));
}
al_put_text_centre(al_screen, al_font_8x8, "<press a al_key>", AL_SCREEN_W/2, AL_SCREEN_H-16, al_make_color(255, 255, 255));
al_release_screen();
al_read_key();
}
int main()
{
allegro_init();
al_install_keyboard();
/* try each of the possible possible color depths... */
test(8);
test(15);
test(16);
test(24);
test(32);
return 0;
}
AL_END_OF_MAIN();
See more files for this project here