<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Porting a game to HTML5</title>
		<link>http://www.allegro.cc/forums/view/615677</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 24 Aug 2015 06:04:45 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I heard the other day that asm.js can be used to compile Allegro5 projects to HTML5 with the sdl2 backend.</p><p>I&#39;m interested in trying this.</p><p>Are there any instructions, tutorials, or posts on porting one of the examples or similar to html5?</p><p>Many thanks!<br />Edit, sorry for putting this in a.cc comments, meant to put it in installation.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Sat, 22 Aug 2015 19:37:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Basically use the SDL2 backend, then compile with emcc instead of gcc. But it&#39;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&#39;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...</p><p>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.</p><p>[edit:]</p><p>Ok, if you want to try it, this is the things I remember:</p><ul><li><p>Install the emscripten SDK. This is a huge task in itself, I followed <span class="ref"><sup>[<a href="#">1</a>]</sup></span> to do it.</p><br /></li><li><p>Apply this small patch to Allegro <span class="ref"><sup>[<a href="#">2</a>]</sup></span> or just do:
</p></li></ul><pre>git clone -b emscripten <a href="https://github.com/allefant/allegro5.git">https://github.com/allefant/allegro5.git</a></pre><p>

</p><ul><li><p>Install some emscripten packages through their package management system, I think I have SDL2, libpng and zlib. I also compiled freetype2 somehow but only needed if you need truetype fonts.</p><br /></li><li><p>Compile Allegro, using SDL2 and emscripten. Options I used (leave out the freetype ones if you don&#39;t have it):
</p></li></ul><pre>
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
</pre><p>

</p><ul><li><p>Compile your game. I used:
</p></li></ul><pre>
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
</pre><p>

</p><ul><li><p>Run in either Firefox or Chrome: <span class="ref"><sup>[<a href="#">3</a>]</sup></span></p></li></ul><p>Some issues I still have with my actual game:
</p><ul><li><p>Freetype2 compiled from upstream freetype sources seems to sometimes cut off parts of letters, but Google suggests there&#39;s an easy fix.
</p></li><li><p>I have no sound yet, but emscripten supports the SDL1 sound commands, it probably is very easy adapting Allegro&#39;s SDL2 sound driver to support that.
</p></li><li><p>Unless you use emscripten&#39;s pthreads support, everything using threads needs to be rewritten with polling from the main thread. Not a big issue in my case.
</p></li></ul><div class="ref-block"><h2>References</h2><ol><li><a href="http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#sdk-download-and-install">http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#sdk-download-and-install</a></li><li><a href="https://github.com/allefant/allegro5/commit/2351d027f82548787220ea6034740146ab121245">https://github.com/allefant/allegro5/commit/2351d027f82548787220ea6034740146ab121245</a></li><li><a href="http://allegro5.org/html5/ex_draw_bitmap.html">http://allegro5.org/html5/ex_draw_bitmap.html</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 24 Aug 2015 06:04:45 +0000</pubDate>
	</item>
</rss>
