<?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>Acorn Heroes &#187; iPhone</title>
	<atom:link href="http://acornheroes.com/tag/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://acornheroes.com</link>
	<description>iPhone Development from the Ends of the Earth</description>
	<lastBuildDate>Sun, 21 Aug 2011 03:53:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dynamic Lighting Experiments</title>
		<link>http://acornheroes.com/2010/03/dynamic-lighting-experiments/</link>
		<comments>http://acornheroes.com/2010/03/dynamic-lighting-experiments/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 00:43:02 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Prototyping]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=349</guid>
		<description><![CDATA[We&#8217;re currently prototyping some ideas for our next game. This time round we&#8217;re looking to do something fun with light and dark. Unfortunately the fixed OpenGL pipeline has a fairly standard look to it, and we can&#8217;t move to using shaders in OpenGL 2 without alienating a large number of people (including ourselves &#8211; our [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://acornheroes.com/wp-content/uploads/2010/03/screenshot-20100311-205542-200x3003.png"><img class="alignright size-thumbnail wp-image-340" title="screenshot-20100311-205542-200x3003" src="http://acornheroes.com/wp-content/uploads/2010/03/screenshot-20100311-205542-200x3003-150x150.png" alt="" width="150" height="150" /></a>We&#8217;re currently prototyping some ideas for our next game.  This time round we&#8217;re looking to do something fun with light and dark.  Unfortunately the fixed OpenGL pipeline has a fairly standard look to it, and we can&#8217;t move to using shaders in OpenGL 2 without alienating a large number of people (including ourselves &#8211; our personal devices are both iPod Touches).</p>
<p>So as well as game play ideas, we&#8217;ve been prototyping the tech we&#8217;ll need to bring our world to life.  The game will be 2d, but we really want to find a good way to render lights and shadows to create a dark, threatening experience.</p>
<p>After some Google-ing I found a good starting point over on <a href="http://www.gamedev.net/reference/articles/article2032.asp">GameDev.net</a>.  The basic idea is that each light is rendered into a buffer (the alpha buffer in this case), and then any shadows are rendered on top, blacking out the light.  The alpha buffer is then combined with the scene geometry to add colour to the scene.</p>
<p><a href="http://acornheroes.com/wp-content/uploads/2010/03/weird1.jpg"><img src="http://acornheroes.com/wp-content/uploads/2010/03/weird1-150x150.jpg" alt="" title="weird1" width="150" height="150" class="alignleft size-thumbnail wp-image-346" /></a>Fairly quickly I was able to get the basic algorithm up and running.  The problem though is that each light requires rendering a screen&#8217;s worth of data, and frame rates drop drastically after adding more than 2 or 3 lights.  So I started looking around for other options.</p>
<p>One idea that appealed was to render all the lights into a single buffer, and then use a single pass to lay this back over the scene.  The problem here is that we can&#8217;t just render each light&#8217;s shadows into the buffer as black.</p>
<p>The answer here is to calculate the shadows for a light and incorporate them into the mesh used to render the light &#8211; i.e. instead of, say, a circular triangle fan for a light source, we generate a mesh for the circular fan minus the shadows.</p>
<p><a href="http://acornheroes.com/wp-content/uploads/2010/03/screen-shot-2010-03-18-at-123509-pm.png"><img class="alignright size-thumbnail wp-image-337" title="screen-shot-2010-03-18-at-123509-pm" src="http://acornheroes.com/wp-content/uploads/2010/03/screen-shot-2010-03-18-at-123509-pm-150x150.png" alt="" width="150" height="150" /></a>So, after a few false starts I managed to get the basic algorithm working, and you can see its development in the screen shots on this page.  The good news is that we can have large (double digit) numbers of lights in a scene, all casting shadows and all able to be moved or turned on and off dynamically each frame.  Currently performance is about 45fps on a 2nd gen iPod Touch, but I&#8217;m fairly confident that can be drastically improved with some basic optimisation.</p>
<p>Once I&#8217;ve got the code properly under control, I&#8217;ll write an article covering the technique in some depth, if people are interested.</p>
<p>The last screen shot here shows the algorithm working at the moment.  I still need to add spot lights rather than point light sources, but that should be a fairly simple thing to add.  There&#8217;s a couple of bugs still to iron out too, but I think it proves the concept well enough to let us move onto prototyping other parts of the game.  The addition of textures makes a huge difference too.  While this is still very rough, I think there&#8217;s some real promise here, and can&#8217;t wait to start building the game that makes the most of it!</p>
<p><a href="http://acornheroes.com/wp-content/uploads/2010/03/screen-shot-2010-03-19-at-113022-am1.png"><img class="aligncenter size-full wp-image-342" title="screen-shot-2010-03-19-at-113022-am1" src="http://acornheroes.com/wp-content/uploads/2010/03/screen-shot-2010-03-19-at-113022-am1.png" alt="" width="309" height="336" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2010/03/dynamic-lighting-experiments/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Provisioning an iPhone explained simply and clearly</title>
		<link>http://acornheroes.com/2009/08/provisioning-an-iphone-explained-simply-and-clearly/</link>
		<comments>http://acornheroes.com/2009/08/provisioning-an-iphone-explained-simply-and-clearly/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 21:17:30 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Setting up]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Provisioning]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=225</guid>
		<description><![CDATA[One of the weirdest / hardest things to do when starting iPhone development is setting up the connection between your development machine and your iPhone / iPod Touch (known as provisioning).  I&#8217;ve done it once, but it&#8217;s fair to say it happened in a blur and I was following instructions fairly blindly. Dan Grigsby over [...]]]></description>
			<content:encoded><![CDATA[<p>One of the weirdest / hardest things to do when starting iPhone development is setting up the connection between your development machine and your iPhone / iPod Touch (known as <em>provisioning</em>).  I&#8217;ve done it once, but it&#8217;s fair to say it happened in a blur and I was following instructions fairly blindly.</p>
<p>Dan Grigsby over at <a href="http://www.mobileorchard.com">Mobile Orchard</a> has put together a <a href="http://www.mobileorchard.com/iphone-development-provisioning/">screencast</a> that explains the process of provisioning an iPhone / iPod touch.  It&#8217;s well explained, simple to follow, and a very handy resource to have around.  It&#8217;s a free download for the next week, after that it&#8217;ll be US$5.  So if you&#8217;re a new developer, or if this is something that you&#8217;re a bit unsure of, grab the screencast while it&#8217;s free.</p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2009/08/provisioning-an-iphone-explained-simply-and-clearly/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unit Testing and linking Static Libraries with XCode</title>
		<link>http://acornheroes.com/2009/06/unit-testing-and-linking-static-libraries-with-xcode/</link>
		<comments>http://acornheroes.com/2009/06/unit-testing-and-linking-static-libraries-with-xcode/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 04:55:31 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Static Libraries]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=152</guid>
		<description><![CDATA[For some time I&#8217;ve been wanting to set up unit testing as a part of my iPhone development process. Being mainly a Visual Studio developer, I&#8217;ve yet to learn all the ins and outs of XCode and GCC projects, so it seemed like a good chance to learn more.  There are a number of tools [...]]]></description>
			<content:encoded><![CDATA[<p>For some time I&#8217;ve been wanting to set up unit testing as a part of my iPhone development process. Being mainly a Visual Studio developer, I&#8217;ve yet to learn all the ins and outs of XCode and GCC projects, so it seemed like a good chance to learn more.  There are a <a href="http://www.mobileorchard.com/ocunit-integrated-unit-testing-in-xcode/">number</a> of <a href="http://www.sente.ch/s/?p=535&amp;lang=en">tools</a> <a href="http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting">available</a>.  I was keen to try out <a href="http://unittest-cpp.sourceforge.net/">UnitTest++</a> by Noel Llopis and Charles Nicholson, as it is a) light weight, and b) designed for use with C++, which a large portion of our code will be.  Noel has <a href="http://gamesfromwithin.com/?cat=11">several articles</a> about unit testing that I&#8217;d recommend reading.</p>
<p>So here&#8217;s the plan.  I want to set up libraries of useful code that I can re-use across projects.  For the iPhone this currently means statically linked libraries.  Next, I want to create unit tests for the libraries and have the tests run as a part of my build process.  If you just want to get your hands on a working sample, <a href="http://www.acornheroes.com/Code/CoolGame.zip">grab it here</a>.</p>
<p>OK, let&#8217;s get started.  I&#8217;ve created a new project in XCode.  Any will do, but I like to see something visual, so I created an OpenGL application called CoolGame.  By default, XCode adds new files into one monolithic folder, which is a pain.</p>
<p>Instead, open the project folder in the Finder, and add a folder called UnitTest++ under the main project folder, for example,  {YourProjectPath}/CoolGame/UnitTest++.  Download the <a href="http://sourceforge.net/project/showfiles.php?group_id=158151">latest version of UnitTest++</a>. Open up the downloaded folder, we want to copy all the files from the src folder into our UnitTest++ folder.  You can leave out the Win32 and tests folders if you like, we won&#8217;t use them.</p>
<p>Going back to XCode, control-click (or right-click) on &#8216;Targets&#8217; and add a new iPhone static library target, calling it UnitTest++.  From the finder, drag and drop the UnitTest++ folder into XCode, just below the project name in &#8216;Groups &amp; Files&#8217;.  In the dialog that pops up, uncheck &#8217;Copy items&#8230;&#8217;, select &#8216;Recursively create groups&#8230;&#8217; and ensure we&#8217;re adding them only to the UnitTest++ project.  Control click on the UnitTest++ target, and try building it.  If all is going well, it should build happily.  Now we need a test case to prove it&#8217;s all working nicely.</p>
<p>Lets add two new targets to the project.  One is a static library (&#8216;FrameRateLibrary&#8217; in my case), and the other is an application (&#8216;FrameRateLibraryTest&#8217;).  FrameRateLibrary represents our library code, and FrameRateLibraryTest will run unit tests on that library.  FrameRateLibrary will also be used by our main application, CoolGame.  In a larger project, you might have multiple versions of these, one for your renderer, one for a sound, one for UI and so on.</p>
<p>Control click on &#8216;Groups &amp; Files&#8217; to add a new group called FrameRateLibraryTest.  Add a second one called FrameRateLibrary.  This will help us keep the code nicely organised. It may seem a bit strange, but we&#8217;ll get FrameRateLibraryTest working before FrameRateLibrary.  This is a fairly common approach with Test Driven Development &#8211; prove the test works before you write the code to pass it.</p>
<p>Control click on the FrameRateLibraryTest Group to add a new C++ file.  I&#8217;ve called it FrameRateLibraryTestMain.cpp.  In the dialog that pops ups, uncheck the &#8216;create a .h file&#8217; option (we won&#8217;t need one), set the location to be {YourProjectPath}/CoolGame/FrameRateLibraryTest, and ensure that it&#8217;s being added to the FrameRateLibraryTest target only.  You&#8217;ll be asked if you want to create a new folder, say yes.</p>
<p>I added the basic code below, then tried to build the test application and it failed.  Apparently the build is trying to include some Object-C code from somewhere, probably a precompiled header file.  If anyone can fill me in on what&#8217;s happening here I&#8217;d appreciate it.  Anyway, rename the file to FrameRateLibraryTestMain.mm and it should build happily.</p>
<pre class="brush:cpp">

int main(int argc, char *argv[])
{
    return 0;
}
</pre>
<p>Next step is to link in UnitTest++ library and add a simple test.  Change FrameRateLibraryTestMain.mm by adding the code below.  Select the FrameRateLibraryTest target, and click the info button (big blue button with an &#8216;i&#8217; in it).  Add libUnitTest++.a both as a dependancy and a linked library.</p>
<pre class="brush:cpp">

#include  "UnitTest++.h"

TEST(FailSpectacularly)
{
    CHECK(false);
}

int main(int argc, char *argv[])
{
    return UnitTest::RunAllTests();
}
</pre>
<p>Now let&#8217;s test what we have.  From the project menu choose &#8220;Set active target&#8230;&#8221; and set it to be our FrameRateLibraryTest target.  Build and Go, and the iPhone Simulator should pop up briefly, but more importantly, if you look at the console output (you may need to switch to debugging view), you&#8217;ll see that our tests ran, and failed spectacularly, as we would expect.  Hurrah!  Note, that clicking on the error takes you straight to the test case that has failed.</p>
<div id="attachment_188" class="wp-caption aligncenter" style="width: 510px"><a href="http://acornheroes.com/wp-content/uploads/2009/06/spectacularfail1.jpg"><img class="size-full wp-image-188" title="spectacularfail1" src="http://acornheroes.com/wp-content/uploads/2009/06/spectacularfail1.jpg" alt="Failure, excellent!" width="500" height="111" /></a><p class="wp-caption-text">Failure, excellent!</p></div>
<p style="text-align: center;">
<p>So, to recap.  We have a separate application that runs tests, which is linked to the UnitTest++ static library.  We can run the application to run our test code.  We have two things left to do:</p>
<ol>
<li>Set up our FrameRateLibrary library, and tests for it, and</li>
<li>Run the tests as part of the main (CoolGame) target&#8217;s build process.</li>
</ol>
<p>Let&#8217;s tackle the second of those problems first.  Switch the active target back to CoolGame (from the Project menu).  Control click on CoolGame target, and choose &#8216;Add new build phase | New Run script&#8217;.  Get info on the run script phase, either by clicking the &#8216;i&#8217; button as we did before, or control clicking on the CoolGame target and choosing &#8216;Get Info&#8217;.  In the info dialog, add:</p>
<pre class="brush:cpp">
$TARGET_BUILD_DIR/FrameRateLibraryTest.app/FrameRateLibrary
</pre>
<p>Build and go now, and this fails, but not in the way we want.  This problem caused me some grief until I realised that the problem was my script trying to run an iPhone application as a Mac one.  Oops.  What we actually need is to get the iPhone simulator to run the test application for us.  After much gnashing of teeth (and some of googling), I found a description of what to do on <a href="http://cocoawithlove.com/2008/11/automated-user-interface-testing-on.html">CocoaWithLove</a>, using a trick from the <a href="http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting">Google Toolbox for Mac</a>.  So the final script ends up looking like:</p>
<pre class="brush:cpp">

export DYLD_ROOT_PATH="$SDKROOT"
export DYLD_FRAMEWORK_PATH="$CONFIGURATION_BUILD_DIR"
export IPHONE_SIMULATOR_ROOT="$SDKROOT"
export CFFIXED_USER_HOME="$USER_LIBRARY_DIR/Application Support/iPhone Simulator/User"
$TARGET_BUILD_DIR/FrameRateLibraryTest.app/FrameRateLibraryTest -RegisterForSystemEvents
</pre>
<p>If you try to build now, the build should fail (in a good way), pointing to the test that&#8217;s (deliberately) failing.  This is a good thing!  Let&#8217;s &#8216;fix&#8217; the test by removing it in FrameRateLibraryTestMain.mm, and next time we build we&#8217;ll get a nice green tick.  Note, you may need to &#8216;get info&#8217; on the CoolGame target, and add FrameRateLibraryTest as a dependency, otherwise, when you change the code in FrameRateLibraryTestMain.mm, it won&#8217;t recompile it when you build the CoolGame application.</p>
<p>OK, one last thing to do, let&#8217;s actually put in place a useful test of our static library.  Get Info on FrameRateLibraryTest, and add FrameRateLibrary as both a linked library and a dependancy.  Let&#8217;s make out test code for the library. As a proof of concept, let&#8217;s create a test that asks the library for our application&#8217;s frame rate &#8211; 60 frames per second in this case.  Add the following to FrameRateLibraryTestMain.mm:</p>
<pre class="brush:cpp">

#include "FrameRateLibrary.h"

TEST(CheckFrameRate)
{
     CHECK_EQUAL(60, GetFrameRate());
}
</pre>
<p>With our test done, we can write the code that it&#8217;s testing.  Add a FrameRateLibrary.cpp file (and .h) to the FrameRateLibrary group  In the dialog that pops up, choose {YourProjectPath}/CoolGame/FrameRateLibrary as the location to create the files and ensure they&#8217;re added to the FrameRateLibrary target.</p>
<p>Add the following to FrameRateLibrary.h:</p>
<pre class="brush:cpp">

extern int GetFrameRate();
</pre>
<p>and FrameRateLibrary.cpp:</p>
<pre class="brush:cpp">

#include  "FrameRateLibrary.h"

int GetFrameRate()
{
    return 30;
}</pre>
<p>Note, in the best traditions of TDD, I&#8217;ve set up the test to fail before it succeeds.  This is to prove the test is actually running correctly and is an essential step.  Try building now, and the build fails, highlighting the test case that is broken.  Let&#8217;s fix the GetFrameRate() function to return 60, not the 30 I &#8216;accidentally&#8217; put in there.  build now, and we should be all happy again.</p>
<p>Well almost.  One last thing is to link our FrameRateLibrary into the actual application we&#8217;re creating.  This is fairly simple and uses the techniques we&#8217;ve seen several times already (adding the FrameRateLibrary to our target as a dependancy and a linked library).  When I did this though, the build failed with an unresolved symbol error for GetFrameRate().  The place I&#8217;d used the GetFrameRate() function was in CoolGameAppDelegate.m &#8211; which was being compiled as pure Objective-C due to the .m suffix.  Renaming the file to CoolGameAppDelegate.mm fixed the problem.</p>
<p>Phew!  This was a long post, but we&#8217;ve achieved a lot.  We can set up static library targets, test them and run the tests automatically as part of the build process.  It seems like a lot of work, but in fact it can be set up fairly quickly.  Adding UnitTest++ target and code as part of a project template would make the setup signifcantly easier.  I&#8217;m still learning the ins and outs of iPhone / XCode development as I go, so please feel free to point out areas where I could do things a little bit better.  Full source code for this tutorial can be found <a href="http://www.acornheroes.com/Code/CoolGame.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2009/06/unit-testing-and-linking-static-libraries-with-xcode/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>All aboard the bling train, part one</title>
		<link>http://acornheroes.com/2009/05/all-aboard-the-bling-train-part-one/</link>
		<comments>http://acornheroes.com/2009/05/all-aboard-the-bling-train-part-one/#comments</comments>
		<pubDate>Thu, 21 May 2009 10:03:05 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Particle Systems]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=130</guid>
		<description><![CDATA[There&#8217;s one type of system that&#8217;s present in almost all games, and yet has very little functional value. It&#8217;s pure bling. I&#8217;m talking about particle systems and, when well designed, they can add greatly to the character and style of a game. When implemented well, a particle system can be applied to a wide variety [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s one type of system that&#8217;s present in almost all games, and yet has very little functional value.  It&#8217;s pure bling.  I&#8217;m talking about particle systems and, when well designed, they can add greatly to the character and style of a game.  When implemented well, a particle system can be applied to a wide variety of effects &#8211; rain, fire, explosions, blood, splashes, smoke and even some that might not be so obvious, such as grass or footprints.</p>
<p>Particle systems also lie between the realms of artists and programmers, so they make an appealing option for a company built around two programmers with limited artistic abilities!  So in this article (and the ones that follow on from it) I&#8217;ll jump on the bling train and discuss the design, implementation and optimisation of a particle system engine for the iPhone.  Here&#8217;s my want list of features from a design point of view:</p>
<ul>
<li>The ability to manage a wide range of types of particle systems.</li>
<li>Creating a new particle system should require a minimum of coding, and rely on the underlying engine to handle the more mundane tasks, such as rendering, frustrum culling, memory management and so on.</li>
<li>Particles should be able to act as emitters, generating new particles (or maybe even entire particle systems?)</li>
<li>Rendering should be as fast as is feasible &#8211; the more particles we&#8217;re able to render, the more we can achieve visually.</li>
</ul>
<p>From a technical point of view, there&#8217;s a lot of issues to address:</p>
<ul>
<li>Designing base functionality that can be easily extended with the minimum of code.</li>
<li>Avoiding frequent memory allocation (this can be a significant performance killer).</li>
<li>Choosing between point sprites (fast) and textured quads (more flexible).</li>
<li>Fast floating point operation &#8211; particle systems typically involve massive numbers of vector operations.</li>
<li>How to store and hand off data to OpenGL for maximum efficiency - because of a particle systems dynamic nature, we&#8217;ll be resubmitting our vertex data every frame.</li>
</ul>
<p>So, armed with a set of design goals, it&#8217;s time to do some hunting around for inspiration.  One of the better articles out there is <a href="http://www.gamasutra.com/view/feature/3157/building_an_advanced_particle_.php">this one by John Van Der Burg</a>.  Also, Apple offer some handy tips for good OpenGL performance on the iPhone <a href="http://developer.apple.com/iphone/library/technotes/tn2008/tn2230.html">here</a>.  There&#8217;s also some useful tips in various <a href="http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&amp;field-keywords=game+programming+gems&amp;x=0&amp;y=0">Game Programming Gems</a> books.</p>
<p>Wow, l<a href="http://www.jonathancoulton.com/2007/10/15/portal-the-skinny/">ook at me still talking</a> <a href="http://www.youtube.com/watch?v=Y6ljFaKRTrI">when there’s science to do</a>.  I&#8217;ll wrap this up here and get some coding done so that I can have something pretty to show off next time&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2009/05/all-aboard-the-bling-train-part-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s taking how long?</title>
		<link>http://acornheroes.com/2009/05/its-taking-how-long/</link>
		<comments>http://acornheroes.com/2009/05/its-taking-how-long/#comments</comments>
		<pubDate>Thu, 14 May 2009 21:12:26 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Setting up]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Approval]]></category>
		<category><![CDATA[Developer Program]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=124</guid>
		<description><![CDATA[As we&#8217;ve been setting up this company, a lot of thought has gone into how and when we need to do things so that we can maximise the (spare) time we have to devote to it.  We wanted to enrol in the developer program as a company, rather than as individuals, so we set up [...]]]></description>
			<content:encoded><![CDATA[<p>As we&#8217;ve been setting up this company, a lot of thought has gone into how and when we need to do things so that we can maximise the (spare) time we have to devote to it.  We wanted to enrol in the <a href="http://developer.apple.com/iPhone/program/">developer program</a> as a company, rather than as individuals, so <a href="http://acornheroes.com/?p=122">we set up the company</a> first.  Then came the part we were a bit worried about.  Searching the web, you find <a href="http://www.iphonedevsdk.com/forum/business-legal-app-store/10090-why-so-long-enroll-into-iphone-developer-program-2.html">plenty</a> of <a href="http://www.30daygame.com/2009/05/03/getting-approval/">stories</a> of one or two month waiting times to become enrolled on the program.</p>
<p>Here&#8217;s how it went down for us:</p>
<ul>
<li>Create company on the 9th of May.</li>
<li>Submit for application for developer program on the 10th.</li>
<li>Email from Apple asking for our Certificate of Incorporation on the 12th.</li>
<li>Finally get a chance to fax off the Certificate on the morning of the 14th.</li>
<li>Get a phone call / email from Apple about noon.</li>
<li>Purchase license about 5 minutes later.</li>
<li>Prepare to wait &#8216;up to 48 hours&#8217; for activation code.</li>
<li>It turns up 4 hours later.</li>
<li>Go to the Apple&#8217;s iPhone Dev Center <strong><em>and remember to log out and log back in again </em><span style="font-weight: normal;">to see the update.</span></strong></li>
<li>Done, we have the keys to the Magic Kingdom.</li>
</ul>
<p>That&#8217;s right, the bulk of the process happened in a single day.  Start to finish was only five days, two of which were a weekend, and one of which was lost due to my inability to get close enough to a fax machine.  Thank you Apple, you&#8217;ve made my week, possibly my month.</p>
<p>Now admitedly we haven&#8217;t sorted out all the financial details yet, but we don&#8217;t have an application to sell yet either, so I&#8217;m not too worried.  What we do have is the ability to deploy applications to an iPhone or iPod Touch now, and the first time you do that is a little magical <img src='http://acornheroes.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Sam and I also had a design session last night where we started seriously planning our first two applications.  More on that later.</p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2009/05/its-taking-how-long/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adding Font support in OpenGL</title>
		<link>http://acornheroes.com/2009/04/adding-font-support-in-opengl/</link>
		<comments>http://acornheroes.com/2009/04/adding-font-support-in-opengl/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 08:39:33 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=44</guid>
		<description><![CDATA[*Update* Brandon Mantzey very kindly pointed out a glaring bug in the code accompanying this post&#8230; Never fear, I&#8217;ve tracked down the idiot responsible (me), and it&#8217;s all good now. The bug was actually two bugs &#8211; first I was confusing the width in pixels of a character&#8217;s texture and the space it takes on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>*Update*</strong>  Brandon Mantzey very kindly pointed out a glaring bug in the code accompanying this post&#8230;  Never fear, I&#8217;ve tracked down the idiot responsible (me), and it&#8217;s all good now.  The bug was actually two bugs &#8211; first I was confusing the width in pixels of a character&#8217;s texture and the space it takes on screen.  Secondly I was working from the bottom left corner of a string, where as I should have been working from the top left.  Thanks Brandon for encouraging me to fix this!  The link in the paragraph below now has the updated code.</p>
<p><img class="size-medium wp-image-57 alignright" title="Font test screen shot" src="http://acornheroes.com/wp-content/uploads/2009/04/text-156x300.jpg" alt="Custom fonts in OpenGL" width="156" height="300" />A bit of a change of pace this week as we dive into something more technical.  Code that accompanies this post can be found <a href="http://acornheroes.com/Code/FontTest.zip">here</a>, and is free for you to use as you see fit.</p>
<p>While OpenGL provides a lot of graphical power, it&#8217;s typically at a fairly low level, giving the programmer a set of tools with which they can build higher level, more useful code.  Rendering text is one example of this.  Pretty much every OpenGL application needs to put text on screen at some stage.  But with no built in font rendering support, we&#8217;re left to our own devices.  In this blog I&#8217;ll show you one easy way to get text on screen.  We&#8217;ll end up with something like the screen shot on the right.<br />
<span id="more-44"></span><br />
There&#8217;s a number of different strategies we can use.</p>
<p>One simple option is to use an image editor like Photoshop.  We can generate a texture file with the text &#8216;baked in&#8217;.  It&#8217;s then a reasonably simple process to load the image into a texture and render it.  This is possibly the quickest way to render text on screen.  However, it means we need to know in advance what text we want to render.  Also, every piece of text uses another chunk of texture memory.</p>
<p>A second option is to render the text into a texture on the fly.  Noel Llopis from Snappy Touch describes how this can be done for the iPhone on his <a href="http://gamesfromwithin.com/?p=326">Games from Within blog</a>. While this allows us to generate text on the fly, it still suffers from each piece of text chewing up more texture memory.  We&#8217;re also limited to fonts already installed on the iPhone.</p>
<p>Both of these techniques are useful, but sometimes we need the ability to generate large quantities of text using our own custom font.  What we can do is pre-render our character set into a texture map, and generate text as a series of textured quads, with one letter per quad.  This way we store the font once, and can render as much text as we like.  The trouble here is that we need to store all the font&#8217;s <a href="http://en.wikipedia.org/wiki/Kerning">kerning</a> information.  Now you could delve into all sorts of documentation to get the information you need.  But someone else has already done the heavy lifting for us, and we can reap the rewards.</p>
<p>Paul Nettle has written a nice utility for us that will take any given font and dump out a data file with all the information we need.  His Font Generation tool is Windows based, but most of us can find a Windows machine if we really need to&#8230;</p>
<p>So, enough talking, let&#8217;s get started.  The first thing you&#8217;ll need to do is to choose your font and install it.  There are large numbers of freely available available fonts on the net.  One good source is <a href="http://www.dafont.com">dafont.com</a>.  Next, grab the Font generator from <a href="http://www.paulnettle.com">Paul Nettle&#8217;s site</a>, under the &#8216;Code&#8217; section.  It&#8217;s a fairly simple tool, select the font you want, specify a file to save it to and hit the &#8216;go&#8217; button.  Transfer the generated file to your Mac and add it to the Resources section of your XCode project.</p>
<p>We create a class, CFont, to store our font information.  It&#8217;s constructor takes the path to our font file as an argument.  We can get the path within our application bundle using the following code:</p>
<pre name="code" class="cpp:nogutter:nocontrols">

NSString *galacticaFontPath = [[NSBundle mainBundle]
				pathForResource:@"Battlestar"
				ofType: @"fnt"];
mGalacticaFont = new CFont([galacticaFontPath cStringUsingEncoding:1]);
</pre>
<p>The file is in a simple binary format, so we use fopen() to open it and read out the each character:</p>
<pre name="code" class="cpp:nogutter:nocontrols">

void CCharacterData::Load(FILE *fontFile)
{
	fread(&#038;byteWidth, sizeof(int), 1, fontFile);
	fread(&#038;byteHeight, sizeof(int), 1, fontFile);
	fread(&#038;xOffset, sizeof(int), 1, fontFile);
	fread(&#038;yOffset, sizeof(int), 1, fontFile);
	fread(&#038;screenWidth, sizeof(int), 1, fontFile);
	fread(&#038;screenHeight, sizeof(int), 1, fontFile);

	buffer = new unsigned char[byteWidth * byteHeight];
	fread(buffer, byteWidth * byteHeight, 1, fontFile);
}
</pre>
<p>The array <em>buffer</em> contains the pixel data that we will transfer to our texture map.  The other fields are used to tell us how and were to render the character.  Or in other words, they contain the relevant kerning information that we need.  We load all the character data from the file and store it away for later use.</p>
<p>The next task is to turn this data into a useful texture map.  We calculate the size of texture we need, using the <em>CFont::GetHeightForTexture()</em> method, and allocate a suitably sized data array.  In the code below, each character is added to the array, and we generate and store texture coordinates as we go.  Finally we generate and bind a GL texture using our data array.</p>
<pre name="code" class="cpp:nogutter:nocontrols">

// Allocate texture data
GLubyte *textureData = new GLubyte[textureWidth * textureHeight * 4];

// Should really clear out data array...
int texX = 0;
int texY = 0;

for (i = 0; i < 256; ++i)
{
	if (!mCharacterData[i].isWanted)
	{
		continue;
	}

	if (texX + maxSizeX >= textureWidth)
	{
		texX = 0;
		texY += maxSizeY;
	}

	int offX = texX + cCharacterPadding / 2;
	int offY = textureHeight - 1 - (texY + cCharacterPadding / 2);

	// Calculate texture coordinates for this character
	float widthScale = 1.0f / (float)(textureWidth - 1);
	float heightScale = 1.0f / (float)(textureHeight - 1);

	float left = (float)offX * widthScale;
	float right =
		left + (float)mCharacterData[i].byteWidth * widthScale;

	float top = (float)offY * heightScale;
	float bottom =
		top - (float)mCharacterData[i].byteHeight * heightScale;

	mCharacterData[i].texCoords[0] = left;
	mCharacterData[i].texCoords[1] = bottom;

	mCharacterData[i].texCoords[2] = left;
	mCharacterData[i].texCoords[3] = top;

	mCharacterData[i].texCoords[4] = right;
	mCharacterData[i].texCoords[5] = bottom;

	mCharacterData[i].texCoords[6] = right;
	mCharacterData[i].texCoords[7] = top;

	// Store the pixel data in the texture
	// Should investigate using a single channel texture
	for (int x = 0; x < mCharacterData[i].byteWidth; ++x)
	{
		for (int y = 0; y < mCharacterData[i].byteHeight; ++y)
		{
			int texIndex = ((offY - y) * textureWidth) + (offX + x);
			int charIndex = y * mCharacterData[i].byteWidth + x;

			textureData[4 * texIndex + 0] = 255;
			textureData[4 * texIndex + 1] = 255;
			textureData[4 * texIndex + 2] = 255;
			textureData[4 * texIndex + 3] =
				mCharacterData[i].buffer[charIndex];
		}
	}

	texX += maxSizeX;
}
</pre>
<p>OK, so we have a font texture, what do we do with it?  What we need now is a class, lets call it <em>CGLString</em>, to build our text and render it as needed.  The CGLString constructor takes a string with the text we want to render and the font we want to render it with.  The first time the Render() method is called, we construct a series of textured quads that are textured with the font's texture.  The actual rendering is fairly simple.  We just call the CGLString's Render method:</p>
<pre name="code" class="cpp:nogutter:nocontrols">

mGalacticaText->Render();
</pre>
<p>Inside the Render() method, here's what's going on:</p>
<pre name="code" class="cpp:nogutter:nocontrols">

// Enable texturing, bind the font's texture and set up blending
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mFont->mTexId);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Bind our vertex data
glVertexPointer(2, GL_FLOAT, 0, mVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, mUVs);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

// Draw the text
glDrawElements(GL_TRIANGLES, 6 * mNumberOfQuads, GL_UNSIGNED_BYTE, mIndices);
</pre>
<p>We bind the font texture, enable blending and render the textured quads.  Fairly simple, eh?</p>
<p>And there we have it - your favourite font rendered in OpenGL.  Now what we have here is a good starting point, although there's a lot more we could add here.  A string that will be rendered repeatedly could be rendered using Vertex Buffer Objects for efficiency.  Drop shadows can be added fairly simply.  A useful method would be one that calculates the size of a piece of text.  Then we'll be able to align and justify the text, or scale it if it's too large.  There's lots here we can do.  The code here is a useful basis on which to build.  I plan to post an updated version later to show you what this could be like when fully developed.</p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2009/04/adding-font-support-in-opengl/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Acorn Who?</title>
		<link>http://acornheroes.com/2009/03/acorn-who/</link>
		<comments>http://acornheroes.com/2009/03/acorn-who/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 07:56:49 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[About Us]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://acornheroes.com/?p=13</guid>
		<description><![CDATA[There&#8217;s a bunch of ideas for posts mulling around in my head, but perhaps the best place to begin is, as they say, at the beginning.  So here&#8217;s a quick introduction. Who? There&#8217;s two of us, Sam and George.  &#8221;Sam and George&#8217;s well designed and written software for the iPhone and iPod Touch&#8221; was catchy [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a bunch of ideas for posts mulling around in my head, but perhaps the best place to begin is, as they say, at the beginning.  So here&#8217;s a quick introduction.</p>
<p><strong>Who?</strong></p>
<p>There&#8217;s two of us, Sam and George.  &#8221;Sam and George&#8217;s well designed and written software for the iPhone and iPod Touch&#8221; was catchy and, most surprisingly, available as a domain name, but it was perhaps just a smidge long for a company name, and so we settled on Acorn Heroes instead.  Between us we have over twenty years experience in the <a href="http://www.straylight-studios.com/">gaming</a> and r<a href="http://www.arl.co.nz/">eal time animation</a> business, not to mention six kids, several cats, a dog, rabbit and two very understanding wives.</p>
<p><strong>What?</strong></p>
<p>We&#8217;re developing quality software for the iPhone and iPod Touch.  What do I mean by quality?  Careful design, consideration for the user and solid, reliable code that <a href="http://en.wikipedia.org/wiki/Eat_one's_own_dog_food">we will use ourselves</a>.  While our primary goal is to bring to life some of the hundreds of game ideas floating around in our heads, we&#8217;re also keen to build useful applications that just help to make life easier, more organised, more fun, more meaningful, more&#8230; well, you get the idea.</p>
<p><strong>Where?</strong></p>
<p>Well &#8216;here&#8217;, obviously <img src='http://acornheroes.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Here for us being <a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=dunedin,+nz&amp;ie=UTF8&amp;ll=-44.840291,170.859375&amp;spn=29.399767,63.544922&amp;t=h&amp;z=4">Dunedin</a>, in the lower reaches of New Zealand.  It&#8217;s a lovely place, with a wealth of very talented people, beautiful scenery, and great beer.</p>
<p><strong>When?</strong></p>
<p>Weekday evenings, especially Thursday, because there&#8217;s nothing on TV.  And the odd weekend too.  You see, with families and mortgages, we can&#8217;t quite turn our back on &#8216;<a href="http://tracplus.com/index.aspx">The Man</a>&#8216; just yet.  And besides, in my case &#8216;The Man&#8217; is a friend and good employer.  So this is a part time effort &#8211; although that doesn&#8217;t mean we&#8217;ll sacrifice the quality of our work, just that we need to ensure we work smarter, not harder.</p>
<p><strong>Why?</strong></p>
<p>Partly it&#8217;s the challenge, partly it&#8217;s the prospect of earning some extra money.  Oh, and it could be that the iPhone is one of the coolest toys out there.</p>
<p>So now that you know us so well, what can you expect from this site?  That&#8217;s one of the things we&#8217;re still figuring out.  So feel free to pop in and see what we&#8217;re up to, leave a note, or subscribe to our <a href="feed:http://acornheroes.com/?feed=rss2">RSS feed</a>, and we&#8217;ll come to you!</p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2009/03/acorn-who/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://acornheroes.com/2008/09/hello-world/</link>
		<comments>http://acornheroes.com/2008/09/hello-world/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 13:25:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Welcome]]></category>

		<guid isPermaLink="false">http://acornheroes.com//?p=1</guid>
		<description><![CDATA[Welcome to Acorn Heroes!  There&#8217;s not much to see here for now, we&#8217;re just getting set up.  In fact, if you&#8217;re here reading this, you&#8217;re probably either a friend or family. In the near future we&#8217;ll be putting up details of our plans for world domin&#8230; er&#8230; great products for the iPhone.]]></description>
			<content:encoded><![CDATA[<p>Welcome to Acorn Heroes!  There&#8217;s not much to see here for now, we&#8217;re just getting set up.  In fact, if you&#8217;re here reading this, you&#8217;re probably either a friend or family.</p>
<p>In the near future we&#8217;ll be putting up details of our plans for <span style="text-decoration: line-through;">world domin</span>&#8230; er&#8230; great products for the iPhone.</p>
]]></content:encoded>
			<wfw:commentRss>http://acornheroes.com/2008/09/hello-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

