<?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>Ed&#039;s BlogEd&#039;s Blog</title>
	<atom:link href="http://edmundlong.com/edsBlog/feed/" rel="self" type="application/rss+xml" />
	<link>http://edmundlong.com/edsBlog</link>
	<description>Stuff I&#039;m working on at the moment</description>
	<lastBuildDate>Thu, 26 Apr 2012 09:37:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Graphics DrawTexture</title>
		<link>http://edmundlong.com/edsBlog/graphics-drawtexture/</link>
		<comments>http://edmundlong.com/edsBlog/graphics-drawtexture/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 09:36:34 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Unity3d]]></category>
		<category><![CDATA[unity3d gui]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=376</guid>
		<description><![CDATA[Quick post regarding the Graphics.DrawTexture in Unity3D. Drawing a sprite sheet using specific UV coordinates in the GUI is only possible (pre 3.5) using Graphics.DrawTexture. The API shows how to use it: http://unity3d.com/support/documentation/ScriptReference/Graphics.DrawTexture.html You need to be very careful however when using it within an OnGUI call however, I got caught with this yesterday. The [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fgraphics-drawtexture%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fgraphics-drawtexture%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Quick post regarding the Graphics.DrawTexture in Unity3D. </p>
<p>Drawing a sprite sheet using specific UV coordinates in the GUI is only possible (pre 3.5) using Graphics.DrawTexture. The API shows how to use it: http://unity3d.com/support/documentation/ScriptReference/Graphics.DrawTexture.html </p>
<p>You need to be very careful however when using it within an OnGUI call however, I got caught with this yesterday. The texture was being drawn multiple times, due to the event types that are used in the GUI system. </p>
<p>The important thing to do is to ensure that the texture is only actually drawn within the repaint, the DrawTexture call draws a texture so for the layout, mouse move passes it will also draw the texture!</p>
<pre  class="brush:csharp">
if (Event.current.type == EventType.Repaint)
{
	 Graphics.DrawTexture(screenRect, texture, uvRect, 0, 0, 0, 0, drawColor);
}
</pre>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/graphics-drawtexture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change GUI Label text colour on hover</title>
		<link>http://edmundlong.com/edsBlog/change-gui-label-text-colour-on-hover/</link>
		<comments>http://edmundlong.com/edsBlog/change-gui-label-text-colour-on-hover/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 10:08:04 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=373</guid>
		<description><![CDATA[Hi, Today I ran into a problem whereby I was drawing a GUI label that I want to have a different colour on hover to it&#8217;s normal state. Following the usual steps I altered the style in the GUI skin to have a different hover text colour expecting this to work. However it does not. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fchange-gui-label-text-colour-on-hover%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fchange-gui-label-text-colour-on-hover%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hi,</p>
<p>Today I ran into a problem whereby I was drawing a GUI label that I want to have a different colour on hover to it&#8217;s normal state. Following the usual steps I altered the style in the GUI skin to have a different hover text colour expecting this to work. However it does not. The colour remaining the same even on hover. My draw code is fairly simple, akin to:</p>
<p>GUI.Label(rect,text,style);</p>
<p>So nothing wrong here. After playing around a bit I put in a background texture on the hover in the style to see if this made a difference and low and behold the text colour changed! I do not want a texture though so instead I created a 1&#215;1 pixel texture which is completely alphaed out and used that as a background texture. Naff and pretty hidden behaviour but thats the workaround I found.</p>
<p>Also you need to change the drawing code to draw the item as a GUI.Button instead of a Label.</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/change-gui-label-text-colour-on-hover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update GUI Button text colour Unity</title>
		<link>http://edmundlong.com/edsBlog/update-gui-button-text-colour-unity/</link>
		<comments>http://edmundlong.com/edsBlog/update-gui-button-text-colour-unity/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 12:35:40 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=371</guid>
		<description><![CDATA[I recently had a bit of text that I wanted to be able to click. This is easy to do, just make a GUI.Button with a custom style that has no background and use the text as the GUIContent parameter. However I wanted to change the colour of the text when you hover over the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fupdate-gui-button-text-colour-unity%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fupdate-gui-button-text-colour-unity%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently had a bit of text that I wanted to be able to click. This is easy to do, just make a GUI.Button with a custom style that has no background and use the text as the GUIContent parameter. However I wanted to change the colour of the text when you hover over the text, this proved trickier. I changed the hover text colour but nothing happened. I tried just putting in a background texture for the hover state in the GUI skin for a test and noticed that the text colour changed when I hovered over it!<br />
So the solution that I found is to make a 1&#215;1 transparent texture and use that as the background texture for the hover! Terrible I know but there is no other way I can see to fix it&#8230;</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/update-gui-button-text-colour-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing GUI.Button text colour</title>
		<link>http://edmundlong.com/edsBlog/changing-gui-button-skin/</link>
		<comments>http://edmundlong.com/edsBlog/changing-gui-button-skin/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 12:33:33 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=367</guid>
		<description><![CDATA[I recently had a bit of text that I wanted to be able to click. This is easy to do, just make a GUI.Button with a custom style that has no background and use the text as the GUIContent parameter. However I wanted to change the colour of the text when you hover over the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fchanging-gui-button-skin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fchanging-gui-button-skin%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently had a bit of text that I wanted to be able to click. This is easy to do, just make a GUI.Button with a custom style that has no background and use the text as the GUIContent parameter. However I wanted to change the colour of the text when you hover over the text, this proved trickier. I changed the hover text colour but nothing happened. I tried just putting in a background texture for the hover state in the GUI skin for a test and noticed that the text colour changed when I hovered over it!<br />
So the solution that I found is to make a 1&#215;1 transparent texture and use that as the background texture for the hover! Terrible I know but there is no other way I can see to fix it&#8230;</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/changing-gui-button-skin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making NSAssert work</title>
		<link>http://edmundlong.com/edsBlog/making-nsassert-work/</link>
		<comments>http://edmundlong.com/edsBlog/making-nsassert-work/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 21:28:39 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iTouch]]></category>
		<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=365</guid>
		<description><![CDATA[Hi, NSAssert is handy but it has been annoying me recently as the execution of the debugger doesn&#8217;t stop when an assert is hit. Instead we get a message output to the console and the execution is stopped in the update loop at a later point. When something hits an assertion I want the program [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fmaking-nsassert-work%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fmaking-nsassert-work%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hi,</p>
<p>NSAssert is handy but it has been annoying me recently as the execution of the debugger doesn&#8217;t stop when an assert is hit. Instead we get a message output to the console and the execution is stopped in the update loop at a later point. When something hits an assertion I want the program execution to stop immediately. For some reason beyond me this is disabled in XCode by default. To enable it go to Run->Stop on Objective-C Exceptions</p>
<p>There you go, your exceptions will now work.</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/making-nsassert-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error from Debugger: Failed to launch simulated application: iPhone Simulator failed to install the application.</title>
		<link>http://edmundlong.com/edsBlog/error-from-debugger-failed-to-launch-simulated-application-iphone-simulator-failed-to-install-the-application/</link>
		<comments>http://edmundlong.com/edsBlog/error-from-debugger-failed-to-launch-simulated-application-iphone-simulator-failed-to-install-the-application/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 21:53:05 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=363</guid>
		<description><![CDATA[I got the error below when attempting to Build and Go in XCode. Error from Debugger: Failed to launch simulated application: iPhone Simulator failed to install the application. My app wouldn&#8217;t launch in the iPhone Simulator and the console has little or no feedback. I went through a few steps to fix this, firstly I [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Ferror-from-debugger-failed-to-launch-simulated-application-iphone-simulator-failed-to-install-the-application%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Ferror-from-debugger-failed-to-launch-simulated-application-iphone-simulator-failed-to-install-the-application%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I got the error below when attempting to Build and Go in XCode. </p>
<pre class="brush:text">
Error from Debugger: Failed to launch simulated application: iPhone Simulator failed to install the application.
</pre>
<p>My app wouldn&#8217;t launch in the iPhone Simulator and the console has little or no feedback.</p>
<p>I went through a few steps to fix this, firstly I tried to Clean All Targets but that didn&#8217;t work. What I did that worked was:</p>
<ul>
<li>Close the iPhone Simulator</li>
<li>Open the terminal and execute
<pre class="brush":bash">sudo rm -Rfv ~/Library/Application\ Support/iPhone\ Simulator</pre>
</ul>
<p>Should work now when you Build and Go again.</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/error-from-debugger-failed-to-launch-simulated-application-iphone-simulator-failed-to-install-the-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO: Record a movie from the iPhone Simulator</title>
		<link>http://edmundlong.com/edsBlog/howto-record-a-movie-from-the-iphone-simulator/</link>
		<comments>http://edmundlong.com/edsBlog/howto-record-a-movie-from-the-iphone-simulator/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 21:44:28 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iTouch]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=354</guid>
		<description><![CDATA[This is easy, only a few little steps. 1. First install SIMBL, use the pkg install and choose All Users install. 2. Download the iPhone Simulator Capture 3. Open up the iPhone Simulator and click on the iOS Simulator menu option and select About iOS Simulator. Note down the version number in brackets after the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fhowto-record-a-movie-from-the-iphone-simulator%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fhowto-record-a-movie-from-the-iphone-simulator%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is easy, only a few little steps.</p>
<p>1. First install <a href="http://www.culater.net/software/SIMBL/SIMBL.php">SIMBL</a>, use the pkg install and choose All Users install.</p>
<p>2. Download the <a href="https://github.com/davbeck/iPhone-Simulator-Capture/archives/master">iPhone Simulator Capture</a></p>
<p>3. Open up the iPhone Simulator and click on the iOS Simulator menu option and select About iOS Simulator. Note down the version number in brackets after the main version, it is 235 for me.</p>
<p>4. Open up the iPhone Simulator Capture.xcodeproj, navigate to Info.plist in the project view and update MaxBundleVersion to be the iOS Simulation version noted above.</p>
<p>5. Select Release and Build. You may see a post-build error, this is as the build process attempts to copy the output to two locations, the user SIMBL directory and the all-users SIMBL direction, only one is likely to exist from your install. The plugin should be copied to the SIMBL plugins directory*</p>
<p>6. Restart the Simulator and you&#8217;ll now see a Record menu option! It should be all fairly simple, one thing is that after you record a move you need to manually choose the Save Movie option afterwards, it does not save it to the HD as you go!</p>
<p>Easy!</p>
<p>* You can verify the build completed correctly by going to ~Library/Application Support/SIMBL/Plugins and you&#8217;ll see the file &#8220;iPhone Simulator Capture.bundle&#8221; if the install succeeded. If it isn&#8217;t there then check the user directory ~Users/MYUSERNAME/Library/Application Support/SIMBL/Plugins directory. If it is in neither then you may need to copy the bundle manually, check the iPhone Simulator Capture build/Release directory.</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/howto-record-a-movie-from-the-iphone-simulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notepad starts off-screen</title>
		<link>http://edmundlong.com/edsBlog/notepad-starts-off-screen/</link>
		<comments>http://edmundlong.com/edsBlog/notepad-starts-off-screen/#comments</comments>
		<pubDate>Thu, 19 May 2011 09:34:23 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=352</guid>
		<description><![CDATA[So you&#8217;ve changed you primary, secondary screens and now notepad opens off screen and you can&#8217;t get to it. Alt-tabbing does nothing to fix it, how do you resolve this? The default position for Windows Notepad is stored in this Registry key: HKEY_CURRENT_USER\Software\Microsoft\Notepad Close all open Notepad windows and change the following values as shown: [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fnotepad-starts-off-screen%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fnotepad-starts-off-screen%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>So you&#8217;ve changed you primary, secondary screens and now notepad opens off screen and you can&#8217;t get to it. Alt-tabbing does nothing to fix it, how do you resolve this?</p>
<p>The default position for Windows Notepad is stored in this Registry key:</p>
<p>HKEY_CURRENT_USER\Software\Microsoft\Notepad</p>
<p>Close all open Notepad windows and change the following values as shown:<br />
iWindowPosX : 0<br />
iWindowPosY : 0<br />
iWindowPosDX : 200<br />
iWindowPosDY: 200</p>
<p>This would set default position to top-left. You can resize and position Notepad window later as you wish. </p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/notepad-starts-off-screen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A simple HashedString implementation</title>
		<link>http://edmundlong.com/edsBlog/a-simple-hashedstring-implementation/</link>
		<comments>http://edmundlong.com/edsBlog/a-simple-hashedstring-implementation/#comments</comments>
		<pubDate>Tue, 17 May 2011 10:41:59 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=340</guid>
		<description><![CDATA[Hi, In my first forays into my engine development I&#8217;ve found it necessary to come up with my own simple hashed string implementation. I plan on using this in place of strings wherever possible for identifiers of objects or for storage. My requirements are fairly simple, I want to have an implementation that resolves a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fa-simple-hashedstring-implementation%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fa-simple-hashedstring-implementation%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hi,</p>
<p>In my first forays into my engine development I&#8217;ve found it necessary to come up with my own simple hashed string implementation. I plan on using this in place of strings wherever possible for identifiers of objects or for storage. My requirements are fairly simple, I want to have an implementation that resolves a string to an unsigned integer. In debug I want to be able to identify the string in the debugger so I have a debug only char array that is used to store the original string when passed in.</p>
<p>For my hash functions I used the code from <a href="http://www.partow.net/programming/hashfunctions/">General Purpose Hash Functions</a>. I haven&#8217;t looked at the hashing algorithms in much detail, a lot of the math looks above my head. I chose the DJB hash function as it is described as being one of the most efficient hashing algorithms ever produced. </p>
<p>One of the things I haven&#8217;t considered as of yet is that collisions may be possible. I&#8217;ll have to look at the various hashing implementations and pick the one that looks to be the best choice and come up with a system to cope with clashes. This will probably involve doing some tests on a wide range of strings, for now however I don&#8217;t have many strings and so my implementation will suffice.</p>
<p>Below are the header and implementation of my HashString along with the HashFunctions found at the link above. You may need to fiddle with them slightly to get them working for your purposes but they&#8217;re largely for illustration purposes anyway. These are provided as is, I may find bugs and will endeavour to reupload the fixes.</p>
<p><a href='http://edmundlong.com/edsBlog/wp-content/uploads/2011/05/GeneralHashFunctions.c'>GeneralHashFunctions.c</a><br />
<a href='http://edmundlong.com/edsBlog/wp-content/uploads/2011/05/HashedString.h'>HashedString.h</a><br />
<a href='http://edmundlong.com/edsBlog/wp-content/uploads/2011/05/GeneralHashFunctions.h'>GeneralHashFunctions.h</a></p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/a-simple-hashedstring-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a game engine &#8211; Part 2</title>
		<link>http://edmundlong.com/edsBlog/writing-a-game-engine-part-2/</link>
		<comments>http://edmundlong.com/edsBlog/writing-a-game-engine-part-2/#comments</comments>
		<pubDate>Tue, 03 May 2011 13:19:54 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=333</guid>
		<description><![CDATA[A quick one today, I&#8217;ve got a basic application up and running using the simple framework located here. One interesting thing to note is that Nehe uses global variables for the active, fullscreen and keys variables. I don&#8217;t want to do this. I want to have these as members of an Application class to begin [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fwriting-a-game-engine-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fedmundlong.com%2FedsBlog%2Fwriting-a-game-engine-part-2%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A quick one today, I&#8217;ve got a basic application up and running using the simple framework located <a href="http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01">here</a>.</p>
<p>One interesting thing to note is that Nehe uses global variables for the active, fullscreen and keys variables. I don&#8217;t want to do this. I want to have these as members of an Application class to begin with and eventually I&#8217;ll create an input handler class and also a renderer that may hold onto these. However due to the way in which the windows are created only static non-member functions can be used to handle the callbacks from the window to handle messages like WM_NCCREATE, WM_ACTIVATE, WM_CLOSE, WM_KEYDOWN and so on. To allow a member function to be able to handle these messages you need to do perform some trickery. You need to define two static callback methods that will handle and messages from the window. </p>
<p>Firstly, we need to alter the way in which the window is created. The first thing we need to do is the give the name of one of the static methods you defined as the initial callback i.e. called on creation of the window:</p>
<pre class="brush:cpp">
wc.lpfnWndProc		= &#038;InitialWndProc;						// WndProc Handles Messages
</pre>
<p>The next thing you need to do is to alter the CreateWindowEx call and add change the last parameter from NULL to &#8216;this&#8217;. This last parameter is an optional extra data that is passed to the creation of the window. By passing this we are passing a pointer to the current Application class to the window creation callback.</p>
<p>So I mentioned two static methods earlier. The first method is to handle the creation of the window:</p>
<pre  class="brush:cpp">
static LRESULT CALLBACK InitialWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
		if (Msg == WM_NCCREATE) {
			LPCREATESTRUCT create_struct = reinterpret_cast<LPCREATESTRUCT>(lParam);
			void * lpCreateParam = create_struct->lpCreateParams;
			Application * theApp = reinterpret_cast< Application*>(lpCreateParam);
			SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(theApp));
			SetWindowLongPtr(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&#038;StaticWndProc));
			return theApp->WndProc(hWnd, Msg, wParam, lParam);
		}
		return DefWindowProc(hWnd, Msg, wParam, lParam);
	}
</pre>
<p>Here we are taking the extra data that was passed into the CreateWindowEX, casting it to an Application pointer and then telling hWnd (the handle to the window) what the new user data (GWLP_USERDATA) will be and also WNDPROC will be that will handle messages from now on in. Essentially what this does is that it tells the window that all messages should be sent to the static method StaticWndProc with the user data being theApp (which is cast to a long pointer). Also note the call to theApp->WndProc, this is important later.</p>
<p>The second static method you need to define is the one that will pass on all messages that come to the window during runtime. </p>
<pre class="brush:cpp">
static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
		LONG_PTR user_data = GetWindowLongPtr(hWnd, GWLP_USERDATA);
		Application * theApp = reinterpret_cast< Application*>(user_data);
		return theApp->WndProc(hWnd, Msg, wParam, lParam);
	}
</pre>
<p>This is simple, all it does is take the user data from window that we setup earlier, cast it to the right Application* type and then pass along the callback to the class&#8217;s desired member. </p>
<p>So now we can have a member function on Application like so:</p>
<pre class="brush:cpp">
LRESULT CALLBACK Application::WndProc(	HWND	hWnd,			// Handle For This Window
											UINT	uMsg,			// Message For This Window
											WPARAM	wParam,			// Additional Message Information
											LPARAM	lParam)			// Additional Message Information
	{
		switch (uMsg)									// Check For Windows Messages
		{
			case WM_ACTIVATE:							// Watch For Window Activate Message
			{
				if (!HIWORD(wParam))					// Check Minimization State
				{
					m_active=TRUE;						// Program Is Active
				}
				else
				{
					m_active=FALSE;						// Program Is No Longer Active
				}

				return 0;								// Return To The Message Loop
			}

			case WM_SYSCOMMAND:							// Intercept System Commands
			{
				switch (wParam)							// Check System Calls
				{
					case SC_SCREENSAVE:					// Screensaver Trying To Start?
					case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
					return 0;							// Prevent From Happening
				}
				break;									// Exit
			}

			case WM_CLOSE:								// Did We Receive A Close Message?
			{
				PostQuitMessage(0);						// Send A Quit Message
				return 0;								// Jump Back
			}

			case WM_KEYDOWN:							// Is A Key Being Held Down?
			{
				m_keys[wParam] = TRUE;					// If So, Mark It As TRUE
				return 0;								// Jump Back
			}

			case WM_KEYUP:								// Has A Key Been Released?
			{
				m_keys[wParam] = FALSE;					// If So, Mark It As FALSE
				return 0;								// Jump Back
			}

			case WM_SIZE:								// Resize The OpenGL Window
			{
				reSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
				return 0;								// Jump Back
			}
		}

		// Pass All Unhandled Messages To DefWindowProc
		return DefWindowProc(hWnd,uMsg,wParam,lParam);
	}
</pre>
<p>And have achieved what I wanted, be able to have member variables and a member function be able to handle the various messages that come from the window.</p>
<p>Note: There is no error handling if the Application casting goes wrong, I might add that at some point.</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/writing-a-game-engine-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
