6
6
7
7
#include "common.c"
8
8
9
+ /* Fire the update every 10 milliseconds. */
9
10
#define INTERVAL 0.01
10
11
11
12
@@ -15,7 +16,7 @@ float bmp_dx = 96;
15
16
float bmp_dy = 96 ;
16
17
int bmp_flag = 0 ;
17
18
18
-
19
+ /* Updates the bitmap velocity, orientation and position. */
19
20
static void update (ALLEGRO_BITMAP * bmp )
20
21
{
21
22
ALLEGRO_BITMAP * target = al_get_target_bitmap ();
@@ -67,29 +68,43 @@ int main(int argc, char **argv)
67
68
bool done = false;
68
69
bool redraw = true;
69
70
71
+ /* Silence unused arguments warnings. */
70
72
(void )argc ;
71
73
(void )argv ;
72
74
73
75
if (!al_init ()) {
74
76
abort_example ("Failed to init Allegro.\n" );
75
77
}
76
78
79
+ /* Initialize the image addon. Requires the allegro_image addon
80
+ * library.
81
+ */
77
82
if (!al_init_image_addon ()) {
78
83
abort_example ("Failed to init IIO addon.\n" );
79
84
}
80
85
86
+ /* Initialize the image font. Requires the allegro_font addon
87
+ * library.
88
+ */
81
89
al_init_font_addon ();
82
- init_platform_specific ();
90
+ init_platform_specific (); /* Helper functions from common.c. */
83
91
92
+ /* Create a new display that we can render the image to. */
84
93
display = al_create_display (640 , 480 );
85
94
if (!display ) {
86
95
abort_example ("Error creating display.\n" );
87
96
}
88
97
98
+ /* Allegro requires installing drivers for all input devices before
99
+ * they can be used.
100
+ */
89
101
if (!al_install_keyboard ()) {
90
102
abort_example ("Error installing keyboard.\n" );
91
103
}
92
104
105
+ /* Loads a font from disk. This will use al_load_bitmap_font if you
106
+ * pass the name of a known bitmap format, or else al_load_ttf_font.
107
+ */
93
108
font = al_load_font ("data/fixed_font.tga" , 0 , 0 );
94
109
if (!font ) {
95
110
abort_example ("Error loading data/fixed_font.tga\n" );
@@ -117,13 +132,17 @@ int main(int argc, char **argv)
117
132
118
133
al_start_timer (timer );
119
134
135
+ /* Default premultiplied aplha blending. */
120
136
al_set_blender (ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_INVERSE_ALPHA );
121
137
138
+ /* Primary 'game' loop. */
122
139
while (!done ) {
123
140
ALLEGRO_EVENT event ;
124
141
142
+ /* If the timer has since been fired and the queue is empty, draw.*/
125
143
if (redraw && al_is_event_queue_empty (queue )) {
126
144
update (bmp );
145
+ /* Clear so we don't get trippy artifacts left after zoom. */
127
146
al_clear_to_color (al_map_rgb_f (0 , 0 , 0 ));
128
147
al_draw_tinted_bitmap (bmp , al_map_rgba_f (1 , 1 , 1 , 0.5 ),
129
148
bmp_x , bmp_y , bmp_flag );
@@ -138,6 +157,9 @@ int main(int argc, char **argv)
138
157
if (event .keyboard .keycode == ALLEGRO_KEY_ESCAPE )
139
158
done = true;
140
159
else if (event .keyboard .keycode == ALLEGRO_KEY_SPACE ) {
160
+ /* Spacebar toggles whether render from a memory bitmap
161
+ * or display bitamp.
162
+ */
141
163
if (bmp == mem_bmp ) {
142
164
bmp = disp_bmp ;
143
165
text = "Display bitmap (space to change)" ;
0 commit comments