Created
April 4, 2015 19:01
-
-
Save smolt/7fa1ecfd295a6baaa8b3 to your computer and use it in GitHub Desktop.
Hints at how to use D and Allegro5 on iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/+ | |
Hints until I get more of the recipe cleaned up. This file has some image | |
and font dependencies, but you can modify to something you have locally. | |
Assumes you have allegro5 libs built for iOS and dependencies by following | |
their instructions in README_iphone.txt. Note: the Xcode project did not | |
work as-is, needs some paths fixed. Then... | |
- Clone and build ldc-iphone-dev (follow README.md at | |
https://github.com/smolt/ldc-iphone-dev) | |
- Add ldc-iphone-dev/tools to PATH, e.g. | |
PATH=~/projects/ldc-iphone-dev/tools:$PATH | |
- Make DAllegro for iOS. Note: You may have to edit base.d and change | |
ALLEGRO_WIP_VERSION to match your allegro5 source, or make sure you get | |
allegro5 source to match DAllegro. | |
git clone -b 5.1 https://github.com/SiegeLord/DAllegro5.git | |
cd DAllegro | |
iphoneos-ldc2 -w -c -oq -od=.objs-iphoneos/ allegro5/*.d allegro5/internal/*.d | |
ar -r libdallegro5-iphoneos.a .objs-iphoneos/*.o | |
- Compile this file dtest.d with something like: | |
iphoneos-ldc2 -c -IDAllegro5 dtest.d | |
- Use helloD Xcode project in ldc-iphone-dev as example or starting point | |
and add allegro5 libs and deps from allegro iphoneos README_iphone.txt | |
instructions, libdallegro5-iphoneos.a, and dtest.o. | |
- Build and run. | |
+/ | |
module dtest; | |
import allegro5.allegro; | |
//import allegro5.allegro_primitives; | |
import allegro5.allegro_image; | |
import allegro5.allegro_font; | |
import allegro5.allegro_ttf; | |
//import allegro5.allegro_color; | |
import std.stdio; | |
import std.string; | |
import std.datetime; | |
import core.memory; | |
version (IPhoneOS) | |
{ | |
extern (C) int _al_mangled_main(int, char**) | |
{ | |
import core.runtime: Runtime; | |
Runtime.initialize(); | |
int r = dtest(); | |
// normal iOS apps never return, but just to be complete... | |
Runtime.terminate(); | |
return r; | |
} | |
} | |
else | |
{ | |
// Normal DAllegro entry point | |
int main() | |
{ | |
return al_run_allegro({return dtest();}); | |
} | |
} | |
int dtest() | |
{ | |
writeln("Starting"); | |
if (!al_init()) { | |
stderr.writeln("Sorry, failed to al_init()"); | |
return 1; | |
} | |
al_init_image_addon(); | |
al_init_font_addon(); | |
al_init_ttf_addon(); | |
//Change working directory to location of resources | |
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); | |
al_append_path_component(path, "res"); | |
al_change_directory(al_path_cstr(path, '/')); | |
al_destroy_path(path); | |
version (IPhoneOS) { | |
ALLEGRO_BITMAP* ink = al_load_bitmap("ink.png"); | |
//ALLEGRO_BITMAP* pencil = al_load_bitmap("pencil.png"); | |
ALLEGRO_FONT* verdana = al_load_ttf_font("verdana.ttf", 24, 0); | |
} | |
else { | |
ALLEGRO_BITMAP* ink = al_load_bitmap("img/ink.png"); | |
//ALLEGRO_BITMAP* pencil = al_load_bitmap("img/pencil.png"); | |
ALLEGRO_FONT* verdana = al_load_ttf_font("fnt/verdana.ttf", 24, 0); | |
} | |
ALLEGRO_DISPLAY* display = al_create_display(800, 600); | |
ALLEGRO_COLOR black = al_map_rgba(0, 0, 0, 255); | |
ALLEGRO_COLOR red = al_map_rgba(255, 0, 0, 255); | |
ALLEGRO_EVENT_QUEUE* eq = al_create_event_queue(); | |
ALLEGRO_EVENT event; | |
//Prepare to receive exit events | |
al_register_event_source(eq, al_get_display_event_source(display)); | |
bool exit = false; | |
//Prepare to receive mouse events | |
// TODO: Do I need this | |
al_install_mouse(); | |
version (IPhoneOS) { | |
al_install_touch_input(); | |
with (ALLEGRO_MOUSE_EMULATION_MODE) { | |
//al_set_mouse_emulation_mode(ALLEGRO_MOUSE_EMULATION_5_0_x); | |
al_set_mouse_emulation_mode(ALLEGRO_MOUSE_EMULATION_TRANSPARENT); | |
} | |
al_register_event_source(eq, al_get_touch_input_mouse_emulation_event_source()); | |
//al_register_event_source(eq, al_get_touch_input_event_source()); | |
} | |
else { | |
al_register_event_source(eq, al_get_mouse_event_source()); | |
} | |
int mx = 0, my = 0; | |
const(char)* msg = "Whee!".ptr; | |
//Prepare to receive joystick events | |
//al_install_joystick(); | |
//al_register_event_source(eq, al_get_joystick_event_source()); | |
while (!exit) { | |
//GC.collect(); | |
auto timestr = Clock.currTime.toISOExtString(); | |
al_clear_to_color(black); | |
al_draw_bitmap(ink, 0, 0, 0); | |
//al_draw_scaled_bitmap(pencil, 0, 0, 3124, 2248, 100, 100, 400, 250, 0); | |
al_draw_text(verdana, red, 0, 400, 0, timestr.toStringz); | |
al_draw_text(verdana, red, mx + 15, my, 0, msg); | |
al_flip_display(); | |
al_wait_for_event(eq, &event); | |
if (event.type == ALLEGRO_EVENT_MOUSE_AXES || | |
event.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY){ | |
mx = event.mouse.x; | |
my = event.mouse.y; | |
} | |
else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN){ | |
msg = "Boop!"; | |
writeln("Down"); | |
} | |
else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP){ | |
msg = "Whee!"; | |
writeln("Up"); | |
} | |
else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE){ | |
exit = true; | |
} | |
} | |
al_destroy_event_queue(eq); | |
al_destroy_bitmap(ink); | |
//al_destroy_bitmap(pencil); | |
al_destroy_font(verdana); | |
al_destroy_display(display); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment