mirror of
https://github.com/ysoftdevs/cpp-examples.git
synced 2026-01-11 14:30:32 +01:00
update Allegro example
This commit is contained in:
@@ -12,50 +12,55 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
ALLEGRO_EVENT_QUEUE *event_queue;
|
||||
ALLEGRO_DISPLAY *display;
|
||||
|
||||
ALLEGRO_EVENT event;
|
||||
ALLEGRO_BITMAP *image;
|
||||
ALLEGRO_EVENT_QUEUE *event_queue;
|
||||
ALLEGRO_DISPLAY *display;
|
||||
|
||||
ALLEGRO_EVENT event;
|
||||
ALLEGRO_BITMAP *image;
|
||||
|
||||
al_init();
|
||||
al_install_keyboard();
|
||||
al_init_image_addon();
|
||||
|
||||
display = al_create_display(640, 480);
|
||||
if (!display)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if(!al_init()) {
|
||||
fprintf(stderr, "failed to initialize allegro!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create Event queue
|
||||
display = al_create_display(640, 480);
|
||||
if (!display)
|
||||
{
|
||||
fprintf(stderr, "failed to create display!\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
al_install_keyboard();
|
||||
al_init_image_addon();
|
||||
|
||||
// Create Event queue
|
||||
event_queue = al_create_event_queue();
|
||||
|
||||
// Register Keyboard to queue
|
||||
// Register Keyboard to queue
|
||||
al_register_event_source(event_queue, al_get_keyboard_event_source());
|
||||
al_register_event_source(event_queue, al_get_display_event_source(display));
|
||||
al_register_event_source(event_queue, al_get_display_event_source(display));
|
||||
|
||||
// Clear screen
|
||||
al_clear_to_color(al_map_rgb_f(1.0, 1.0, 1.0));
|
||||
|
||||
// Load and display image
|
||||
image = al_load_bitmap("smajlik.png");
|
||||
if (image != NULL)
|
||||
{
|
||||
al_draw_bitmap(image, 10, 10, 0);
|
||||
} else {
|
||||
printf("No bitmap.\n");
|
||||
return 1;
|
||||
}
|
||||
al_flip_display();
|
||||
// Clear screen
|
||||
al_clear_to_color(al_map_rgb_f(1.0, 1.0, 1.0));
|
||||
|
||||
// Load and display image
|
||||
image = al_load_bitmap("smajlik.png");
|
||||
if (image != NULL)
|
||||
{
|
||||
al_draw_bitmap(image, 10, 10, 0);
|
||||
} else {
|
||||
printf("No bitmap.\n");
|
||||
return 1;
|
||||
}
|
||||
al_flip_display();
|
||||
|
||||
// Wait until some key is pressed
|
||||
al_wait_for_event(event_queue, &event);
|
||||
// Wait until some key is pressed
|
||||
al_wait_for_event(event_queue, &event);
|
||||
|
||||
// Release
|
||||
al_destroy_bitmap(image);
|
||||
al_uninstall_keyboard();
|
||||
al_uninstall_system();
|
||||
return 0;
|
||||
// Release
|
||||
al_destroy_bitmap(image);
|
||||
al_uninstall_keyboard();
|
||||
al_uninstall_system();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user