1 module a5test; 2 3 pragma(lib, "dallegro5"); 4 5 version(ALLEGRO_NO_PRAGMA_LIB) 6 { 7 8 } 9 else 10 { 11 pragma(lib, "allegro"); 12 pragma(lib, "allegro_primitives"); 13 pragma(lib, "allegro_image"); 14 pragma(lib, "allegro_font"); 15 pragma(lib, "allegro_ttf"); 16 pragma(lib, "allegro_color"); 17 } 18 19 import std.stdio; 20 21 import allegro5.allegro; 22 import allegro5.allegro_primitives; 23 import allegro5.allegro_image; 24 import allegro5.allegro_font; 25 import allegro5.allegro_ttf; 26 import allegro5.allegro_color; 27 28 int main(char[][] args) 29 { 30 return al_run_allegro( 31 { 32 if (!al_init()) 33 { 34 auto ver = al_get_allegro_version(); 35 auto major = ver >> 24; 36 auto minor = (ver >> 16) & 255; 37 auto revision = (ver >> 8) & 255; 38 auto release = ver & 255; 39 40 writefln("The system Allegro version (%s.%s.%s.%s) does not match the version of this binding (%s.%s.%s.%s)", 41 major, minor, revision, release, 42 ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION, ALLEGRO_RELEASE_NUMBER); 43 return 1; 44 } 45 46 ALLEGRO_CONFIG* cfg = al_load_config_file("test.ini"); 47 version(Tango) 48 { 49 char[] arr = fromStringz(al_get_config_value(cfg, "", "name")); 50 Stdout.formatln("Entry is: {}", arr); 51 } 52 53 ALLEGRO_DISPLAY* display = al_create_display(500, 500); 54 55 ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue(); 56 57 if (!al_install_keyboard()) assert(0, "al_install_keyboard failed!"); 58 if (!al_install_mouse()) assert(0, "al_install_mouse failed!"); 59 if (!al_init_image_addon()) assert(0, "al_init_image_addon failed!"); 60 if (!al_init_font_addon()) assert(0, "al_init_font_addon failed!"); 61 if (!al_init_ttf_addon()) assert(0, "al_init_ttf_addon failed!"); 62 if (!al_init_primitives_addon()) assert(0, "al_init_primitives_addon failed!"); 63 64 al_register_event_source(queue, al_get_display_event_source(display)); 65 al_register_event_source(queue, al_get_keyboard_event_source()); 66 al_register_event_source(queue, al_get_mouse_event_source()); 67 68 ALLEGRO_BITMAP* bmp = al_load_bitmap("mysha.pcx"); 69 ALLEGRO_FONT* font = al_load_font("DejaVuSans.ttf", 18, 0); 70 71 with(ALLEGRO_BLEND_MODE) 72 { 73 al_set_blender(ALLEGRO_BLEND_OPERATIONS.ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); 74 } 75 76 auto color1 = al_color_hsl(0, 0, 0); 77 auto color2 = al_map_rgba_f(0.5, 0.25, 0.125, 1); 78 version(Tango) 79 { 80 Stdout.formatln("{}, {}, {}, {}", color1.r, color1.g, color2.b, color2.a); 81 } 82 else 83 { 84 writefln("%s, %s, %s, %s", color1.r, color1.g, color2.b, color2.a); 85 } 86 87 88 bool exit = false; 89 while(!exit) 90 { 91 ALLEGRO_EVENT event; 92 while(al_get_next_event(queue, &event)) 93 { 94 switch(event.type) 95 { 96 case ALLEGRO_EVENT_DISPLAY_CLOSE: 97 { 98 exit = true; 99 break; 100 } 101 case ALLEGRO_EVENT_KEY_DOWN: 102 { 103 switch(event.keyboard.keycode) 104 { 105 case ALLEGRO_KEY_ESCAPE: 106 { 107 exit = true; 108 break; 109 } 110 default: 111 } 112 break; 113 } 114 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: 115 { 116 exit = true; 117 break; 118 } 119 default: 120 } 121 } 122 123 al_clear_to_color(ALLEGRO_COLOR(0.5, 0.25, 0.125, 1)); 124 al_draw_bitmap(bmp, 50, 50, 0); 125 al_draw_triangle(20, 20, 300, 30, 200, 200, ALLEGRO_COLOR(1, 1, 1, 1), 4); 126 al_draw_text(font, ALLEGRO_COLOR(1, 1, 1, 1), 70, 40, ALLEGRO_ALIGN_CENTRE, "Hello!"); 127 al_flip_display(); 128 } 129 130 return 0; 131 }); 132 }