Show exxfade.c syntax highlighted
/*
* 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)
{
AL_BITMAP *bmp, *buffer;
AL_PALETTE pal;
int alpha;
/* load the file */
bmp = al_load_bitmap(name, pal);
if (!bmp)
return -1;
buffer = al_create_bitmap(AL_SCREEN_W, AL_SCREEN_H);
al_blit(al_screen, buffer, 0, 0, 0, 0, AL_SCREEN_W, AL_SCREEN_H);
al_set_palette(pal);
/* fade it in on top of the previous picture */
for (alpha=0; alpha<256; alpha+=8) {
al_set_trans_blender(0, 0, 0, alpha);
al_draw_trans_sprite(buffer, bmp, (AL_SCREEN_W-bmp->w)/2, (AL_SCREEN_H-bmp->h)/2);
al_vsync();
al_blit(buffer, al_screen, 0, 0, 0, 0, AL_SCREEN_W, AL_SCREEN_H);
if (al_key_pressed()) {
al_destroy_bitmap(bmp);
al_destroy_bitmap(buffer);
if ((al_read_key() & 0xFF) == 27)
return 1;
else
return 0;
}
}
al_blit(bmp, al_screen, 0, 0, (AL_SCREEN_W-bmp->w)/2, (AL_SCREEN_H-bmp->h)/2, bmp->w, bmp->h);
al_destroy_bitmap(bmp);
al_destroy_bitmap(buffer);
if ((al_read_key() & 0xFF) == 27)
return 1;
else
return 0;
}
int main(int argc, char *argv[])
{
int i;
allegro_init();
if (argc < 2) {
al_show_message("Usage: 'exxfade files.[bmp|lbm|pcx|tga]'\n");
return 1;
}
al_install_keyboard();
/* set the best color depth that we can find */
al_set_color_depth(16);
if (al_set_gfx_mode(AL_GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
al_set_color_depth(15);
if (al_set_gfx_mode(AL_GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
al_set_color_depth(32);
if (al_set_gfx_mode(AL_GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
al_set_color_depth(24);
if (al_set_gfx_mode(AL_GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
al_show_message("Error setting graphics mode\n%s\n", al_error);
return 1;
}
}
}
}
/* load all images in the same color depth as the display */
al_set_color_conversion(AL_COLORCONV_TOTAL);
/* process all the files on our command al_draw_line */
for (i=1; i<argc; i++) {
switch (show(argv[i])) {
case -1:
/* error */
al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
al_show_message("Error loading image file '%s'\n", argv[i]);
return 1;
case 0:
/* ok! */
break;
case 1:
/* quit */
al_remove_system();
return 0;
}
}
return 0;
}
AL_END_OF_MAIN();
See more files for this project here