#include "allegro.h" int grInit(void); void wait_for_keypress(); int main(void) { int rc; int w, h, top, bot, Rwd, Rht, space, space1, space2, space3, space4; // initialize graphics rc = grInit(); // ... and check for initialization error if (rc == -1) return 1; // stuff that shows graphics... here just show a dot at 100, 100 putpixel(screen, 100, 100, 5); // show some text that we can see textout(screen, font, "Hello", 10, 20, 50); // write something in the middle of the screen textout_centre (screen, font, "center", 320, 240, 255); // try some flood filling w = SCREEN_W; h = SCREEN_H; // choose rectangle size Rwd = 20; Rht = 40; // y coord of rect tops and // y coord of rect bottoms top = h/2 - Rht/2; bot = h/2 + Rht/2; // size of space between rects space = (w - 3*Rwd)/3; // draw the three rectangles in green space1 = (int) (1.5*space + Rwd); space2 = (int) (1.5*space + 2*Rwd); space3 = (int) (2.5*space + 2*Rwd); space4 = (int) (2.5*space + 3*Rwd); rect(screen, space/2, top, space/2 + Rwd, bot, 50); rect(screen, space1, top, space2, bot, 50); rect(screen, space3, top, space4, bot, 50); // calc pt at 1,1 offset from top left of each rect; floodfill(screen, space/2 + 1, top + 1, 100); floodfill(screen, space1 + 1, top + 1, 150); floodfill(screen, space3 + 1, top + 1, 200); //return control to user wait_for_keypress(); return 0; } END_OF_MAIN(); //******************************************************************* // This initializes the graphics system. Note that it is called from // main(). You must include this in your program - but you do not // have to copy the comments. //******************************************************************* int grInit() { /* you should always do this at the start of Allegro programs */ allegro_init(); /* set up the keyboard handler */ install_keyboard(); /* set a graphics mode sized 640x480 */ if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return -1; } /* set the color palette */ set_palette(desktop_palette); /* clear the screen to white */ clear_to_color(screen, makecol(255, 255, 255)); /* you don't need to do this, but on some platforms (eg. Windows) things * will be drawn more quickly if you always acquire the screen before * trying to draw onto it. */ acquire_screen(); /* set transparent text */ text_mode(-1); return 1; } //******************************************************************* void wait_for_keypress() { /* you must always release bitmaps before calling any input functions */ release_screen(); // seems optional; slows down next operations readkey(); acquire_screen(); // but adding this speeds it up again }