aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--01-rwalk/src/main.c4
-rw-r--r--02-wolfautomata/src/main.c31
-rw-r--r--03-wolfrand/screenshot.gifbin128974 -> 101948 bytes
-rw-r--r--03-wolfrand/src/main.c34
4 files changed, 44 insertions, 25 deletions
diff --git a/01-rwalk/src/main.c b/01-rwalk/src/main.c
index 28592e4..98ede82 100644
--- a/01-rwalk/src/main.c
+++ b/01-rwalk/src/main.c
@@ -66,7 +66,7 @@ int main(int argc, char **argv)
DO_INIT(al_init_primitives_addon(), "primitives");
DO_INIT(al_install_keyboard(), "keyboard");
- DO_INIT(t = al_create_timer(1.0 / 30.0), "timer");
+ DO_INIT(t = al_create_timer(1.0 / 60.0), "timer");
DO_INIT(eq = al_create_event_queue(), "event queue");
al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE);
@@ -127,7 +127,7 @@ int main(int argc, char **argv)
break;
}
- al_draw_filled_rectangle(x, y, x + 1.0, y + 1.0, al_map_rgb(255, 255, 255));
+ al_put_pixel(x, y, al_map_rgb(255, 255, 255));
randbytes = randombytes_random();
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)
diff --git a/03-wolfrand/screenshot.gif b/03-wolfrand/screenshot.gif
index fd8ad07..f92007e 100644
--- a/03-wolfrand/screenshot.gif
+++ b/03-wolfrand/screenshot.gif
Binary files differ
diff --git a/03-wolfrand/src/main.c b/03-wolfrand/src/main.c
index 4d4fa34..5d90690 100644
--- a/03-wolfrand/src/main.c
+++ b/03-wolfrand/src/main.c
@@ -11,7 +11,7 @@
#define DISP_WIDTH 640
#define DISP_HEIGHT 480
-#define FPS 3.3
+#define FPS 15.0
#define DO_INIT(check, desc) \
if (!(check)) { \
@@ -46,9 +46,10 @@ int main(int argc, char **argv)
bool pause = 0;
- 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;
@@ -63,6 +64,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, DISP_HEIGHT), "buffer");
al_register_event_source(eq, al_get_keyboard_event_source());
al_register_event_source(eq, al_get_display_event_source(d));
@@ -126,7 +129,7 @@ int main(int argc, char **argv)
memset(bits[1], 0, (DISP_HEIGHT - 1) * DISP_WIDTH / 8);
for (x = 1; x < DISP_WIDTH - 1; x++) {
- if (randombytes_random() < 0x20000000)
+ if (randombytes_random() < 0x10000000)
bit_toggle(bits[0], x);
}
@@ -148,20 +151,23 @@ int main(int argc, char **argv)
/* draw frame */
- al_clear_to_color(al_map_rgb(0, 0, 0));
+ al_lock_bitmap(b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
+
+ al_set_target_bitmap(b);
for (y = 0; y < DISP_HEIGHT; y++) {
for (x = 0; x < DISP_WIDTH; x++) {
- if (bit_get(bits[y], x)) {
- al_draw_filled_rectangle(
- (float)x, (float)y,
- (float)(x + 1), (float)(y + 1),
- al_map_rgb(255, 255, 255)
- );
- }
+ if (bit_get(bits[y], x))
+ al_put_pixel(x, y, al_map_rgb(255, 255, 255));
+ else
+ al_put_pixel(x, y, al_map_rgb(0, 0, 0));
}
}
+ al_unlock_bitmap(b);
+
+ al_set_target_backbuffer(d);
+ al_draw_bitmap(b, 0, 0, 0);
al_flip_display();
}
}
@@ -171,6 +177,8 @@ done:
if (d)
al_destroy_display(d);
+ if (b)
+ al_destroy_bitmap(b);
if (t)
al_destroy_timer(t);
if (eq)