Урок 6. Часть 1. Таймеры. Allegro


Исходный код:
#define ALLEGRO_STATICLINK

#include <allegro5\allegro.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>

int main()
{
int width = 640;
int height = 480;
bool user_exit = false;
int count = 0;

int FPS = 10;

ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;

if(!al_init()) //Инициализация Аллегро
return -1;

display = al_create_display(width, height); //Создание дисплея

if(!display) //Проверка дисплея
return -1;

al_init_font_addon();
al_init_ttf_addon();

ALLEGRO_FONT *font = al_load_font("Resources/arial.ttf", 20, 0);

timer = al_create_timer(1.0 / FPS);
event_queue = al_create_event_queue();

al_register_event_source(event_queue, al_get_timer_event_source(timer));

al_start_timer(timer);

while(!user_exit)
{
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);

count++;

al_draw_textf(font, al_map_rgb(255, 255, 255), width / 2, height / 2, ALLEGRO_ALIGN_CENTRE,
"Frames: %i", count);

al_flip_display();
al_clear_to_color(al_map_rgb(0, 0, 0));
}

al_destroy_display(display); //Удаление дисплея
al_destroy_event_queue(event_queue);
al_destroy_timer(timer);
return 0;
}


Комментариев нет:

Отправить комментарий