Advertisement
tourniquet

Allegro Lesson 2

Jan 29th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. #include <allegro5/allegro.h>
  2. #include <allegro5/allegro_font.h>
  3. #include <allegro5/allegro_ttf.h>
  4. #include <allegro5/allegro_native_dialog.h>
  5.  
  6. int main() {
  7.  
  8.     ALLEGRO_DISPLAY *display = NULL;
  9.  
  10.     if(!al_init()) {
  11.         al_show_native_message_box(display, NULL, NULL, "failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_YES_NO);
  12.         return -1;
  13.     }
  14.    
  15.     display = al_create_display(640, 480);
  16.     if(!display) {
  17.         al_show_native_message_box(NULL, NULL, NULL, "failed to initialize display!", NULL, ALLEGRO_MESSAGEBOX_YES_NO);
  18.         return -1;
  19.     }   e
  20.  
  21.     al_init_font_addon();
  22.     al_init_ttf_addon();
  23.  
  24.     ALLEGRO_FONT *font18 = al_load_font("arial.ttf", 18, 0);
  25.    
  26.     al_clear_to_color(al_map_rgb(0, 255, 0));
  27.  
  28.     al_draw_textf(font18, al_map_rgb(255, 0, 255), 50, 50, 0, "Hello, world, this is 18 point!");
  29.  
  30.     int screen_w = al_get_display_width(display);
  31.     int screen_h = al_get_display_height(display);
  32.  
  33.     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);
  34.  
  35.     al_flip_display();
  36.  
  37.     al_rest(60.0);
  38.  
  39.     al_destroy_font(font18);
  40.     al_destroy_display(display);
  41.  
  42.     return 0;
  43. }
  44.  
  45. /* http://youtu.be/3VsadOzv3lQ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement