Get Allegro up and running
#include "allegro5/allegro.h"
#include "allegro5/allegro_font.h"
int main (int argc, char *argv[])
{
al_init();
al_init_font_addon();
ALLEGRO_DISPLAY *display = al_create_display(640, 480);
ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
ALLEGRO_TIMER* timer = al_create_timer(1.0 / 30.0);
ALLEGRO_FONT* font = al_create_builtin_font();
bool running = true;
bool redraw = false;
ALLEGRO_EVENT event;
al_register_event_source(queue, al_get_display_event_source(display));
al_register_event_source(queue, al_get_timer_event_source(timer));
al_start_timer(timer);
while(running)
{
al_wait_for_event(queue, &event);
switch(event.type)
{
case ALLEGRO_EVENT_TIMER:
{
redraw = true;
break;
}
case ALLEGRO_EVENT_DISPLAY_CLOSE:
{
running = false;
break;
}
case ALLEGRO_EVENT_DISPLAY_HALT_DRAWING:
{
al_stop_timer(timer);
redraw = false;
al_acknowledge_drawing_halt(display);
break;
}
case ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING:
{
al_acknowledge_drawing_resume(display);
al_start_timer(timer);
break;
}
}
if(redraw && al_is_event_queue_empty(queue))
{
al_clear_to_color(al_map_rgb(0, 100, 0));
al_draw_text(font, al_map_rgb(255, 255, 255), 320, 240, ALLEGRO_ALIGN_CENTER, "Hello world!");
al_flip_display();
redraw = false;
}
}
// Allegro takes a second or two to close down
al_destroy_display(display);
al_destroy_event_queue(queue);
al_destroy_timer(timer);
return 0;
}