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