|
Porting a game to HTML5 |
jmasterx
Member #11,410
October 2009
|
I heard the other day that asm.js can be used to compile Allegro5 projects to HTML5 with the sdl2 backend. I'm interested in trying this. Are there any instructions, tutorials, or posts on porting one of the examples or similar to html5? Many thanks! Agui GUI API -> https://github.com/jmasterx/Agui |
Elias
Member #358
May 2000
|
Basically use the SDL2 backend, then compile with emcc instead of gcc. But it's not always straightforward and I added some stuff to my local A5 copy, mostly to support timers - emscripten has pthreads support, compiling with that gives you normal timers... but only the latest firefox supports javascript threading so it's not too useful for now. With my changed SDL driver timers work by comparing the time when al_get_next_event() is called and it works in Chrome as well. I can try and write down what I did so far tomorrow... If you search the forums, someone else did a port of Allegro to emscripten a while ago as well which may work even better than that since there is no intermediate SDL2 layer. [edit:] Ok, if you want to try it, this is the things I remember:
git clone -b emscripten https://github.com/allefant/allegro5.git
ALLEGRO_EMSCRIPTEN=ON ALLEGRO_SDL=ON SHARED=OFF WANT_MONOLITH=ON CMAKE_C_COMPILER=emcc CMAKE_CXX_COMPILER=em++ CMAKE_C_FLAGS=-s USE_ZLIB=1 -s USE_LIBPNG=1 CMAKE_INSTALL_PREFIX=/home/elias/prog/allegro/emscripten_install FREETYPE_INCLUDE_DIR_freetype2=/home/elias/stuff/emsdk_portable/freetype-2.6/include FREETYPE_INCLUDE_DIR_ft2build=/home/elias/stuff/emsdk_portable/freetype-2.6/include FREETYPE_LIBRARY=libfreetype.a
emcc -O3 examples/ex_draw_bitmap.bc lib/liballegro_monolith-static.a lib/libfreetype.a -s USE_SDL=2 -s FULL_ES2=1 -o ex_draw_bitmap.html --preload-file data -s USE_ZLIB=1 -s USE_LIBPNG=1 -s TOTAL_MEMORY=1000000000
Some issues I still have with my actual game:
-- |
|