1#include <stdio.h>
2#include <allegro5/allegro.h>
3#include <allegro5/allegro_primitives.h>
4#include <allegro5/allegro_font.h>
5#include <allegro5/allegro_ttf.h>
6#include "some_class.h"
7
8const float FPS
= 30;
9
10int main
(int argc,
char **argv
)
11{
12 int screen_width
= 320;
13 int screen_height
= 200;
14
15 some_class
*the_class
= new some_class
(screen_width, screen_height
);
16
17 ALLEGRO_DISPLAY *display
= NULL
;
18 ALLEGRO_BITMAP *bitmap
= NULL
;
19 ALLEGRO_EVENT_QUEUE *event_queue
= NULL
;
20 ALLEGRO_TIMER *timer
= NULL
;
21 ALLEGRO_FONT *ttf_font
;
22
23 bool exit = false;
24
25 if(!al_init())
26 {
27 fprintf(stderr,
"failed to initialize allegro!\n");
28 return -1;
29 }
30
31 timer
= al_create_timer(1.
0 / FPS
);
32 if(!timer
)
33 {
34 fprintf(stderr,
"failed to create timer!\n");
35 return -1;
36 }
37
38
39
40 display
= al_create_display(screen_width, screen_height
);
41
42 if(!display
)
43 {
44 fprintf(stderr,
"failed to create display!\n");
45 al_destroy_timer(timer
);
46 return -1;
47 }
48
49 if (!al_init_primitives_addon())
50 {
51 fprintf(stderr,
"failed to initiialize primitives addon!\n");
52 return -1;
53 }
54
55 if(!al_install_keyboard())
56 {
57 fprintf(stderr,
"failed to initialize the keyboard!\n");
58 return -1;
59 }
60
61 event_queue
= al_create_event_queue();
62
63 if(!event_queue
)
64 {
65 fprintf(stderr,
"failed to create event_queue!\n");
66 al_destroy_display(display
);
67 al_destroy_timer(timer
);
68 return -1;
69 }
70
71 al_register_event_source(event_queue,
al_get_keyboard_event_source());
72 al_register_event_source(event_queue,
al_get_display_event_source(display
));
73 al_register_event_source(event_queue,
al_get_timer_event_source(timer
));
74
75 al_clear_to_color(al_map_rgb(0,
0,
0));
76
77 al_flip_display();
78 al_start_timer(timer
);
79
80 bool redraw
= true;
81
82 int SCREEN_HEIGHT_Y
;
83 int SCREEN_WIDTH_X
;
84 ALLEGRO_COLOR COLOR_WHITE
;
85 SCREEN_HEIGHT_Y
= 200;
86 SCREEN_WIDTH_X
= 320;
87 COLOR_WHITE
= al_map_rgb(255,
255,
255);
88
89 while(!exit)
90 {
91
92 ALLEGRO_EVENT ev
;
93 al_wait_for_event(event_queue,
&ev
);
94
95 if (redraw
)
96 {
97
98 //the_class->draw();
99
100 al_lock_bitmap(al_get_target_bitmap(), ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE
);
101 for(int y
= 0; y
< SCREEN_HEIGHT_Y
; y
++)
102 {
103 for(int x
= 0; x
< SCREEN_WIDTH_X
; x
++)
104 {
105 al_draw_pixel(x, y, COLOR_WHITE
);
106 }
107 }
108 al_unlock_bitmap(al_get_target_bitmap());
109
110
111 al_flip_display();
112 redraw
= false;
113 }
114 if(ev.type
== ALLEGRO_EVENT_TIMER
)
115 {
116 redraw
= true;
117 }
118 else if(ev.type
== ALLEGRO_EVENT_DISPLAY_CLOSE
)
119 {
120 exit = true;
121 break;
122 }
123 if(al_is_event_queue_empty(event_queue
))
124 {
125 if (ev.type
== ALLEGRO_EVENT_KEY_DOWN
)
126 {
127 if (ev.keyboard.keycode
== ALLEGRO_KEY_ESCAPE
)
128 {
129 exit = true;
130 break;
131 }
132 }
133 }
134 }
135
136 al_destroy_timer(timer
);
137 al_destroy_display(display
);
138 al_destroy_event_queue(event_queue
);
139
140 delete the_class
;
141
142 return 0;
143}