Skip to content

Commit 978e71f

Browse files
Daniel JohnsonSiegeLord
authored andcommitted
Added more inline documentation to ex_bitmap_flip
1 parent 0262db8 commit 978e71f

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

examples/ex_bitmap_flip.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "common.c"
88

9+
/* Fire the update every 10 milliseconds. */
910
#define INTERVAL 0.01
1011

1112

@@ -15,7 +16,7 @@ float bmp_dx = 96;
1516
float bmp_dy = 96;
1617
int bmp_flag = 0;
1718

18-
19+
/* Updates the bitmap velocity, orientation and position. */
1920
static void update(ALLEGRO_BITMAP *bmp)
2021
{
2122
ALLEGRO_BITMAP *target = al_get_target_bitmap();
@@ -67,29 +68,43 @@ int main(int argc, char **argv)
6768
bool done = false;
6869
bool redraw = true;
6970

71+
/* Silence unused arguments warnings. */
7072
(void)argc;
7173
(void)argv;
7274

7375
if (!al_init()) {
7476
abort_example("Failed to init Allegro.\n");
7577
}
7678

79+
/* Initialize the image addon. Requires the allegro_image addon
80+
* library.
81+
*/
7782
if (!al_init_image_addon()) {
7883
abort_example("Failed to init IIO addon.\n");
7984
}
8085

86+
/* Initialize the image font. Requires the allegro_font addon
87+
* library.
88+
*/
8189
al_init_font_addon();
82-
init_platform_specific();
90+
init_platform_specific(); /* Helper functions from common.c. */
8391

92+
/* Create a new display that we can render the image to. */
8493
display = al_create_display(640, 480);
8594
if (!display) {
8695
abort_example("Error creating display.\n");
8796
}
8897

98+
/* Allegro requires installing drivers for all input devices before
99+
* they can be used.
100+
*/
89101
if (!al_install_keyboard()) {
90102
abort_example("Error installing keyboard.\n");
91103
}
92104

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+
*/
93108
font = al_load_font("data/fixed_font.tga", 0, 0);
94109
if (!font) {
95110
abort_example("Error loading data/fixed_font.tga\n");
@@ -117,13 +132,17 @@ int main(int argc, char **argv)
117132

118133
al_start_timer(timer);
119134

135+
/* Default premultiplied aplha blending. */
120136
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
121137

138+
/* Primary 'game' loop. */
122139
while (!done) {
123140
ALLEGRO_EVENT event;
124141

142+
/* If the timer has since been fired and the queue is empty, draw.*/
125143
if (redraw && al_is_event_queue_empty(queue)) {
126144
update(bmp);
145+
/* Clear so we don't get trippy artifacts left after zoom. */
127146
al_clear_to_color(al_map_rgb_f(0, 0, 0));
128147
al_draw_tinted_bitmap(bmp, al_map_rgba_f(1, 1, 1, 0.5),
129148
bmp_x, bmp_y, bmp_flag);
@@ -138,6 +157,9 @@ int main(int argc, char **argv)
138157
if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
139158
done = true;
140159
else if (event.keyboard.keycode == ALLEGRO_KEY_SPACE) {
160+
/* Spacebar toggles whether render from a memory bitmap
161+
* or display bitamp.
162+
*/
141163
if (bmp == mem_bmp) {
142164
bmp = disp_bmp;
143165
text = "Display bitmap (space to change)";

0 commit comments

Comments
 (0)