/* * Example program for the Allegro library, by Shawn Hargreaves. * * This program demonstrates how to write directly to video memory. * It implements a simple fire effect, first by calling getpixel() and * putpixel(), then by accessing video memory directly a byte at a * time, and finally using block memory copy operations. */ #include /* The fire is formed from several 'hotspots' which are moved randomly * across the bottom of the screen. */ #define FIRE_HOTSPOTS 48 int hotspot[FIRE_HOTSPOTS]; unsigned char *temp; /* This function updates the bottom line of the screen with a pattern * of varying intensities which are then moved upwards and faded out * by the code in main(). */ void draw_bottom_line_of_fire(void) { int c, c2; /* zero the buffer */ for (c=0; c= 0) && (c2 < SCREEN_W)) temp[c2] = MIN(temp[c2] + 20-ABS(hotspot[c]-c2), 192); /* move the hotspots */ hotspot[c] += (AL_RAND() & 7) - 3; if (hotspot[c] < 0) hotspot[c] += SCREEN_W; else if (hotspot[c] >= SCREEN_W) hotspot[c] -= SCREEN_W; } /* display the buffer */ for (c=0; c 0) c--; putpixel(screen, x, y, c); } } release_screen(); } clear_keybuf(); textout_ex(screen, font, "Using direct memory writes", 0, 0, makecol(255,255,255), makecol(0, 0, 0)); /* It is much faster if we access the screen memory directly. This * time we read an entire line of the screen into our own buffer, * modify it there, and then write the whole line back in one go. * That is to avoid having to keep switching back and forth between * different scanlines: if we only copied one pixel at a time, we * would have to call bmp_write_line() for every single pixel rather * than just twice per line. */ while (!keypressed()) { acquire_screen(); draw_bottom_line_of_fire(); bmp_select(screen); for (y=64; y 0) temp[x]--; /* get an address for writing line y */ address = bmp_write_line(screen, y); /* write line with farptr functions */ for (x=0; x 0) temp[x]--; /* get an address for writing line y */ address = bmp_write_line(screen, y); /* write line in 32 bit chunks */ for (x=0; x