<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MikeCann.co.ukMikeCann.co.uk - mikey see, mikey do!</title>
	<atom:link href="http://mikecann.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikecann.co.uk</link>
	<description>mikey see, mikey do!</description>
	<lastBuildDate>Sat, 28 Jan 2012 13:10:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Homebrewin&#8217; Tip</title>
		<link>http://mikecann.co.uk/misc/homebrewin-tip/</link>
		<comments>http://mikecann.co.uk/misc/homebrewin-tip/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 13:08:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1848</guid>
		<description><![CDATA[This post is a little off the normal beaten track for my blog. I have been so super busy of late on a project that I havent really had any time for technical personal projects. I have however had time to do a little home-brewing so I thought I would share a little tip I had picked [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2012/01/head.jpg"><img class="size-full wp-image-1849 alignnone" title="head" src="http://mikecann.co.uk/wp-content/uploads/2012/01/head.jpg" alt="" width="700" height="451" /></a></p>
<p>This post is a little off the normal beaten track for my blog. I have been so super busy of late on a project that I havent really had any time for technical personal projects.</p>
<p>I have however had time to do a little home-brewing so I thought I would share a little tip I had picked up. A little white back a friend lent me his kit for homebrewing. Its so simple all you have to do is fill a two litre bottle with juice and sugar, add a little yeast and cap it off with a simple valve-cap. Leave it for a few weeks and you have a &#8216;tastey&#8217; strong beverage.</p>
<p>The problem however is knowing how long to leave it. The instructions say 2-3weeks but that is heavily dependant on a number of factors such as the ambient temperature of the room. At first what I was doing was putting the juice, yeast and sugar in at the same time then giving it a good shake so all the sugar was disolved.</p>
<p>I have discovered a better way of doing things however. If you put the sugar in the bottom then put the yeast on top then gently pour in the juice over it then you get a rough indicator of when the fermentation process has completed. As the yeast grows and respirates it burns its way down through the sugar slowly converting the sucrose to alcohol. What this results in is a slowly shifting yeast layer as it works it way down. When the layer hits the bottom, no more sugar left and the brew is ready for drinking <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/misc/homebrewin-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Cleaning &amp; Updated Bio</title>
		<link>http://mikecann.co.uk/photos-personal/spring-cleaning-updated-bio/</link>
		<comments>http://mikecann.co.uk/photos-personal/spring-cleaning-updated-bio/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 16:24:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Photos & Personal]]></category>
		<category><![CDATA[Websites]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1842</guid>
		<description><![CDATA[I have been meaning to do this for a while, but never gotten round to it. Well more precisely other projects have always been more interesting so I pursued those instead This Christmas however I decided it was about time that I finally did it. Anyways I have finally given my bio on the About page abit of a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://mikecann.co.uk/wp-content/uploads/2007/09/about01.png" alt="" width="700" height="400" /></p>
<p>I have been meaning to do this for a while, but never gotten round to it. Well more precisely other projects have always been more interesting so I pursued those instead <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  This Christmas however I decided it was about time that I finally did it.</p>
<p>Anyways I have finally given my bio on the <a href="http://mikecann.co.uk/about-2/">About</a> page abit of a spit shine. I originally wrote it based on my CV a long time ago and thought it deserved a little bit of love considering that it gets quite a few hits. Its all written in the third person, im not entirely sure why I decided to do it like that originally, oh well.</p>
<p>I have also rearranged some of my earlier work so best to give the archive a more accurate timeline.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/photos-personal/spring-cleaning-updated-bio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hxaria, Infinite Terrain [HaXe, WebGL,dat.GUI]</title>
		<link>http://mikecann.co.uk/personal-project/hxaria-infinite-terrain-haxe-webgldat-gui/</link>
		<comments>http://mikecann.co.uk/personal-project/hxaria-infinite-terrain-haxe-webgldat-gui/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 14:19:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[GLSL]]></category>
		<category><![CDATA[HaXe]]></category>
		<category><![CDATA[Hxaria]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Experiment]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[Particles]]></category>
		<category><![CDATA[terraria]]></category>
		<category><![CDATA[tilemaps]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1790</guid>
		<description><![CDATA[So I have been working on my &#8220;Terraria like Terrain&#8221; project &#8220;Hxaria&#8221; again. Following on from the last post, I have now made it so that each particle can have its texture changed. This completes the functionality required to render each tile as a point sprite, as talked about in my previous post. The way [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/header.jpg"><img class="alignnone size-full wp-image-1792" title="header" src="http://mikecann.co.uk/wp-content/uploads/2011/11/header.jpg" alt="" width="700" height="416" /></a></p>
<p>So I have been working on my &#8220;<a href="http://mikecann.co.uk/personal-project/hxaria-terraria-like-terrain-in-haxe-and-webgl/">Terraria like Terrain</a>&#8221; project &#8220;Hxaria&#8221; again.</p>
<p>Following on from the last post, I have now made it so that each particle can have its texture changed. This completes the functionality required to render each tile as a point sprite, as talked about in my<a href="http://mikecann.co.uk/personal-project/hxaria-terraria-like-terrain-in-haxe-and-webgl/"> previous post</a>.</p>
<p>The way it works is that the entire world is recorded in a 2&#215;2 array Tilemap. This 2&#215;2 array holds a single Tile object for every single tile in the world:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">class</span> Tile</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw2">var</span> <span class="kw7">x</span> <span class="sy0">:</span> Int<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw2">var</span> <span class="kw7">y</span> <span class="sy0">:</span> Int<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw2">var</span> <span class="kw7">type</span> <span class="sy0">:</span> Int<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw1">new</span><span class="br0">&#40;</span><span class="kw7">x</span><span class="sy0">:</span>Int<span class="sy0">,</span> <span class="kw7">y</span><span class="sy0">:</span>Int<span class="sy0">,</span> <span class="kw7">type</span><span class="sy0">:</span>Int<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">this</span><span class="sy0">.</span><span class="kw7">x</span> = <span class="kw7">x</span><span class="sy0">;</span> <span class="kw1">this</span><span class="sy0">.</span><span class="kw7">y</span> = <span class="kw7">y</span><span class="sy0">;</span> <span class="kw1">this</span><span class="sy0">.</span><span class="kw7">type</span> = <span class="kw7">type</span><span class="sy0">;</span> <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>&nbsp;</p>
<p>When the TileRenderer needs to render it asks this Tilemap for a Tile that represents that screen coordinate, the Tilemap then offsets the position due to the camera movement and returns a tile. So it looks something like:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/tm.png"><img class="alignnone size-full wp-image-1795" title="tm" src="http://mikecann.co.uk/wp-content/uploads/2011/11/tm.png" alt="" width="600" height="357" /></a></p>
<p>The tile type is then passed to the shader in attribute buffers per point sprite / tile along with all the tiles which are stored on a single texture:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/tilescompressed.png"><img class="alignnone size-full wp-image-1803" title="tilescompressed" src="http://mikecann.co.uk/wp-content/uploads/2011/11/tilescompressed.png" alt="" width="256" height="352" /></a></p>
<p>The shader then performs the neccessary calculations to work out what the UV coordinate in the texture. The Vertex Shader:</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="glsl" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> amplitude<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> tileSize<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> texTilesWide<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> texTilesHigh<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> invTexTilesWide<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> invTexTilesHigh<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">attribute</span> <span class="kw3">float</span> size<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">attribute</span> <span class="kw3">vec3</span> customColor<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">attribute</span> <span class="kw3">float</span> tileType<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">varying</span> <span class="kw3">vec3</span> vColor<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">varying</span> <span class="kw3">vec2</span> vTilePos<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw3">void</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	vColor <span class="sy0">=</span> customColor<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw3">float</span> t <span class="sy0">=</span> <span class="kw5">floor</span><span class="br0">&#40;</span>tileType<span class="sy0">/</span>texTilesWide<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	vTilePos <span class="sy0">=</span> <span class="kw3">vec2</span><span class="br0">&#40;</span>tileType<span class="sy0">-</span><span class="br0">&#40;</span>t<span class="sy0">*</span>texTilesWide<span class="br0">&#41;</span><span class="sy0">,</span> t<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// +(.5/tileSize)</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw6">gl_PointSize</span> <span class="sy0">=</span> size<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw6">gl_Position</span> <span class="sy0">=</span> projectionMatrix <span class="sy0">*</span> modelViewMatrix <span class="sy0">*</span> <span class="kw3">vec4</span><span class="br0">&#40;</span> position<span class="sy0">,</span> 1<span class="sy0">.</span>0 <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>&nbsp;</p>
<p>And the Fragment Shader:</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="glsl" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">vec3</span> color<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">sampler2D</span> texture<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> invTexTilesWide<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">uniform</span> <span class="kw3">float</span> invTexTilesHigh<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">varying</span> <span class="kw3">vec3</span> vColor<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw2">varying</span> <span class="kw3">vec2</span> vTilePos<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw3">void</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw3">vec2</span> uv <span class="sy0">=</span> <span class="kw3">vec2</span><span class="br0">&#40;</span> <span class="kw6">gl_PointCoord</span><span class="sy0">.</span><span class="me1">x</span><span class="sy0">*</span>invTexTilesWide <span class="sy0">+</span> invTexTilesWide<span class="sy0">*</span>vTilePos<span class="sy0">.</span><span class="me1">x</span><span class="sy0">,</span> <span class="kw6">gl_PointCoord</span><span class="sy0">.</span><span class="me1">y</span><span class="sy0">*</span>invTexTilesHigh <span class="sy0">+</span> invTexTilesHigh<span class="sy0">*</span>vTilePos<span class="sy0">.</span><span class="me1">y</span><span class="br0">&#41;</span><span class="sy0">;</span>	</div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw6">gl_FragColor</span> <span class="sy0">=</span> <span class="kw5">texture2D</span><span class="br0">&#40;</span> texture<span class="sy0">,</span> uv <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>So it works in a way very much like a raster engine. You only have to render as many particles as the screen can contain.</p>
<p>If the screen area moves beyond the extent of the Tilemap then more tiles are randomly generated:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/22222.png"><img class="alignnone size-full wp-image-1796" title="22222" src="http://mikecann.co.uk/wp-content/uploads/2011/11/22222.png" alt="" width="515" height="335" /></a></p>
<p>The new tiles are randomly selected from 4 different types, Dirt, Gold, Diamonds and Rock. I have added some controls to the demo that allow you to tweak these values to demonstrate the random tile generation:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/Shot_041.png"><img class="alignnone size-full wp-image-1797" title="Shot_04" src="http://mikecann.co.uk/wp-content/uploads/2011/11/Shot_041.png" alt="" width="254" height="168" /></a></p>
<p>The UI may look familiar to people that have seen any experiments anyone who has worked with Three.js before, its the very popular <a href="http://code.google.com/p/dat-gui/">dat.GUI</a>. Its a really simple library written in javascript for creating controls that can be used to tweak experiments, perfect for me!</p>
<p>To get dat.GUI to work with haxe, I used the awesome <a href="http://www.google.co.uk/url?sa=t&amp;rct=j&amp;q=haxe%20externs&amp;source=web&amp;cd=1&amp;ved=0CBwQFjAA&amp;url=http%3A%2F%2Fhaxe.org%2Fdoc%2Fjs%2Fexterns&amp;ei=Gu_QTvK8IYP4sgbo15TzDA&amp;usg=AFQjCNEQvrXVfGjjQNO-yHhZ6HRTKlcmYw">Extern feature of HaXe</a>. This means that all I have to do is provide a stub interface to dat.GUI rather than a full implementation in haXe. This is great as it allows me to rapidly begin to use the library but also have the type safety of HaXe. It didnt take long to stub out the bits of the library I needed in an extern:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">package</span> dat<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/**</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* ...</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* @author Mike Cann</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">extern <span class="kw4">class</span> GUI</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw1">new</span><span class="br0">&#40;</span>options<span class="sy0">:</span>Dynamic<span class="br0">&#41;</span> <span class="sy0">:</span> Void<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw7">add</span><span class="br0">&#40;</span>options<span class="sy0">:</span>Dynamic<span class="sy0">,</span> <span class="kw7">name</span><span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw7">name</span><span class="br0">&#40;</span><span class="kw7">value</span><span class="sy0">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span class="kw5">String</span></a><span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw7">min</span><span class="br0">&#40;</span><span class="kw7">value</span><span class="sy0">:</span>Float<span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw7">max</span><span class="br0">&#40;</span><span class="kw7">value</span><span class="sy0">:</span>Float<span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> step<span class="br0">&#40;</span><span class="kw7">value</span><span class="sy0">:</span>Float<span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> onFinishChange<span class="br0">&#40;</span>f<span class="sy0">:</span>Void <span class="sy0">-&gt;</span> Void<span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> listen<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">:</span> GUI<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>Then I used it like:</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><span class="kw4">package</span> <span class="sy0">;</span>
<span class="kw1">import</span> dat<span class="sy0">.</span>GUI<span class="sy0">;</span>
&nbsp;
<span class="coMULTI">/**
 * ...
 * @author
 */</span>
&nbsp;
<span class="kw4">class</span> GUIManager
<span class="br0">&#123;</span>
	<span class="kw1">public</span> <span class="kw2">var</span> goldChance <span class="sy0">:</span> Float<span class="sy0">;</span>
	<span class="kw1">public</span> <span class="kw2">var</span> rockChance <span class="sy0">:</span> Float<span class="sy0">;</span>
	<span class="kw1">public</span> <span class="kw2">var</span> diamondsChance <span class="sy0">:</span> Float<span class="sy0">;</span>
	<span class="kw1">public</span> <span class="kw2">var</span> mapWidth <span class="sy0">:</span> Int<span class="sy0">;</span>
	<span class="kw1">public</span> <span class="kw2">var</span> mapHeight <span class="sy0">:</span> Int<span class="sy0">;</span>
&nbsp;
	<span class="kw1">private</span> <span class="kw2">var</span> gui <span class="sy0">:</span> GUI<span class="sy0">;</span>
	<span class="kw1">private</span> <span class="kw2">var</span> game <span class="sy0">:</span> Game<span class="sy0">;</span>
&nbsp;
	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw1">new</span><span class="br0">&#40;</span>game<span class="sy0">:</span>Game<span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="kw1">this</span><span class="sy0">.</span>game = game<span class="sy0">;</span>
&nbsp;
		gui = <span class="kw1">new</span> GUI<span class="br0">&#40;</span> <span class="br0">&#123;</span> <span class="kw7">height</span> <span class="sy0">:</span> 5 <span class="sy0">*</span> 32 <span class="sy0">-</span> 1 <span class="br0">&#125;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
		goldChance = game<span class="sy0">.</span>tilemap<span class="sy0">.</span>goldSpawnChance<span class="sy0">;</span>
		rockChance = game<span class="sy0">.</span>tilemap<span class="sy0">.</span>rockSpawnChance<span class="sy0">;</span>
		diamondsChance = game<span class="sy0">.</span>tilemap<span class="sy0">.</span>diamondsSpawnChance<span class="sy0">;</span>
		game<span class="sy0">.</span>tilemap<span class="sy0">.</span>mapResized = onTilemapResized<span class="sy0">;</span>
		mapWidth = <span class="nu0">0</span><span class="sy0">;</span>
		mapHeight = <span class="nu0">0</span><span class="sy0">;</span>
&nbsp;
		gui<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> <span class="st0">'goldChance'</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">name</span><span class="br0">&#40;</span><span class="st0">&quot;Gold&quot;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">min</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">max</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">.</span>step<span class="br0">&#40;</span>0<span class="sy0">.</span>001<span class="br0">&#41;</span><span class="sy0">.</span>onFinishChange<span class="br0">&#40;</span><span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> game<span class="sy0">.</span>tilemap<span class="sy0">.</span>goldSpawnChance = goldChance<span class="sy0">;</span> <span class="br0">&#125;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
		gui<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> <span class="st0">'rockChance'</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">name</span><span class="br0">&#40;</span><span class="st0">&quot;Rock&quot;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">min</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">max</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">.</span>step<span class="br0">&#40;</span>0<span class="sy0">.</span>001<span class="br0">&#41;</span><span class="sy0">.</span>onFinishChange<span class="br0">&#40;</span><span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> game<span class="sy0">.</span>tilemap<span class="sy0">.</span>rockSpawnChance = rockChance<span class="sy0">;</span> <span class="br0">&#125;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
		gui<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> <span class="st0">'diamondsChance'</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">name</span><span class="br0">&#40;</span><span class="st0">&quot;Diamond&quot;</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">min</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span><span class="sy0">.</span><span class="kw7">max</span><span class="br0">&#40;</span>1<span class="br0">&#41;</span><span class="sy0">.</span>step<span class="br0">&#40;</span>0<span class="sy0">.</span>001<span class="br0">&#41;</span><span class="sy0">.</span>onFinishChange<span class="br0">&#40;</span><span class="kw3">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> game<span class="sy0">.</span>tilemap<span class="sy0">.</span>diamondsSpawnChance = diamondsChance<span class="sy0">;</span> <span class="br0">&#125;</span> <span class="br0">&#41;</span><span class="sy0">;</span>
		gui<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> <span class="st0">'mapWidth'</span><span class="br0">&#41;</span><span class="sy0">.</span>listen<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
		gui<span class="sy0">.</span><span class="kw7">add</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="sy0">,</span> <span class="st0">'mapHeight'</span><span class="br0">&#41;</span><span class="sy0">.</span>listen<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">private</span> <span class="kw3">function</span> onTilemapResized<span class="br0">&#40;</span>mapW<span class="sy0">:</span>Int<span class="sy0">,</span> mapH<span class="sy0">:</span>Int<span class="br0">&#41;</span><span class="sy0">:</span>Void
	<span class="br0">&#123;</span>
		mapWidth = mapW<span class="sy0">;</span>
		mapHeight = mapH<span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>Simples!</p>
<p>Anyways you can check the final result out on this page: <a href="http://mikecann.co.uk/projects/hxaria/02/">http://mikecann.co.uk/projects/hxaria/02/<br />
</a>(Click and drag to move the camera about)</p>
<p>I have also uploaded a quick video too:</p>
<p><iframe width="650" height="471" src="http://www.youtube.com/embed/Hw1bntVoNmU?hd=1" frameborder="0" allowfullscreen></iframe></p>
<p>I have also uploaded the source again to my github page: <a href="https://github.com/mikecann/Hxaria">https://github.com/mikecann/Hxaria</a><br />
(I have also created a tag, incase the source changes in the future)</p>
<p>Next up, lighting!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/hxaria-infinite-terrain-haxe-webgldat-gui/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>New Blog Host &amp; Face-lift</title>
		<link>http://mikecann.co.uk/misc/new-blog-host-face-lift/</link>
		<comments>http://mikecann.co.uk/misc/new-blog-host-face-lift/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 15:48:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[strato]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1783</guid>
		<description><![CDATA[Just a quick post to say I have finally moved away from my old hosting on WebFusion and now im on the cheaper (and hopefully) more reliable hosting by STRATO. Its the first time I have had hosting on a windows machine and I must say I really like it. I feel much more at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/mememe.jpg"><img class="alignnone size-full wp-image-1784" title="mememe" src="http://mikecann.co.uk/wp-content/uploads/2011/11/mememe.jpg" alt="" width="700" height="400" /></a><br />
Just a quick post to say I have finally moved away from my old hosting on WebFusion and now im on the cheaper (and hopefully) more reliable hosting by <a href="http://www.strato-hosting.co.uk/">STRATO</a>.</p>
<p>Its the first time I have had hosting on a windows machine and I must say I really like it. I feel much more at home on a windows machine, I know where everything is and im more familiar in a graphical OS. I had a couple of permissions problems related to uploading new images on wordpress but a quick Google turned up this post:</p>
<p><a href="http://wordpress.org/support/topic/weird-permissions-with-iis7-and-uploaded-images">http://wordpress.org/support/topic/weird-permissions-with-iis7-and-uploaded-images</a></p>
<p>Apparently WordPress sticks new uploads in the c:\windows\temp directory, before it moves them to the usual \wp-content\ folder, so you have to ensure that temporary folder has the correct permissions for IIS_IUSRS too else it wont work correctly when the file is moved to the content folder.</p>
<p>You may also notice that I have decided to give the blog a little face-lift too with a new theme. I decided this time to go for a paid theme, as they aren&#8217;t that expensive (compared to hosting costs) and the quality and customization with paid themes are go much better than their free counterparts. I found it on the excellent <a href="http://themeforest.net/">themeforest</a> site, the theme is called <a href="http://themeforest.net/item/pixelpower-responsive-html5css3-wordpress-theme/705136">PixelPower</a>.</p>
<p>Anyways if you find any broken links or anything off with the site then let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/misc/new-blog-host-face-lift/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hxaria, Terraria like terrain in HaXe and WebGL</title>
		<link>http://mikecann.co.uk/personal-project/hxaria-terraria-like-terrain-in-haxe-and-webgl/</link>
		<comments>http://mikecann.co.uk/personal-project/hxaria-terraria-like-terrain-in-haxe-and-webgl/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 19:32:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HaXe]]></category>
		<category><![CDATA[Hxaria]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1726</guid>
		<description><![CDATA[I woke up the other day thinking about Terraria. No idea why as I haven&#8217;t played it in ages, but its the type of game I really enjoy so it must have snuck into my dreams during the night. Anyways, it got my thinking if it would be possible to make something similar to it in the browser using [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/head2.jpg"><img class="size-full wp-image-1728 alignnone" title="head2" src="http://mikecann.co.uk/wp-content/uploads/2011/11/head2.jpg" alt="" width="700" height="400" /></a></p>
<p>I woke up the other day thinking about Terraria. No idea why as I haven&#8217;t played it in ages, but its the type of game I really enjoy so it must have snuck into my dreams during the night.</p>
<p>Anyways, it got my thinking if it would be possible to make something similar to it in the browser using WebGL. For those not aware of Terraria, it looks something like this:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/screen01.jpg"><img class="alignnone size-full wp-image-1729" title="screen01" src="http://mikecann.co.uk/wp-content/uploads/2011/11/screen01.jpg" alt="" width="600" height="500" /></a></p>
<p>To produce the above you need several layers of tilemaps (background, water, foreground etc) that can potentially change every single frame (due to lighting environment effects etc). To do that at 1680&#215;1050 at 16&#215;16 per tile with only one layer changing each frame will be 6800 tile draws per frame.</p>
<p>Having calculated that I got thinking about the best way to render lots of tiles.</p>
<p>My first thought was to render each tile as a separate quad. That would certainty work, however it would mean that for each tile I would need 4 vertices, times that by say 4 layers that&#8217;s 108,800 vertices. Its not a massive massive amount but sizable enough for me to wonder if there was a more efficient way.</p>
<p>My next thought was that I could share vertices by using vertex indices in a triangle-strip, that way at best each tile will only require just over one vertex per tile then arrange them in a lattice so that the vertices are shard between tiles:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/11/mesh_bad.png"><img class="alignnone size-full wp-image-1732" title="mesh_bad" src="http://mikecann.co.uk/wp-content/uploads/2011/11/mesh_bad.png" alt="" width="207" height="193" /></a></p>
<p>This would then only require about 27,200 vertices which is really nice. I was hover having difficulties imagining how I would reference each tile individually in the shader so I could apply texture and color transformations and started wondering if another technique might work..</p>
<p>Having recently done some work with <a href="http://mikecann.co.uk/personal-project/terrainicles-webgl-haxe/">Point Sprite Particles</a> I knew that the GPU was really good at rendering Point Sprites. So I thought to myself, why not just make each tile a point sprite. That way I could then represent each tile as a vertex then I could pass custom properties such as texture and color to the shader as vertex buffer attributes. Doing it this way means that you only need as many vertices as there are visible tiles (about 27,200 for 4 layers) and I can reference each tile individually in the attribute buffer.</p>
<p>So armed with the theory I set to work bashing out some code. Having worked with raw WebGL in haXe on my last <a href="http://mikecann.co.uk/personal-project/gpu-state-preserving-particle-systems-with-webgl-haxe/">few experiments</a> I decided I didnt want to go through all that <a href="http://mikecann.co.uk/programming/why-developing-for-webgl-sucks/">pain</a> again just for the sake of a little more performance, so I decided to give Three.js another go in HaXe. Thankfully this time I was treading a known path so I could learn from existing threejs point-sprite particle samples. The bulk of the custom particle system logic I took from this rather excellent sample:</p>
<p><a href="http://alteredqualia.com/three/examples/webgl_custom_attributes_particles.html"><img class="alignnone size-full wp-image-1733" title="Shot_01" src="http://mikecann.co.uk/wp-content/uploads/2011/11/Shot_01.png" alt="" width="445" height="380" /></a></p>
<p>(<a href="http://alteredqualia.com/three/examples/webgl_custom_attributes_particles.html">http://alteredqualia.com/three/examples/webgl_custom_attributes_particles.html</a>)</p>
<p>So once I had the project setup it took me no time at all to bash out a sample that showed that I could easily have 27k+ tiles changing size and color each frame:</p>
<p><a href="http://mikecann.co.uk/projects/Hxaria/01/index.html">http://mikecann.co.uk/projects/Hxaria/01/index.html</a></p>
<p>Pretty aint it?</p>
<p>What you are looking at is 40,000 point sprites changing to a random colour and size every frame, well above the 27k needed. As part of my testing I found that it can actually handle a lot more (hundreds of thousands) of individually updating tiles!</p>
<p>Im planning to continue work on this sample, my next step is to get each particle using a different tile type and changing each frame.</p>
<p>I have uploaded the source to github for your perousal: <a href="https://github.com/mikecann/Hxaria">https://github.com/mikecann/Hxaria</a></p>
<p>Enjoy!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/hxaria-terraria-like-terrain-in-haxe-and-webgl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Terrainicles [WebGL &amp; HaXe]</title>
		<link>http://mikecann.co.uk/personal-project/terrainicles-webgl-haxe/</link>
		<comments>http://mikecann.co.uk/personal-project/terrainicles-webgl-haxe/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 14:14:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[GLSL]]></category>
		<category><![CDATA[HaXe]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1713</guid>
		<description><![CDATA[I have been playing with this thing, tweaking it, making changes for weeks. Theres so many different things I want to add. Different options, scenarios, optimisations etc. I decided however just to follow the &#8216;release early and often&#8217; mantra and get this thing out now. Before I go any further check out what im talking about here: http://mikecann.co.uk/projects/WebGLTerrainicles/ (You [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/head2.png"><img class="size-full wp-image-1715 alignnone" title="head2" src="http://mikecann.co.uk/wp-content/uploads/2011/10/head2.png" alt="" width="700" height="400" /></a></p>
<p>I have been playing with this thing, tweaking it, making changes for weeks. Theres so many different things I want to add. Different options, scenarios, optimisations etc. I decided however just to follow the &#8216;release early and often&#8217; mantra and get this thing out now.</p>
<p>Before I go any further check out what im talking about here:</p>
<p><a href="http://mikecann.co.uk/projects/WebGLTerrainicles/">http://mikecann.co.uk/projects/WebGLTerrainicles/<br />
(You will need a WebGL compatible browser, that means no IE) </a></p>
<p>Its a continuation of my earlier work on <a href="http://mikecann.co.uk/personal-project/gpu-state-preserving-particle-systems-with-webgl-haxe/">GPU particles using WebGL and HaXE</a>. Im trying to emulate some work I did years ago in XNA, on the <a href="http://mikecann.co.uk/lieroxna/project-update/">LieroXNA project</a>.</p>
<p>It uses the same techniques for updating and rendering particles entirely on the GPU as my previous post. What that means is that is possible have millions of particles interacting updating and rendering simultaneously as all the operations are performed on the GPU.</p>
<p>What I have added this time is another texture for the particles to collide with as they move. I was originally working with the same dirt and grass texture as my XNA project but I thought as it was Halloween I would get into the spirit a little <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>There are several options on the right hand side that can be used to tweak the properties of the simulation. I spent alot of time playing around with these, there are some really cool effects you can achieve with just simple modifications.</p>
<p>There are so many things I could add to improve this. You can see some of them in a video I made years ago:</p>
<p><object width="700" height="505" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/MocF1IU-5dc?version=3&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed width="700" height="505" type="application/x-shockwave-flash" src="http://www.youtube.com/v/MocF1IU-5dc?version=3&amp;hl=en_US" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<p>There we have some cool stuff like Bloom, forces and multiple rendering layers going on. It would be nice to get those in this sample too.</p>
<p>For now however I think im going to have a break from this sample. I have spent quite a few weeks to get to this point so far, and I think I need a break for a little bit so I can work on other things. I may come back to it soon tho If people are interested or if (probably more likely) I think of some &#8216;cool new thing&#8217; that will &#8216;only take 5 mins&#8217;.</p>
<p>I have uploaded the source for this sample to Github for people to lookat/fork if they wish:</p>
<p><a href="https://github.com/mikecann/WebGLTerrainicles">https://github.com/mikecann/WebGLTerrainicles</a></p>
<p>Enjoy!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/terrainicles-webgl-haxe/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why Developing for WebGL Sucks!</title>
		<link>http://mikecann.co.uk/programming/why-developing-for-webgl-sucks/</link>
		<comments>http://mikecann.co.uk/programming/why-developing-for-webgl-sucks/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 17:36:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebGL]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[textures]]></category>
		<category><![CDATA[threejs]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1698</guid>
		<description><![CDATA[For some time now I have been working with WebGL and have developed a sort of love/hate relationship with it. I love the ability to instantly target millions of people with GPU accelerated code without any plugins or barriers (excluding the targets that dont support it). However as a developer, writing code that takes advantage [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/head02.png"><img class="alignnone size-full wp-image-1701" title="head02" src="http://mikecann.co.uk/wp-content/uploads/2011/10/head02.png" alt="" width="700" height="400" /></a></p>
<p>For some time now I have been working with WebGL and have developed a sort of love/hate relationship with it. I love the ability to instantly target millions of people with GPU accelerated code without any plugins or barriers (excluding the targets that dont support it). However as a developer, writing code that takes advantage of WebGL kinda sucks.</p>
<h2>Procedural Based</h2>
<p>First off is the way you have to structure your GL calls. For example take a look at the following generic bit of webGL harvested from the net:</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">texture <span class="sy0">=</span> gl.<span class="me1">createTexture</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">activeTexture</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE0</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">bindTexture</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> texture<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">pixelStorei</span><span class="br0">&#40;</span>gl.<span class="me1">UNPACK_ALIGNMENT</span><span class="sy0">,</span> 1<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">texImage2D</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> 0<span class="sy0">,</span> gl.<span class="me1">RGB</span><span class="sy0">,</span> 64<span class="sy0">,</span> 64<span class="sy0">,</span> 0<span class="sy0">,</span></div></li><li class="li1"><div class="de1">     gl.<span class="me1">RGB</span><span class="sy0">,</span> gl.<span class="me1">FLOAT</span><span class="sy0">,</span> <span class="kw2">new</span> Float32Array<span class="br0">&#40;</span>pix<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">texParameteri</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> gl.<span class="me1">TEXTURE_MIN_FILTER</span><span class="sy0">,</span> gl.<span class="me1">NEAREST</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">texParameteri</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> gl.<span class="me1">TEXTURE_MAG_FILTER</span><span class="sy0">,</span> gl.<span class="me1">NEAREST</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">   texture1 <span class="sy0">=</span> gl.<span class="me1">createTexture</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">activeTexture</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE1</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">bindTexture</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> texture1<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">pixelStorei</span><span class="br0">&#40;</span>gl.<span class="me1">UNPACK_ALIGNMENT</span><span class="sy0">,</span> 1<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">texImage2D</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> 0<span class="sy0">,</span> gl.<span class="me1">RGB</span><span class="sy0">,</span> 64<span class="sy0">,</span> 64<span class="sy0">,</span> 0<span class="sy0">,</span></div></li><li class="li1"><div class="de1">     gl.<span class="me1">RGB</span><span class="sy0">,</span> gl.<span class="me1">FLOAT</span><span class="sy0">,</span> <span class="kw2">new</span> Float32Array<span class="br0">&#40;</span>pix1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">texParameteri</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> gl.<span class="me1">TEXTURE_MIN_FILTER</span><span class="sy0">,</span> gl.<span class="me1">NEAREST</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">texParameteri</span><span class="br0">&#40;</span>gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> gl.<span class="me1">TEXTURE_MAG_FILTER</span><span class="sy0">,</span> gl.<span class="me1">NEAREST</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">   FBO <span class="sy0">=</span> gl.<span class="me1">createFramebuffer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">bindFramebuffer</span><span class="br0">&#40;</span>gl.<span class="me1">FRAMEBUFFER</span><span class="sy0">,</span> FBO<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">framebufferTexture2D</span><span class="br0">&#40;</span>gl.<span class="me1">FRAMEBUFFER</span><span class="sy0">,</span> gl.<span class="me1">COLOR_ATTACHMENT0</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">       gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> texture<span class="sy0">,</span> 0<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   FBO1 <span class="sy0">=</span> gl.<span class="me1">createFramebuffer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">bindFramebuffer</span><span class="br0">&#40;</span>gl.<span class="me1">FRAMEBUFFER</span><span class="sy0">,</span> FBO1<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   gl.<span class="me1">framebufferTexture2D</span><span class="br0">&#40;</span>gl.<span class="me1">FRAMEBUFFER</span><span class="sy0">,</span> gl.<span class="me1">COLOR_ATTACHMENT0</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">       gl.<span class="me1">TEXTURE_2D</span><span class="sy0">,</span> texture1<span class="sy0">,</span> 0<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">   <span class="kw1">if</span><span class="br0">&#40;</span> gl.<span class="me1">checkFramebufferStatus</span><span class="br0">&#40;</span>gl.<span class="me1">FRAMEBUFFER</span><span class="br0">&#41;</span> <span class="sy0">!=</span> gl.<span class="me1">FRAMEBUFFER_COMPLETE</span><span class="br0">&#41;</span></div></li><li class="li1"><div class="de1">     <span class="kw3">alert</span><span class="br0">&#40;</span>err <span class="sy0">+</span> <span class="st0">&quot;FLOAT as the color attachment to an FBO&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div></div>
<p>All it does is create a couple of textures, setting their starting values and creates two frame buffers for rendering to. Its just it looks complicated and difficult to understand.</p>
<p>GL works on a procedural basis, so you tell GL that you are about to work on something by calling a function like &#8220;bindTexture()&#8221; then on the next line you perform an operation on it such as &#8220;pixelStorei()&#8221;. Now this may have made perfect sense back when we were writing everything in C which is procedural anyway however this is Javascript (or haXe in my case) which is an Object based language, code like this is difficult to understand and follow.</p>
<p>The procedural nature of WebGL means you have to be much more careful about unsetting things you have previously set. For example if you bind a texture to perform some operation, you must then remember to unbind it else you could inadvertently cause operations to be applied to it on subsequent calls elsewhere in your codebase. It this &#8216;hidden state&#8217; that has caused me alot of headaches when developing my samples.</p>
<p>The principal behind WebGL was to provide a very low-level library which other developers can build upon to build more complex and abstracted libraries. And there are numerous libraries out there. I personally have tried several of them including the very popular <a href="https://github.com/mrdoob/three.js/">three.js</a>. Three.js is great for doing common things like loading models and putting quads on the screen. I however encountered a problem with render targets which I struggled with for days before I discovered that you had to set &#8220;needsUpdate&#8221; to true on your texture before using it. In the end I decided to drop three.js beacuse of another issue I encountered and instead attempt to reduce my complications by working with webGL directly.</p>
<p>Flash11&#8242;s Stage3D has the same philosophy as webGL, to provide a low level API for other developers to build libraries upon. The thing is Flash11&#8242;s low-level API makes more sense and is more readable. For example the following to me is much more readable than its webGL equivalent:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1">texture = <span class="kw7">c</span><span class="sy0">.</span>createTexture<span class="br0">&#40;</span>logo<span class="sy0">.</span><span class="kw7">width</span><span class="sy0">,</span> logo<span class="sy0">.</span><span class="kw7">height</span><span class="sy0">,</span> Context3DTextureFormat<span class="sy0">.</span>BGRA<span class="sy0">,</span> <span class="kw1">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">texture<span class="sy0">.</span>uploadFromBitmapData<span class="br0">&#40;</span>logo<span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div></div>
<p>The Stage3D API also uses language like &#8220;upload&#8221; to let you know when you are transferring data to the GPU, for a new comer to GL you have no clue when things are going to the GPU. Its small things like this that reduce the &#8220;WTF?&#8221; factor when tackling the tricky world of hardware-accelerated 3D programming.</p>
<h2>Cross-domain textures</h2>
<p>This one cropped up around July time this year and took me ages to work out what was going on. For some inexplicable reason (or so it seemed) my code one day stopped working. When I looked for demo code online it all worked fine, however when I downloaded it and run it locally it also didnt work. I was getting errors like the following:</p>
<p><span style="color: #ff0000;">Uncaught Error: SECURITY_ERR: DOM Exception 18</span><br />
<span style="color: #ff0000;">Uncaught Error: SECURITY_ERR: DOM Exception 18</span><br />
<span style="color: #ff0000;">Uncaught Error: SECURITY_ERR: DOM Exception 18</span><br />
<span style="color: #ff0000;">Uncaught Error: SECURITY_ERR: DOM Exception 18</span><br />
<span style="color: #ff0000;">Uncaught Error: SECURITY_ERR: DOM Exception 18 </span></p>
<p>I was so baffled that <a href="http://haxe.1354130.n2.nabble.com/WebGL-amp-Textures-td6638378.html">I posted about it</a> on the HaXe mailing list asking for help, thinking it was something I was doing wrong with HaXe. It turns out (after much wall-head-butting) this was a change that they brought into Chrome 13 and Firefox 5 to combat a security problem when using shaders that use textures from a different domain to the one running the code:</p>
<p><a href="http://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html">http://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html</a></p>
<p>Now I have no problem with cross-domain issues, im used to this from Flash where we have the same sort of setPixel() restrictions on cross-domain BitmapData&#8217;s. The thing is, it appears that this restriction applies when running code locally too. So If you are developing something on your local machine and trying to access a texture from disk it throws the same security errors because the browser thinks you are reaching across domains to access the image.</p>
<p>At the time the only way to get around this was to create your own webserver that you run on localhost to server up the files. So to do that I had to download python so I could run a simple localhost commandline webserver from my bin directory. What an effort! There may be easier ways these days to solve it but at the time it really frustrated me and formed yet another barrier to developing webGL.</p>
<h2>No Error Messages</h2>
<p>This is by far the most annoying thing about developing for WebGL. So many times I have been trying to write something that I know SHOULD work but for some reason it doesn&#8217;t. I dont get any error messages, nothing. It makes writing something from scratch neigh on impossible.</p>
<p>In my last post &#8220;<a href="http://mikecann.co.uk/personal-project/gpu-state-preserving-particle-systems-with-webgl-haxe/">GPU State Preserving Particle Systems with WebGL &amp; HaXe</a>&#8221; I started with an idea. I attempted to code it &#8216;bottom-up&#8217;. That is start with nothing and then add more code until I reached what I wanted. Unfortunately having no error messages in WebGL makes this very difficult indeed. I would spend some time writing something really simple, like trying to get a textured quad to render on the screen only to find I get nothing. I double check my camera matrices my vertex and texture buffers, my shader and still nothing. Eventually I found that I hadn&#8217;t bound something first before trying to operate on it *sigh*</p>
<p>In the end I found the best way to get anywhere is to go from the other direction, a &#8216;top-down&#8217; method. Start with something kind of simmilar to what you want then cut bits out one line at a time until you get what you want. Its extremely time consuming and frustrating, but its less frustrating than going from the other way.</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/1-Trace.gif"><img class="size-full wp-image-1706 alignnone" title="1-Trace" src="http://mikecann.co.uk/wp-content/uploads/2011/10/1-Trace.gif" alt="" width="705" height="231" /></a></p>
<p>There are tools out there that help with debugging what is going wrong. Namely the <a href="http://www.google.co.uk/url?sa=t&amp;rct=j&amp;q=webgl%20inspector&amp;source=web&amp;cd=1&amp;ved=0CBwQFjAA&amp;url=http%3A%2F%2Fbenvanik.github.com%2FWebGL-Inspector%2F&amp;ei=9EWhTsHdAtSJhQe7hv3jBA&amp;usg=AFQjCNElgWdAeKcNOnrDFrSnr6rbCLUcWg">WebGL Inspector</a> (see above) is intended to provide gDEBugger / PIX like debugging information about what is going on inside webGL. Its a clever bit of tech, it lets you inspect buffers and traces each gl call, however it suffers from the same underlying problem of having no errors. You setup a buffer incorrectly and what you get is &#8220;INVALID_VALUE&#8221;. No indication as to which of the values is invalid or what part of the call you messed up on <img src='http://mikecann.co.uk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<h2>Googling Doesn&#8217;t Help</h2>
<p>If you do happen to get an error message (unlikely) or you word your problem in a sufficiently succinct and googaleble way you will then run into the next big problem with WebGL; theres very few people using it. Now I know I am likely to be flamed for that comment, but it just seems that way to me. Whenever I tried to google my problem, or google for what I was trying to achieve (because working bottom-up doesnt work) there would be a very sparse smattering of relevant posts. Usually the results are forum posts and are OpenGL not WebGL related and are from 5-10 years ago.</p>
<h2>But..</h2>
<p>Now having just ranted on for several hundred words about why it sucks im going to finish it off by saying that im going to continue to develop for WebGL using haXe regardless. Why? Well I just like making pretty things that run fast and GPGPU programming appeals to me for some unknown (likely sadistic) reason.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/programming/why-developing-for-webgl-sucks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>GPU State Preserving Particle Systems with WebGL &amp; HaXe</title>
		<link>http://mikecann.co.uk/personal-project/gpu-state-preserving-particle-systems-with-webgl-haxe/</link>
		<comments>http://mikecann.co.uk/personal-project/gpu-state-preserving-particle-systems-with-webgl-haxe/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 12:02:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[GLSL]]></category>
		<category><![CDATA[HaXe]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WebGL]]></category>
		<category><![CDATA[complex]]></category>
		<category><![CDATA[glsl]]></category>
		<category><![CDATA[gpu]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Particles]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1687</guid>
		<description><![CDATA[Well this is the post I didnt think was going to happen. I have been struggling for weeks with this little bit of tech, ill explain more about why it has been so difficult in another post. For now however, ill just talk about this sample. So the idea was to build upon what I had been [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/header01.png"><img class="alignnone size-full wp-image-1688" title="header01" src="http://mikecann.co.uk/wp-content/uploads/2011/10/header01.png" alt="" width="700" height="400" /></a></p>
<p>Well this is the post I didnt think was going to happen. I have been struggling for weeks with this little bit of tech, ill explain more about why it has been so difficult in another post. For now however, ill just talk about this sample.</p>
<p>So the idea was to build upon what I had been working with previously with my <a href="http://mikecann.co.uk/programming/5000000-chrome-crawlers-why-not-haxe-webgl/">stateless particles systems with WebGL and HaXe</a>. The intention from the start was to replicate some of my <a href="http://mikecann.co.uk/university-projects/xnagpuparticles-1000000-dynamic-particles/">very early work</a> (from 2007) on state preserving particle systems in WebGL.</p>
<p><strong>Before I go any further, you can check it out in action here:<br />
</strong><strong><a href="http://mikecann.co.uk/projects/HaxeWebGLParticles/">http://mikecann.co.uk/projects/HaxeWebGLParticles/</a> </strong></p>
<p>First a quick reminder. The difference between a stateless and state-preserving particle simulation is that in the latter we store and update the positions, velocities and other properties of each particle per frame, allowing us to interact and control the simulation. This differs from the stateless particle simulation (detailed in my<a href="http://mikecann.co.uk/programming/5000000-chrome-crawlers-why-not-haxe-webgl/"> previous post</a>), where the position for each particle is calculated each frame based on a fixed algorithm.</p>
<p>A <a href="http://code.google.com/p/angleproject/issues/detail?id=95">fairly reccent addition</a> to WebGL made this possible, namely texture lookups in the vertex shader (aka Vertex Texture Fetch). I wont go over the exact details how this makes state preserving particle systems possible as I have already documented it in <a href="http://mikecann.co.uk/university-projects/xnagpuparticles-1000000-dynamic-particles/">my earlier work</a>. A brief explanation is that it allows you to use the fragment shader to perform the updates on particle state stored in textures then use the vertex shader to map those states to a point-sprite vertex buffer.</p>
<p>Basically what this means is that the entire particle simulation can be contained and updated on the GPU, which means <a href="http://mikecann.co.uk/programming/5000000-chrome-crawlers-why-not-haxe-webgl/">no read-back</a>. This allows us to achieve simulations of <strong>millions</strong> of particles without too much difficulty (depending on GPU ofcourse).</p>
<p><strong>I have uploaded the source for people to perouse at their leisure</strong>:<br />
<a href="https://github.com/mikecann/HaxeWebGLParticles">https://github.com/mikecann/HaxeWebGLParticles</a></p>
<p>As usual it was written using the JS target of HaXe so it should be fairly easy to understand whats going on if you have written any Ecma-script-like-language. Im going to detail this in my next post, but the code isnt the best I have ever written as its a result of a mish-mash of various samples and examples I have found on the web. If anyone has any comments on things that are wrong or could be done better I would be very happy to hear about them.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/gpu-state-preserving-particle-systems-with-webgl-haxe/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Game of Life HaXe &amp; NME on iOS</title>
		<link>http://mikecann.co.uk/personal-project/game-of-life-haxe-nme-on-ios/</link>
		<comments>http://mikecann.co.uk/personal-project/game-of-life-haxe-nme-on-ios/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 19:22:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HaXe]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1675</guid>
		<description><![CDATA[For the last few days I have been playing around with trying to get the game of life sample from my previous post working on the iPhone using haXe with NME. In theory NME should do all the heavy lifting for you so that it should be as simple as running: [code lang="text"] haxelib run nme build [...]]]></description>
			<content:encoded><![CDATA[<p>For the last few days I have been playing around with trying to get the<a href="http://mikecann.co.uk/personal-project/conways-game-of-life-in-haxe-nme-massiveunit/"> game of life sample from my previous post</a> working on the iPhone using haXe with NME.</p>
<p>In theory NME should do all the heavy lifting for you so that it should be as simple as running:</p>
<p>[code lang="text"]</p>
<pre>haxelib run nme build nmebuild.nmml ios</pre>
<p>[/code]</p>
<p>Unfortunately however when I ran this I was getting rather cryptic errors:</p>
<p>[code lang="text"]</p>
<pre>Called from ? line 1
Called from InstallTool.hx line 384
Called from a C function
Called from InstallTool.hx line 70
Called from a C function
Called from installers/InstallerBase.hx line 61
Called from installers/InstallerBase.hx line 668
Called from installers/InstallerBase.hx line 762
Called from haxe/xml/Fast.hx line 59
Uncaught exception - icon is missing attribute name</pre>
<p>[/code]</p>
<p>I had read from the <a href="http://www.haxenme.org/developers/get-started/">NME documentation page</a> that this may have been fixed in the more reccent versions of NME. So I downloaded the beta version (you could checkout from SVN too if you wish) and told haxelib that im going to be working with a development version of NME with the following command:</p>
<p>[code lang="text"]</p>
<pre>haxelib dev nme /Users/mikec/Documents/NME_3.1_Beta</pre>
<p>[/code]</p>
<p>Now when I try to build for ios I get success!</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/2011-10-12_1149.png"><img class="alignnone size-full wp-image-1679" title="2011-10-12_1149" src="http://mikecann.co.uk/wp-content/uploads/2011/10/2011-10-12_1149.png" alt="" width="454" height="165" /></a></p>
<p>From there is a simple matter of opening the generated xcode project, connecting my iphone and hitting run:</p>
<p><object width="700" height="386"><param name="movie" value="http://www.youtube.com/v/ZsILr8vjWL8?version=3&amp;hl=en_GB&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZsILr8vjWL8?version=3&amp;hl=en_GB&amp;hd=1" type="application/x-shockwave-flash" width="700" height="386" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>I really like how easy the workflow is compared to the Adobe Air packaging system. Generating the xcode project makes things so much faster. </p>
<p>If I can get my hands on an Android phone next I think im going to have to have a go at getting this sample working on there too!</p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/game-of-life-haxe-nme-on-ios/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Conway&#8217;s Game of Life in haXe [NME &amp; MassiveUnit]</title>
		<link>http://mikecann.co.uk/personal-project/conways-game-of-life-in-haxe-nme-massiveunit/</link>
		<comments>http://mikecann.co.uk/personal-project/conways-game-of-life-in-haxe-nme-massiveunit/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 17:13:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HaXe]]></category>
		<category><![CDATA[Personal Projects]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[haxe]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://mikecann.co.uk/?p=1662</guid>
		<description><![CDATA[The second day of try{harder} was dedicated to a single topic; test driven development (TDD). The group was split into pairs and given the task of using TDD to write a solver for the game of life in AS3. After an hour we then threw away everything we had done, swapped partners and repeated the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/2011-10-09_1257.png"><img class="alignnone size-full wp-image-1664" title="2011-10-09_1257" src="http://mikecann.co.uk/wp-content/uploads/2011/10/2011-10-09_1257.png" alt="" width="700" height="400" /></a></p>
<p>The second day of <a href="http://mikecann.co.uk/programming/try-harder-my-haxe-slides-and-code/">try{harder}</a> was dedicated to a single topic; test driven development (TDD).</p>
<p>The group was split into pairs and given the task of using TDD to write a solver for the game of life in AS3. After an hour we then threw away everything we had done, swapped partners and repeated the process.</p>
<p>This was extremely valuable for me as I had never written a unit test before. Seeing how different people tackled the same problem was fascinating and informative.</p>
<p>After repeating the process three times Stray asked if I was interested in teaming up with another attendee of the conference <a href="http://www.google.co.uk/url?sa=t&amp;source=web&amp;cd=1&amp;sqi=2&amp;ved=0CBsQFjAA&amp;url=http%3A%2F%2Falecmce.com%2F&amp;ei=jZyRTp-fEcmAhQeIwtn0Dw&amp;usg=AFQjCNEKPdue-giHnTp0HZCJwVWz3QeVoQ">Alec McEachran</a> to investigate unit testing in haXe. It was a great idea as it meant we both could investigate how unit testing worked in haXe and it would give me another code example for my talk the following day.</p>
<p>After a brief search we decided on Mike Stead&#8217;s <a href="https://github.com/massiveinteractive/MassiveUnit">MassiveUnit</a> for testing as the testing syntax looked similar to FlexUnit and it contained a toolchain for running the tests on multiple platforms.</p>
<p>An example of a test we wrote is:</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw4">package</span> <span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw1">import</span> massive<span class="sy0">.</span>munit<span class="sy0">.</span>Assert<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="kw1">import</span> Grid<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/**</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* ...</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* @author MikeC &amp; Alec McEachran</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw4">class</span> GridTest</div></li><li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw2">var</span> grid <span class="sy0">:</span> Grid<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	@Before</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> before<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Void</div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		grid = <span class="kw1">new</span> Grid<span class="br0">&#40;</span>3<span class="sy0">,</span> 3<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	@After</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> after<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Void</div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		grid = <span class="kw1">null</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	@Test</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> initiallyThereAreNoLiveNeighbors<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Void</div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		<span class="kw2">var</span> liveNeighbors = grid<span class="sy0">.</span>getLiveNeighbors<span class="br0">&#40;</span>1<span class="sy0">,</span> 1<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		Assert<span class="sy0">.</span>isTrue<span class="br0">&#40;</span>liveNeighbors == 0<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	@Test</div></li><li class="li1"><div class="de1">	<span class="kw1">public</span> <span class="kw3">function</span> liveNeighborCountIsAccurate<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Void</div></li><li class="li1"><div class="de1">	<span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		grid<span class="sy0">.</span><span class="kw1">set</span><span class="br0">&#40;</span>0<span class="sy0">,</span> 0<span class="sy0">,</span> <span class="kw1">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		grid<span class="sy0">.</span><span class="kw1">set</span><span class="br0">&#40;</span>1<span class="sy0">,</span> 0<span class="sy0">,</span> <span class="kw1">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		grid<span class="sy0">.</span><span class="kw1">set</span><span class="br0">&#40;</span>2<span class="sy0">,</span> 1<span class="sy0">,</span> <span class="kw1">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="kw2">var</span> liveNeighbors = grid<span class="sy0">.</span>getLiveNeighbors<span class="br0">&#40;</span>1<span class="sy0">,</span> 1<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		Assert<span class="sy0">.</span>isTrue<span class="br0">&#40;</span>liveNeighbors == 3<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre></div></div>
<p>It should look fairly familiar to anyone who has used FlexUnit before. The metatags @Before @After and @Test perform in exactly the same way as they do in FlexUnit. Another benefit of using munit over the built in testing framework in haXe is that you are given a tool to run tests on all platforms simultaneously:</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">haxelib run munit test test.hxml</pre></div></div>
<p>When executed you get something that looks like the following:</p>
<p><a href="http://mikecann.co.uk/wp-content/uploads/2011/10/ScreenHunter_01-Oct.-09-13.54.jpg"><img class="alignnone size-full wp-image-1670" title="ScreenHunter_01 Oct. 09 13.54" src="http://mikecann.co.uk/wp-content/uploads/2011/10/ScreenHunter_01-Oct.-09-13.54.jpg" alt="" width="643" height="344" /></a></p>
<p>Which presents a nice graphical representation of the tests run and which failed (if any).</p>
<p>Once built and tested we decided to give the code a simple visual representation. We wanted to show off the ability for haXe to target multiple platforms. To do this we decided to go with <a href="http://www.haxenme.org/">NME </a>which I had been experimenting around with recently.</p>
<p><a href="http://www.haxenme.org/">NME </a>is a library and tool chain for haXe designed to allow the developer to use the flash API on multiple platforms. They achieve this by writing platform targeted version of the flash API. So what this means is code such as the following:</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="actionscript3" style="font-family:monospace;"><span class="kw4">package</span> <span class="sy0">;</span>
<span class="kw1">import</span> <span class="kw6">flash.display</span><span class="sy0">.</span><a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span class="kw5">Bitmap</span></a><span class="sy0">;</span>
<span class="kw1">import</span> <span class="kw6">flash.display</span><span class="sy0">.</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span class="kw5">BitmapData</span></a><span class="sy0">;</span>
<span class="kw1">import</span> <span class="kw6">flash.display</span><span class="sy0">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span class="kw5">MovieClip</span></a><span class="sy0">;</span>
<span class="kw1">import</span> <span class="kw6">flash.geom</span><span class="sy0">.</span><a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span class="kw5">Rectangle</span></a><span class="sy0">;</span>
&nbsp;
<span class="coMULTI">/**
 * ...
 * @author MikeC &amp; Alec McEachran
 */</span>
&nbsp;
<span class="kw4">class</span> Render
<span class="br0">&#123;</span>
&nbsp;
	<span class="kw1">private</span> <span class="kw2">var</span> _cellSize <span class="sy0">:</span> Int<span class="sy0">;</span>
	<span class="kw1">private</span> <span class="kw2">var</span> _renderTarget <span class="sy0">:</span> <a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span class="kw5">BitmapData</span></a><span class="sy0">;</span>
	<span class="kw1">private</span> <span class="kw2">var</span> _rect<span class="sy0">:</span><a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span class="kw5">Rectangle</span></a><span class="sy0">;</span>
&nbsp;
	<span class="kw1">public</span> <span class="kw3">function</span> <span class="kw1">new</span><span class="br0">&#40;</span>container<span class="sy0">:</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span class="kw5">MovieClip</span></a><span class="sy0">,</span> cols<span class="sy0">:</span>Int<span class="sy0">,</span> rows<span class="sy0">:</span>Int<span class="sy0">,</span> cellSize<span class="sy0">:</span>Int<span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		_cellSize = cellSize<span class="sy0">;</span>
		_renderTarget = <span class="kw1">new</span> <a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span class="kw5">BitmapData</span></a><span class="br0">&#40;</span>cols <span class="sy0">*</span> cellSize<span class="sy0">,</span> rows <span class="sy0">*</span> cellSize<span class="sy0">,</span> <span class="kw1">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
		container<span class="sy0">.</span><span class="kw7">addChild</span><span class="br0">&#40;</span><span class="kw1">new</span> <a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span class="kw5">Bitmap</span></a><span class="br0">&#40;</span>_renderTarget<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
		_rect = <span class="kw1">new</span> <a href="http://www.google.com/search?q=rectangle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:rectangle.html"><span class="kw5">Rectangle</span></a><span class="br0">&#40;</span>0<span class="sy0">,</span> 0<span class="sy0">,</span> _cellSize<span class="sy0">,</span> _cellSize<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">public</span> inline <span class="kw3">function</span> <span class="kw7">lock</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Void
	<span class="br0">&#123;</span>
		_renderTarget<span class="sy0">.</span><span class="kw7">lock</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
		_renderTarget<span class="sy0">.</span><span class="kw7">fillRect</span><span class="br0">&#40;</span>_renderTarget<span class="sy0">.</span><span class="kw7">rect</span><span class="sy0">,</span> 0xff0000<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">public</span> inline <span class="kw3">function</span> renderCell<span class="br0">&#40;</span><span class="kw7">x</span><span class="sy0">:</span>Int<span class="sy0">,</span> <span class="kw7">y</span><span class="sy0">:</span>Int<span class="sy0">,</span> isLive<span class="sy0">:</span>Bool<span class="br0">&#41;</span><span class="sy0">:</span>Void
	<span class="br0">&#123;</span>
		<span class="kw1">if</span> <span class="br0">&#40;</span>isLive<span class="br0">&#41;</span>
		<span class="br0">&#123;</span>
			_rect<span class="sy0">.</span><span class="kw7">x</span> = <span class="kw7">x</span> <span class="sy0">*</span> _cellSize<span class="sy0">;</span>
			_rect<span class="sy0">.</span><span class="kw7">y</span> = <span class="kw7">y</span> <span class="sy0">*</span> _cellSize<span class="sy0">;</span>
			_renderTarget<span class="sy0">.</span><span class="kw7">fillRect</span><span class="br0">&#40;</span>_rect<span class="sy0">,</span> 0<span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">public</span> inline <span class="kw3">function</span> <span class="kw7">unlock</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">:</span>Void
	<span class="br0">&#123;</span>
		_renderTarget<span class="sy0">.</span><span class="kw7">unlock</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
<span class="br0">&#125;</span></pre></div></div>
<p>Will compile down to flash, c++ and Javascript! NME also includes packaging abilities for webos, android and ios. So with a few scripted command lines you can target most app marketplaces:</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://mikecann.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">haxelib run nme test YourProject.nmml flash
haxelib run nme update YourProject.nmml ios
haxelib run nme test YourProject.nmml webos
haxelib run nme test YourProject.nmml android
haxelib run nme test YourProject.nmml cpp
haxelib run nme test YourProject.nmml cpp -64</pre></div></div>
<p>What it means for this project is we could very quickly get a view for our game of life running in flash, JS and native desktop.</p>
<p>To show just how easy it is I made the following video:</p>
<p><object width="700" height="505"><param name="movie" value="http://www.youtube.com/v/VNF2gH5o9Zs?version=3&amp;hl=en_GB"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/VNF2gH5o9Zs?version=3&amp;hl=en_GB" type="application/x-shockwave-flash" width="700" height="505" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>You can see the HTML5 build here: <a href="http://mikecann.co.uk/projects/gameoflife/Export/html5/bin/">http://mikecann.co.uk/projects/gameoflife/Export/html5/bin/</a></p>
<p>And the flash build here: <a href="http://mikecann.co.uk/projects/gameoflife/Export/flash/bin/MyApplication.swf">http://mikecann.co.uk/projects/gameoflife/Export/flash/bin/MyApplication.swf</a></p>
<p>I have uploaded the source for the project here: <a href="http://mikecann.co.uk/projects/gameoflife/gameoflife.zip">http://mikecann.co.uk/projects/gameoflife/gameoflife.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikecann.co.uk/personal-project/conways-game-of-life-in-haxe-nme-massiveunit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

