aboutsummaryrefslogtreecommitdiffstats
path: root/02-wolfautomata/src
diff options
context:
space:
mode:
Diffstat (limited to '02-wolfautomata/src')
-rw-r--r--02-wolfautomata/src/main.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/02-wolfautomata/src/main.c b/02-wolfautomata/src/main.c
index d884280..ded18d3 100644
--- a/02-wolfautomata/src/main.c
+++ b/02-wolfautomata/src/main.c
@@ -38,9 +38,10 @@ int main(int argc, char **argv)
uint8_t automaton = 0;
unsigned x, y;
- ALLEGRO_DISPLAY* d = NULL;
- ALLEGRO_TIMER* t = NULL;
- ALLEGRO_EVENT_QUEUE* eq = NULL;
+ ALLEGRO_DISPLAY *d = NULL;
+ ALLEGRO_BITMAP *b = NULL;
+ ALLEGRO_TIMER *t = NULL;
+ ALLEGRO_EVENT_QUEUE *eq = NULL;
ALLEGRO_EVENT e;
DO_INIT(al_init(), "allegro");
@@ -52,6 +53,8 @@ int main(int argc, char **argv)
al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE);
DO_INIT(d = al_create_display(DISP_WIDTH, DISP_HEIGHT), "display");
+ al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
+ DO_INIT(b = al_create_bitmap(DISP_WIDTH, 1), "buffer");
al_register_event_source(eq, al_get_keyboard_event_source());
al_register_event_source(eq, al_get_display_event_source(d));
@@ -128,17 +131,23 @@ reset:
break;
}
+ al_lock_bitmap(b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
+
+ al_set_target_bitmap(b);
+
/* draw line */
for (x = 0; x < DISP_WIDTH; x++) {
- if (bit_get(bits[DISP_HEIGHT - goframes], x)) {
- al_draw_filled_rectangle(
- (float)x, (float)(DISP_HEIGHT - goframes),
- (float)(x + 1), (float)(DISP_HEIGHT - goframes + 1),
- al_map_rgb(255, 255, 255)
- );
- }
+ if (bit_get(bits[DISP_HEIGHT - goframes], x))
+ al_put_pixel(x, 0, al_map_rgb(255, 255, 255));
+ else
+ al_put_pixel(x, 0, al_map_rgb(0, 0, 0));
}
+ al_unlock_bitmap(b);
+
+ al_set_target_backbuffer(d);
+ al_draw_bitmap(b, 0, DISP_HEIGHT - goframes, 0);
+
al_flip_display();
goframes--;
@@ -153,6 +162,8 @@ done:
if (d)
al_destroy_display(d);
+ if (b)
+ al_destroy_bitmap(b);
if (t)
al_destroy_timer(t);
if (eq)