Advertisement
tourniquet

Allegro Lesson 3

Jan 29th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. // gcc -Wall 2.c -o 2 $(pkg-config --libs allegro-5.0 allegro_image-5.0 allegro_font-5.0 allegro_ttf-5.0 allegro_dialog-5.0)
  2.  
  3. #include <allegro5/allegro.h>
  4. #include <allegro5/allegro_font.h>
  5. #include <allegro5/allegro_ttf.h>
  6. #include <allegro5/allegro_native_dialog.h>
  7.  
  8. int main() {
  9.  
  10.     ALLEGRO_DISPLAY *display = NULL;
  11.  
  12.     if(!al_init()) {
  13.         al_show_native_message_box(display, NULL, NULL, "failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_YES_NO);
  14.         return -1;
  15.     }
  16.    
  17.     display = al_create_display(640, 480);
  18.     if(!display) {
  19.         al_show_native_message_box(NULL, NULL, NULL, "failed to initialize display!", NULL, ALLEGRO_MESSAGEBOX_YES_NO);
  20.         return -1;
  21.     }
  22.  
  23.     al_init_font_addon();
  24.     al_init_ttf_addon();
  25.  
  26.     ALLEGRO_FONT *font18 = al_load_font("arial.ttf", 18, 0);
  27.    
  28.     al_clear_to_color(al_map_rgb(46, 80, 255));
  29.  
  30.     al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 50, 0, "Hello, world, this is 18 point!");
  31.  
  32.     int screen_w = al_get_display_width(display);
  33.     int screen_h = al_get_display_height(display);
  34.  
  35.     al_draw_textf(font18, al_map_rgb(255, 255, 255), screen_w/2, 400, ALLEGRO_ALIGN_CENTRE, "TEXT with variable output (textf): Screen width and height = %i / %i", screen_w, screen_h);
  36.  
  37.     al_flip_display();
  38.  
  39.     al_rest(60.0);
  40.  
  41.     al_destroy_font(font18);
  42.     al_destroy_display(display);
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement