Show exdata.c syntax highlighted
/*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This program demonstrates how to access the contents of an
* Allegro datafile (created by the grabber utility).
*/
#include "allegro.h"
/* the grabber produces this header, which contains defines for the names
* of all the objects in the datafile (BIG_FONT, SILLY_BITMAP, etc).
*/
#include "example.h"
int main(int argc, char *argv[])
{
AL_DATAFILE *datafile;
char buf[256];
allegro_init();
al_install_keyboard();
if (al_set_gfx_mode(AL_GFX_SAFE, 320, 200, 0, 0) != 0) {
al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
al_show_message("Unable to set any graphic mode\n%s\n", al_error);
return 1;
}
/* we still don't have a palette => Don't let Allegro twist colors */
al_set_color_conversion(AL_COLORCONV_NONE);
/* load the datafile into memory */
al_replace_filename(buf, argv[0], "example.dat", sizeof(buf));
datafile = al_load_datafile(buf);
if (!datafile) {
al_set_gfx_mode(AL_GFX_NONE, 0, 0, 0, 0);
al_show_message("Error loading %s!\n", buf);
return 1;
}
/* select the palette which was loaded from the datafile */
al_set_palette(datafile[THE_PALETTE].dat);
/* aha, set a palette and let Allegro convert colors when blitting */
al_set_color_conversion(AL_COLORCONV_TOTAL);
/* display the bitmap from the datafile */
al_put_text(al_screen, al_font_8x8, "This is the bitmap:", 32, 16, al_make_color(255, 255, 255));
al_blit(datafile[SILLY_BITMAP].dat, al_screen, 0, 0, 64, 32, 64, 64);
/* and use the al_font_8x8 from the datafile */
al_put_text(al_screen, datafile[BIG_FONT].dat, "And this is a big al_font_8x8!", 32, 128,
al_make_color(0, 255, 0));
al_read_key();
/* unload the datafile when we are finished with it */
al_destroy_datafile(datafile);
return 0;
}
AL_END_OF_MAIN();
See more files for this project here