<?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>David Amador</title>
	<atom:link href="http://www.david-amador.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.david-amador.com</link>
	<description>Developer&#039;s Blog</description>
	<lastBuildDate>Fri, 03 May 2013 12:41:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=347</generator>
		<item>
		<title>Puwang is running on PC, releasing it for free</title>
		<link>http://www.david-amador.com/2013/04/puwang-is-running-on-pc-releasing-it-for-free/</link>
		<comments>http://www.david-amador.com/2013/04/puwang-is-running-on-pc-releasing-it-for-free/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 22:35:33 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[puwang]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2219</guid>
		<description><![CDATA[Hey guys, Decided to spend the afternoon making Puwang run on Windows, really don&#8217;t know why but I did it. Took me around 3 hours, mostly because I had to add Mouse and Keyboard controls. I also added support for]]></description>
				<content:encoded><![CDATA[<p>Hey guys,</p>
<p>Decided to spend the afternoon making Puwang run on Windows, really don&#8217;t know why but I did it.<a href="http://www.david-amador.com/wp-content/uploads/2013/04/puwang.jpg" rel="shadowbox[sbpost-2219];player=img;"><img class="alignright size-medium wp-image-2220" alt="puwang" src="http://www.david-amador.com/wp-content/uploads/2013/04/puwang-300x200.jpg" width="300" height="200" /></a><br />
Took me around 3 hours, mostly because I had to add Mouse and Keyboard controls. I also added support for an Xbox360 controller to control the game, it&#8217;s very cool. You can&#8217;t use the gamepad to control menus though, sorry.</p>
<p>I decided to release it for Windows for free, because the game isn&#8217;t exactly designed for PC&#8217;s, has a smaller resolution, runs on window mode only and doesn&#8217;t have Leaderboards.</p>
<p>Here&#8217;s a video I just made of the PC version</p>
<p><object width="420" height="315" 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/1UkJHDLfI-A?hl=en_US&amp;version=3" /><param name="allowfullscreen" value="true" /><embed width="420" height="315" type="application/x-shockwave-flash" src="http://www.youtube.com/v/1UkJHDLfI-A?hl=en_US&amp;version=3" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<blockquote><p>The Game requires some external frameworks to be installed, so in event it crashes at start please make sure all dependencies are correctly installed.<br />
-<a href="http://www.microsoft.com/en-us/download/details.aspx?id=5555">Microsoft Visual C++ 2010 Redistributable Package (x86) </a><br />
-<a href="http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx">OpenAL</a><br />
-<a href="http://www.microsoft.com/en-us/download/details.aspx?id=35">DirectX9</a></p></blockquote>
<p>So I hope you have fun, let me know what you think.</p>
<p>Don&#8217;t forget that you can still grab the original iOS (Universal) game <a href="https://itunes.apple.com/us/app/puwang/id566365237?mt=8">here</a>.</p>
<p>Download:<br />
<a href="https://dl.dropboxusercontent.com/u/65262/Puwang/Puwang_win32.rar">Puwang &#8211; (Windows) &#8211; 16.1MB</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2013/04/puwang-is-running-on-pc-releasing-it-for-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL 2D Independent Resolution Rendering</title>
		<link>http://www.david-amador.com/2013/04/opengl-2d-independent-resolution-rendering/</link>
		<comments>http://www.david-amador.com/2013/04/opengl-2d-independent-resolution-rendering/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 10:22:22 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[independent]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[Rendering]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2191</guid>
		<description><![CDATA[Around two years ago I made a tutorial for XNA in which you could render 2D games scaled to the current window resolution with proper letter-boxes or pillar-boxes. As many know since then I moved to C++ and OpenGL, and]]></description>
				<content:encoded><![CDATA[<p>Around two years ago I made a <a href="http://www.david-amador.com/2010/03/xna-2d-independent-resolution-rendering/" title="XNA 2D Independent Resolution Rendering">tutorial for XNA</a> in which you could render 2D games scaled to the current window resolution with proper letter-boxes or pillar-boxes.</p>
<p>As many know since then I moved to C++ and OpenGL, and ocasionally people ask me &#8220;Can you still do that independent resolution thing?&#8221;, and yes it&#8217;s perfectly possible. I&#8217;ve used this on all latest Windows, Mac and iOS, in case you are wondering.</p>
<p>The code is quite straight forward actually. In case you are not familiar with what we are trying to achieve here I recommend my other tutorial first, where I explain this is more detail.</p>
<p>So first we need to set our viewport with proper letterbox or pillar box, if required.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #666666;">// Let's start by clearing the whole screen with black</span>
glClearColor<span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span>, <span style="color:#800080;">0.0f</span>, <span style="color:#800080;">0.0f</span>, <span style="color:#800080;">1.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>	
glClear<span style="color: #008000;">&#40;</span>GL_COLOR_BUFFER_BIT <span style="color: #000040;">|</span> GL_DEPTH_BUFFER_BIT<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// Both these values must be your real window size, so of course these values can't be static</span>
<span style="color: #0000ff;">int</span> screen_width <span style="color: #000080;">=</span> <span style="color: #0000dd;">1024</span><span style="color: #008080;">;</span>  
<span style="color: #0000ff;">int</span> screen_height <span style="color: #000080;">=</span> <span style="color: #0000dd;">728</span><span style="color: #008080;">;</span> 
&nbsp;
<span style="color: #666666;">// This is your target virtual resolution for the game, the size you built your game to</span>
<span style="color: #0000ff;">int</span> virtual_width<span style="color: #000080;">=</span><span style="color: #0000dd;">1280</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> virtual_height<span style="color: #000080;">=</span><span style="color: #0000dd;">720</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">float</span> targetAspectRatio <span style="color: #000080;">=</span> virtual_width<span style="color: #000040;">/</span>virtual_height<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// figure out the largest area that fits in this resolution at the desired aspect ratio</span>
<span style="color: #0000ff;">int</span> width <span style="color: #000080;">=</span> screen_width <span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> height <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>width <span style="color: #000040;">/</span> targetAspectRatio <span style="color: #000040;">+</span> <span style="color:#800080;">0.5f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>height <span style="color: #000080;">&gt;</span> screen_height <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
   <span style="color: #666666;">//It doesn't fit our height, we must switch to pillarbox then</span>
    height <span style="color: #000080;">=</span> screen_height <span style="color: #008080;">;</span>
    width <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>height <span style="color: #000040;">*</span> targetAspectRatio <span style="color: #000040;">+</span> <span style="color:#800080;">0.5f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #666666;">// set up the new viewport centered in the backbuffer</span>
<span style="color: #0000ff;">int</span> vp_x <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>screen_width  <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span>width <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> vp_y <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>screen_height <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span>height<span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
glViewport<span style="color: #008000;">&#40;</span>vp_x,vp_y,width,height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>Now that our viewport is set we should set our 2d perspective</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #666666;">// Now we use glOrtho</span>
glMatrixMode<span style="color: #008000;">&#40;</span>GL_PROJECTION<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glPushMatrix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glLoadIdentity<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #666666;">// This function is for Mac and Windows only, if you are using</span>
<span style="color: #666666;">// iOS you should use glOrthof instead</span>
glOrtho<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, screen_width, screen_height, <span style="color: #0000dd;">0</span>, <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span>, <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #ff0000; font-style: italic;">/*if on iOS*/</span> <span style="color: #666666;">//glOrthof(0, screen_width, screen_height, 0, -1, 1);</span>
glMatrixMode<span style="color: #008000;">&#40;</span>GL_MODELVIEW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glPushMatrix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glLoadIdentity<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>So now we should push the transformations before actually drawing anything</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Push in scale transformations</span>
glMatrixMode<span style="color: #008000;">&#40;</span>GL_MODELVIEW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glPushMatrix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//Now to calculate the scale considering the screen size and virtual size</span>
<span style="color: #0000ff;">float</span> scale_x <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>screen_width<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span>virtual_width<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">float</span> scale_y <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>screen_height<span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span><span style="color: #008000;">&#41;</span>virtual_height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glScalef<span style="color: #008000;">&#40;</span>scale_x, scale_y, <span style="color:#800080;">1.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>We can now proceed to drawing everything we want, that&#8217;s is really up to you now.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Place your sprites drawing code here</span>
<span style="color: #666666;">// Example</span>
glBegin<span style="color: #008000;">&#40;</span>GL_TRIANGLES<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glColor3f<span style="color: #008000;">&#40;</span><span style="color:#800080;">0.1</span>, <span style="color:#800080;">0.2</span>, <span style="color:#800080;">0.3</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glVertex3f<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>,  <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glVertex3f<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">50</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glVertex3f<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">50</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glEnd<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>I really don&#8217;t recommend using glBegin() and glEnd(), this was just for simplicity, you should use glDrawElements or glDrawArrays</p>
<p>After you finish you drawing code we can proceed to the rest</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// This pops those matrices for the scale transformations.</span>
glMatrixMode<span style="color: #008000;">&#40;</span>GL_MODELVIEW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glLoadIdentity<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glPopMatrix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>//Now to finish we should end our 2D perspective</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">glMatrixMode<span style="color: #008000;">&#40;</span>GL_PROJECTION<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glPopMatrix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>   
glMatrixMode<span style="color: #008000;">&#40;</span>GL_MODELVIEW<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
glPopMatrix<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>And that&#8217;s pretty much it. I have this code on my games and it works fine, at least for what I usually need. Feel free to tweak it around for your needs. Hope this helps to get a picture on how to achieve this effect. Let me know if you find any bug.</p>
<p>Here&#8217;s an example of what you might achieve with this</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1280x720_Res_1280x800.jpg" rel="shadowbox[sbpost-2191];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1280x720_Res_1280x800-300x193.jpg" alt="Base_1280x720_Res_1280x800" width="300" height="193" class="alignright size-medium wp-image-805" /></a><a href="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1280x720_Res_800x600.jpg" rel="shadowbox[sbpost-2191];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1280x720_Res_800x600-300x234.jpg" alt="Base_1280x720_Res_800x600" width="300" height="234" class="alignright size-medium wp-image-803" /></a><a href="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1024x768_Res_800x600.jpg" rel="shadowbox[sbpost-2191];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1024x768_Res_800x600-300x234.jpg" alt="Base_1024x768_Res_800x600" width="300" height="234" class="alignnone size-medium wp-image-798" /></a><a href="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1280x720_Res_480x640.jpg" rel="shadowbox[sbpost-2191];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1280x720_Res_480x640-219x300.jpg" alt="Base_1280x720_Res_480x640" width="219" height="300" class="alignright size-medium wp-image-802" /></a><a href="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1024x768_Res_1280x720.jpg" rel="shadowbox[sbpost-2191];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2010/03/Base_1024x768_Res_1280x720-300x175.jpg" alt="Base_1024x768_Res_1280x720" width="300" height="175" class="alignright size-medium wp-image-800" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2013/04/opengl-2d-independent-resolution-rendering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updates, development and new feed url</title>
		<link>http://www.david-amador.com/2013/04/updates-development-and-new-feed-url/</link>
		<comments>http://www.david-amador.com/2013/04/updates-development-and-new-feed-url/#comments</comments>
		<pubDate>Sat, 20 Apr 2013 11:01:44 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[back pain]]></category>
		<category><![CDATA[darys legend]]></category>
		<category><![CDATA[puwang]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2165</guid>
		<description><![CDATA[Almost 4 months without a post, this is the first time it happened. It was nothing in particular that held me back, I just kept postponing and, to be honest, I only write posts when I have something I really]]></description>
				<content:encoded><![CDATA[<p>Almost 4 months without a post, this is the first time it happened.<br />
It was nothing in particular that held me back, I just kept postponing and, to be honest, I only write posts when I have something I really want to write about.</p>
<blockquote><p>Before going into the rest of the post, I would like to ask people to update my feed url on your RSS readers. I always used Feedburner to redirect feeds, and with Google Reader going down I decided to start switching, so in your new FeedsReader use this address: (<a href="http://www.david-amador.com/feed/">http://www.david-amador.com/feed/</a>). I didn&#8217;t deactivated the old one, so they will work both for now (if I didn&#8217;t broke anything). Also, give Feedly a try in case you haven&#8217;t found a replacement for Reader.</p></blockquote>
<p>So what&#8217;s been happening? I&#8217;ll try to compress here a bunch of things that I&#8217;ve been doing, if you want to know.</p>
<p><strong>Puwang new update</strong></p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2013/04/puwang_screen.jpg" rel="shadowbox[sbpost-2165];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2013/04/puwang_screen-300x225.jpg" alt="puwang_screen" width="300" height="225" class="alignright size-medium wp-image-2167" /></a>If you follow my twitter you may already know this, but I released a new update with two new game modes (yes, free, no IAP&#8217;s). A Hard and Survivor mode, which is pretty much self-explanatory, the Hard mode has more enemies and they spawn anywhere on the screen. Survivor mode is the same as normal but your ship won&#8217;t evolve, making it harder to survive.</p>
<p>I did these two modes mainly because while it can can be fun to pick up the game once in a while, once you get used to the controls anytime I played it I was like &#8220;God, I wish the faster action started faster&#8221;, because the game gets incrementally harder to play, but it starts out pretty easy. This was also something many told me personally or via twitter, so I decided to make it.<br />
New modes have their own separate Leaderboards too.</p>
<p>There&#8217;s an extra feature I&#8217;m considering for Puwang, but for a later time, which is recording the game, so you can share it via Twitter, Facebook, etc. I think it might be a nice addition, but it will take some time, whenever I decide to start working on it anyway. It&#8217;s just something on my head.</p>
<p>There&#8217;s one extra improvement, which is the rendering pipeline was written to be faster, so less battery usage, check Dary&#8217;s Legend below for more info.</p>
<p><a href="https://itunes.apple.com/app/id566365237?mt=8&#038;affId=1860684">iTunes link</a></p>
<p><strong>Dary&#8217;s Legend</strong></p>
<p>This has been my main project for a long time now, I&#8217;ve been making posts about it on the game page itself, felt a bit weird to replicated them here, because I assume if anyone is interesting in knowing about the game they will probably check the official places anyway. </p>
<p>But related to development I might say I made some considerable improvements on the rendering pipeline, gained 10FPS in debug mode, while the game runs at 60FPS in release I always had low FPS in debug, since my pc is old, around 20-25FPS. After the changes I get 30-35FPS). </p>
<p>I achieved this tweaking two sections. First I cached a bunch of  calculations on my Sprite class, most of they where done in each draw, which was stupid since most of the time I only needed them to be done when an image change occurs or a scale. <a href="http://www.david-amador.com/wp-content/uploads/2013/04/triangles.jpg" rel="shadowbox[sbpost-2165];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2013/04/triangles-300x173.jpg" alt="triangles" width="300" height="173" class="alignright size-medium wp-image-2178" /></a></p>
<p>The other tweak was using glDrawElements instead of glDrawArrays and sending vertex data with indices. I&#8217;m not entirely sure this will lead to immediate FPS improvement but at least less data is send to GPU. </p>
<p>So for a quad I use GL_TRIANGLES with 4 points. Now has you know GL_TRIANGLES required 3 points per triangle, so since a Quad is two triangle this would required 6 points. So I send the 4 points with 6 indices instead. This proved particularly good for iOS devices. Much less GPU usage, which leads to a smoother game and less battery usage. </p>
<p>I pushed both this improvements to Puwang too. </p>
<p>Right now I have the next update almost finished, it&#8217;s just missing art, so it&#8217;s on the artist&#8217;s hands now, I&#8217;m already working on the next feature which are Pets.</p>
<p><a href="http://www.daryslegend.com">DL Official site</a></p>
<p><strong>New layout</strong></p>
<p>If you are reading this from a feed disregard the rest of this section. As you may noticed the site has a new layout, I honestly don&#8217;t know if it&#8217;s better or worst, for now I like it. The older one had too much stuff going around, this is a bit cleaner. I&#8217;m a fan of darker themes, but it&#8217;s hard to find good ones, well, for free at least. I payed for some in the past, but the problem is as time goes by and WordPress updates they start breaking everywhere. Hope you like it, leave comments if you don&#8217;t. </p>
<p><strong>Back pain</strong></p>
<p>So as any programmer we eventually develop some back pain due to the very long hours we are forced to work in front of computers. I started having this occasional really intense pain for little more than a year. Not frequent, like every 2 months, lasted only like 2-3 days but to the point where I could barely walk. Of course I went to a doctor, &#8220;Drink more water he said, that&#8217;s just kidneys&#8221;. It made some sense so I decided to drink even more water, I usually keep a bottle near the computer I already drink some, but decided to drink even more. Around 3 weeks ago I had to take a 3-4 hour bus trip, the pain kicked in again, bad. Someone recommended me going to one of those guys that check your bones, if everything is ok, really don&#8217;t know the name since it&#8217;s not an official job. I went there, the guy told me I had a rib making pressure into my right kidney. He did his thing and I felt immediate relief, like magic really, of course it was only momentarily, but after that I only felt discomfort of him pulling the rib to the right place. I honestly felt bad for not having more money with me at the time, he didn&#8217;t even want any, but I gave him anyway. He told me this doesn&#8217;t mean I&#8217;m cured, I still have to control the amount of hours I spend on the computer, drink water, exercise, the usually actually, and wait and see if the really intense pain comes back. I have my movements a bit restricted now since I have to be careful for some weeks to make sure the rib doesn&#8217;t get in the way again. I feel some discomfort in that area sometimes but nothing compared to the pain it was before, and only in a couple of months will I know if it actually helped in the long run. But for now it&#8217;s much better, I&#8217;ve been able to work, I just can&#8217;t lift anything heavy for now.</p>
<p><strong>Still here?</strong></p>
<p>I&#8217;ve been playing some games but I&#8217;ll leave that to another separate post. Maybe two posts on the same day? Anyway I&#8217;ll try to keep this more updated and as always thanks for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2013/04/updates-development-and-new-feed-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>hasta la vista, 2012</title>
		<link>http://www.david-amador.com/2012/12/hasta-la-vista-2012/</link>
		<comments>http://www.david-amador.com/2012/12/hasta-la-vista-2012/#comments</comments>
		<pubDate>Sat, 22 Dec 2012 16:41:45 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2120</guid>
		<description><![CDATA[So the world did no end, how about that? This is it, the last post I&#8217;ll make this year. It&#8217;s been a wild year, much much (probably too many) work this year. Some recap: -We finally released DL into the]]></description>
				<content:encoded><![CDATA[<p>So the world did no end, how about that? </p>
<p>This is it, the last post I&#8217;ll make this year.</p>
<p>It&#8217;s been a wild year, much much (probably too many) work this year.</p>
<p>Some recap:</p>
<p>-We finally <a title="Dary’s Legend alpha released" href="http://www.daryslegend.com">released DL into the wild in beta</a> form which was a great feeling, especially since it looks like I&#8217;m working on this for ages now. General feedback has been great and that&#8217;s always a motivator.</p>
<p>-My small Ludum Dare experience turned out into a small but highly addictive iOS game, <a title="Puwang is out on the App Store" href="http://www.david-amador.com/2012/10/puwang-is-out-on-the-app-store/">Puwang</a>, well at least that&#8217;s what people tell me. I was positively surprised with that.</p>
<p>And&#8230;that&#8217;s pretty much it.</p>
<p>For next year there will be a patch for Dary&#8217;s Legend in the first weeks, much of the delay has been my fault (working on the boiling/crafting system) but some of the issues players have been telling us have been addressed.</p>
<p>I will now proceed to take some days off work, so I&#8217;ll finally have some time to kickback, relax and play some of those awesome games that where released this year.</p>
<p>Games you <span style="text-decoration: underline;">should</span> try:<br />
FTL<br />
Little Inferno<br />
Diablo 3<br />
Super Hexagon</p>
<p>Movies that I liked:<br />
The Avengers<br />
The Dark Knight Rises<br />
Looper<br />
The Cabin in the Woods </p>
<p>So Merry Christmas and Happy New Year!</p>
<p><img class="alignnone size-full wp-image-2121" alt="david_xmas_card" src="http://www.david-amador.com/wp-content/uploads/2012/12/david_xmas_card.jpg" width="457" height="600" /><br />
(Thanks to <a href="http://www.twitter.com/_m0r3n4">Rita</a> for doing this sweet wabbit with a christmas hat)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/12/hasta-la-vista-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dary&#8217;s Legend alpha released</title>
		<link>http://www.david-amador.com/2012/12/darys-legend-alpha-released/</link>
		<comments>http://www.david-amador.com/2012/12/darys-legend-alpha-released/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 13:38:51 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[darys legend]]></category>
		<category><![CDATA[IPad]]></category>
		<category><![CDATA[Mac OSX]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2090</guid>
		<description><![CDATA[Yay, so a milestone was reached with this project. If you follow my blog you probably already know that between small projects like Puwang and other mandatory freelancing stuff my big project in hands for these past few months is]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.daryslegend.com"><img class="alignnone  wp-image-2097" title="Dary's Legend" src="http://www.david-amador.com/wp-content/uploads/2012/12/header.jpg" alt="" width="614" height="282" /></a></p>
<p>Yay, so a milestone was reached with this project. If you follow my blog you probably already know that between small projects like <a title="Puwang is out on the App Store" href="http://www.david-amador.com/2012/10/puwang-is-out-on-the-app-store/">Puwang</a> and other mandatory freelancing stuff my big project in hands for these past few months is Dary&#8217;s Legend, a roguelike.</p>
<p>Around two months ago I coincidentally bumped into a conversation about funding and the whole kickstarter thing where one of Desura staff members was participating, and while talking about my own problems funding a whole game out of my pocket he mentioned that he knew the game and that Desura&#8217;s Alpha Funding might be a good place for it.</p>
<p>So yesterday we released it, and you can buy the game right now, get an alpha build with a nice discount while it doesn&#8217;t reach the final build and help us funding the development along the way.</p>
<p>The build is relatively stable, no major crashes crashes that we know and there&#8217;s a Windows and Mac build.</p>
<p><a title="Dary's Legend on Desura" href="http://www.desura.com/games/darys-legend"><img style="border: none;" src="http://button.desura.com/play/outline/games/17158.png" alt="Desura Digital Distribution" width="252" height="54" border="0" /></a></p>
<p><em>Coder-Side-Notes</em></p>
<p>Personally, and although I&#8217;m happy that I managed to get a Windows and Mac build released side-by-side I&#8217;m also a bit sad that I haven&#8217;t been able to release it simultaneously for Linux as well.</p>
<p>Initially my thought was, &#8220;Windows only till the final release, I&#8217;ll deal with ports later&#8221;. But the market is harsh and getting into 2 different platforms can get you more chances of selling.</p>
<p>There wasn&#8217;t a Mac build until a month ago, but I decided to take a couple of days, created a Xcode project and build the source.<br />
After a few tweaks and hacks I had it running, why not release it? So right now, by using Git, since projects are already configured on Windows and Mac, I just need to commit changes, boot the other machine, build and that&#8217;s it.</p>
<p>Linux is a little trickier, first I have little experience with that OS. Second I never had my engine running there, missing all kind of abstraction layers, directory access, mouse, keyboard, etc. And honestly right now I don&#8217;t have the time to be handling 3 versions at the same time. So Linux is probably going to be off the table until the final build is done.</p>
<p>Oh, another thing is that, after getting it running on Mac, I tried building for iPad, the game runs almost perfectly at 60FPS @1024&#215;768, apart from the interface not being prepared for Touch of course, it was designer for a 2 button mouse. So there might be an iPad eventually.</p>
<p>This whole process has made me consider if I should&#8217;t find an &#8220;OK&#8221; (cause VS is the best) cross-platform IDE, like Eclipse or so. Configuring a project on Visual Studio, than on Xcode and another one on Linux (whatever I might end using) is an nightmare. On the other hand I could also take a plunge into makefiles with CMake&#8230;guess I&#8217;ll leave that to another project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/12/darys-legend-alpha-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ati Radeon HD 4000 drivers for Windows 8, fix for slow OpenGL games, yes, including Minecraft</title>
		<link>http://www.david-amador.com/2012/10/ati-radeon-hd-4000-drivers-for-windows-8-fix-for-slow-opengl-games-yes-including-minecraft/</link>
		<comments>http://www.david-amador.com/2012/10/ati-radeon-hd-4000-drivers-for-windows-8-fix-for-slow-opengl-games-yes-including-minecraft/#comments</comments>
		<pubDate>Wed, 31 Oct 2012 09:02:55 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Application & Software]]></category>
		<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[ati radeon]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[minecraft]]></category>
		<category><![CDATA[windows 8]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2070</guid>
		<description><![CDATA[I&#8217;m making this post solely for the purpose of people who can&#8217;t find a solution for this. If you have a Ati Radeon HD 4000 or lower like me you&#8217;ll notice that there are no drivers for Windows 8 listed]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m making this post solely for the purpose of people who can&#8217;t find a solution for this.</p>
<p>If you have a Ati Radeon HD 4000 or lower like me you&#8217;ll notice that there are no drivers for Windows 8 listed when you go to the AMD website. AMD only supports Windows 8 from the 5000+. And the stock ones from Windows 8 are useless, mostly on the OpenGL side, some games won&#8217;t even load, or run really slowly, like your beloved Minecraft which uses OpenGL. The stock drivers won&#8217;t even allow 2048&#215;2048 textures <img src='http://www.david-amador.com/wp-includes/images/smilies/icon_neutral.gif' alt=':|' class='wp-smiley' /> </p>
<p>After some digging around the internet I found this article for old legacy drivers under Windows 8, weirdly not displayed on the list. So here you have it, it worked properly for me.</p>
<p><a href="http://support.amd.com/us/kbarticles/Pages/catalystlegacywin8.aspx">http://support.amd.com/us/kbarticles/Pages/catalystlegacywin8.aspx</a></p>
<p>Hardware:<br />
AMD Radeon HD 4000 Series<br />
AMD Radeon HD 3000 Series<br />
AMD Radeon HD 2000 Series<br />
AMD Mobility Radeon HD 4000 Series<br />
AMD Mobility Radeon HD 3000 Series<br />
AMD Mobility Radeon HD 2000 Series</p>
<p>Operating Systems:<br />
Windows 8 64-bit Edition<br />
Windows 8 32-bit Edition</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/10/ati-radeon-hd-4000-drivers-for-windows-8-fix-for-slow-opengl-games-yes-including-minecraft/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Puwang is out on the App Store</title>
		<link>http://www.david-amador.com/2012/10/puwang-is-out-on-the-app-store/</link>
		<comments>http://www.david-amador.com/2012/10/puwang-is-out-on-the-app-store/#comments</comments>
		<pubDate>Wed, 10 Oct 2012 12:05:23 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[app store]]></category>
		<category><![CDATA[puwang]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2048</guid>
		<description><![CDATA[So tonight, while I was sleeping, Puwang was approved and released on the App Store. I made a small gameplay video where, directly from the screen. and there&#8217;s another one, offscreen, on a real iDevice here Spread the word, buy]]></description>
				<content:encoded><![CDATA[<p>So tonight, while I was sleeping, Puwang was approved and released on the App Store.</p>
<p><a href="http://itunes.apple.com/us/app/puwang/id566365237?l=en&amp;mt=8"><img src="http://www.david-amador.com/wp-content/uploads/2012/10/puwang_icon.png" alt="" title="Puwang" width="179" height="178" class="alignnone size-full wp-image-2049" style="border:none;" /></a></p>
<p>I made a small gameplay video where, directly from the screen.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/EVFTiA2BZiQ" frameborder="0" allowfullscreen></iframe></p>
<p>and there&#8217;s another one, offscreen, on a real iDevice <a href="https://www.youtube.com/watch?v=AIiKBVTiEhM&#038;feature=g-upl" rel="shadowbox[sbpost-2048];player=swf;width=640;height=385;">here</a></p>
<p>Spread the word, buy it if you like =)</p>
<p>App Store Link: <a href="http://itunes.apple.com/us/app/puwang/id566365237?l=en&amp;mt=8">http://itunes.apple.com/us/app/puwang/id566365237?l=en&amp;mt=8</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/10/puwang-is-out-on-the-app-store/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Puwang &#8211; a 5 day work</title>
		<link>http://www.david-amador.com/2012/09/puwang-a-5-day-work/</link>
		<comments>http://www.david-amador.com/2012/09/puwang-a-5-day-work/#comments</comments>
		<pubDate>Fri, 28 Sep 2012 19:03:40 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[puwang]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2023</guid>
		<description><![CDATA[Hi, how&#8217;s everyone doing? So this was a different week for me. It&#8217;s been a long time that I had the chance to work on a small prototype or a 48H competition because of my work on Dary&#8217;s Legend so]]></description>
				<content:encoded><![CDATA[<p>Hi, how&#8217;s everyone doing?</p>
<p>So this was a different week for me. It&#8217;s been a long time that I had the chance to work on a small prototype or a 48H competition because of my work on Dary&#8217;s Legend so I decided to stop for a couple of days and do something else.</p>
<p>Also my cat&#8217;s been quite sick, and between the Vet and taking care of him, working on a fun project gave me more time do everything.</p>
<p>Since I love shump games I decided to do one. The idea is simple, you are in a arena with your ship and you just blast enemies away.</p>
<p>Initially I worked around 6-8hours on this back in August but had to drop it because of some much other work I had, so it wasn&#8217;t until this monday I grabbed it again.</p>
<p>I decided to make the game for iOS because it&#8217;s easier to make prototypes there and I can carry them around everywhere, playing them, to see if they are any good.</p>
<p>Actually the first 8 hours where quite productive and this is what I had after that time:</p>
<p><iframe src="http://www.youtube.com/embed/sfxpNnfoZQI" frameborder="0" width="420" height="315"></iframe></p>
<p>So during these past 5 days I polished it a little, grabbed myself a notepad and hand-drawn everything. It&#8217;s not much artistic, but I&#8217;m not a designer.<br />
Had a few problems with iOS 6 due to some deprecated stuff but in the end it all fall into place.<br />
Also some tweaks performance-wise on the Engine where made since with a lot of stuff on screen things can get out of control pretty easily specially on these portable devices.</p>
<p>iPhone 5 just came out and I even took the time to add support for those extra pixels, actually I just increased the viewport, no scaling.</p>
<p>I probably named it poorly but it&#8217;s <strong>Puwang</strong>.</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/09/puwang2.png" rel="shadowbox[sbpost-2023];player=img;"><img class="alignnone size-medium wp-image-2024" title="puwang2" src="http://www.david-amador.com/wp-content/uploads/2012/09/puwang2-300x200.png" alt="" width="300" height="200" /></a><br />
<a href="http://www.david-amador.com/wp-content/uploads/2012/09/puwang.png" rel="shadowbox[sbpost-2023];player=img;"><img class="alignnone size-medium wp-image-2026" title="puwang" src="http://www.david-amador.com/wp-content/uploads/2012/09/puwang-300x200.png" alt="" width="300" height="200" /></a><br />
<a href="http://www.david-amador.com/wp-content/uploads/2012/09/puwang_icon_screen.png" rel="shadowbox[sbpost-2023];player=img;"><img class="alignnone size-medium wp-image-2025" title="puwang_icon_screen" src="http://www.david-amador.com/wp-content/uploads/2012/09/puwang_icon_screen-200x300.png" alt="" width="200" height="300" /></a></p>
<p>Also added some Leaderboards via Gamecenter and as I write this I&#8217;m starting to receive some feedback of the early beta builds I sent to a couple of testers. If people like it I might release it on the App Store.</p>
<p><iframe src="http://www.youtube.com/embed/AIiKBVTiEhM" frameborder="0" width="560" height="315"></iframe></p>
<p><del datetime="2012-10-09T23:26:01+00:00">If you want to participate in the beta test use this link: <a href="http://tflig.ht/SRB5aP">http://tflig.ht/SRB5aP</a></del></p>
<p><span style="color: #ff0000;">[Edit 10-10-2012]</span> Puwang is now out on the app store, you can get it <a href="http://itunes.apple.com/us/app/puwang/id566365237?ls=1&amp;mt=8">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/09/puwang-a-5-day-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to take screenshots in opengl</title>
		<link>http://www.david-amador.com/2012/09/how-to-take-screenshot-in-opengl/</link>
		<comments>http://www.david-amador.com/2012/09/how-to-take-screenshot-in-opengl/#comments</comments>
		<pubDate>Sat, 08 Sep 2012 15:53:27 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[opengl]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2008</guid>
		<description><![CDATA[So here&#8217;s some quick code to save a screenshot of your OpenGL game in a TGA file. &#160; bool save_screenshot&#40;string filename, int w, int h&#41; &#123; //This prevents the images getting padded // when the width multiplied by 3 is]]></description>
				<content:encoded><![CDATA[<p>So here&#8217;s some quick code to save a screenshot of your OpenGL game in a TGA file.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff;">bool</span> save_screenshot<span style="color: #008000;">&#40;</span>string filename, <span style="color: #0000ff;">int</span> w, <span style="color: #0000ff;">int</span> h<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>	
  <span style="color: #666666;">//This prevents the images getting padded </span>
 <span style="color: #666666;">// when the width multiplied by 3 is not a multiple of 4</span>
  glPixelStorei<span style="color: #008000;">&#40;</span>GL_PACK_ALIGNMENT, <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">int</span> nSize <span style="color: #000080;">=</span> w<span style="color: #000040;">*</span>h<span style="color: #000040;">*</span><span style="color: #0000dd;">3</span><span style="color: #008080;">;</span>
  <span style="color: #666666;">// First let's create our buffer, 3 channels per Pixel</span>
  <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> dataBuffer <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">malloc</span><span style="color: #008000;">&#40;</span>nSize<span style="color: #000040;">*</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>dataBuffer<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #666666;">// Let's fetch them from the backbuffer	</span>
   <span style="color: #666666;">// We request the pixels in GL_BGR format, thanks to Berzeger for the tip</span>
   glReadPixels<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>GLint<span style="color: #008000;">&#41;</span><span style="color: #0000dd;">0</span>, <span style="color: #008000;">&#40;</span>GLint<span style="color: #008000;">&#41;</span><span style="color: #0000dd;">0</span>,
		<span style="color: #008000;">&#40;</span>GLint<span style="color: #008000;">&#41;</span>w, <span style="color: #008000;">&#40;</span>GLint<span style="color: #008000;">&#41;</span>h,
		 GL_BGR, GL_UNSIGNED_BYTE, dataBuffer<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #666666;">//Now the file creation</span>
   <span style="color: #0000ff;">FILE</span> <span style="color: #000040;">*</span>filePtr <span style="color: #000080;">=</span> <span style="color: #0000dd;">fopen</span><span style="color: #008000;">&#40;</span>filename.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">&quot;wb&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>filePtr<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
   <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span> TGAheader<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">12</span><span style="color: #008000;">&#93;</span><span style="color: #000080;">=</span><span style="color: #008000;">&#123;</span><span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">2</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
   <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span> header<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span> w<span style="color: #000040;">%</span><span style="color:#800080;">256</span>,w<span style="color: #000040;">/</span><span style="color: #0000dd;">256</span>,
			       h<span style="color: #000040;">%</span><span style="color:#800080;">256</span>,h<span style="color: #000040;">/</span><span style="color: #0000dd;">256</span>,
			       <span style="color: #0000dd;">24</span>,<span style="color: #0000dd;">0</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
   <span style="color: #666666;">// We write the headers</span>
   <span style="color: #0000dd;">fwrite</span><span style="color: #008000;">&#40;</span>TGAheader,	<span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span>,	<span style="color: #0000dd;">12</span>,	filePtr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #0000dd;">fwrite</span><span style="color: #008000;">&#40;</span>header,	<span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span>,	<span style="color: #0000dd;">6</span>,	filePtr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #666666;">// And finally our image data</span>
   <span style="color: #0000dd;">fwrite</span><span style="color: #008000;">&#40;</span>dataBuffer,	<span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>GLubyte<span style="color: #008000;">&#41;</span>,	nSize,	filePtr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #0000dd;">fclose</span><span style="color: #008000;">&#40;</span>filePtr<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;ve been using this on my projects and it works, although I read a couple of times it&#8217;s better to use p-buffer or FBO, but I leave that for you to research.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/09/how-to-take-screenshot-in-opengl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>QuakeCon 2012 &#8211; John Carmack Keynote</title>
		<link>http://www.david-amador.com/2012/08/quakecon-2012-john-carmack-keynote/</link>
		<comments>http://www.david-amador.com/2012/08/quakecon-2012-john-carmack-keynote/#comments</comments>
		<pubDate>Sat, 04 Aug 2012 17:13:08 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[john carmack]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=2001</guid>
		<description><![CDATA[I usually don&#8217;t do this, but come on, it&#8217;s John Carmack, and this 3h30m keynote given at QuakeCon 2012 is fascinating.]]></description>
				<content:encoded><![CDATA[<p>I usually don&#8217;t do this, but come on, it&#8217;s John Carmack, and this 3h30m keynote given at QuakeCon 2012 is fascinating. </p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/wt-iVFxgFWk" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/08/quakecon-2012-john-carmack-keynote/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gamedev is like a house of cards</title>
		<link>http://www.david-amador.com/2012/07/gamedev-is-like-a-house-of-cards/</link>
		<comments>http://www.david-amador.com/2012/07/gamedev-is-like-a-house-of-cards/#comments</comments>
		<pubDate>Mon, 30 Jul 2012 18:10:46 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[Game Development]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1983</guid>
		<description><![CDATA[It all starts so pretty isn&#8217;t it? A clean project, a quick prototype, it works! It&#8217;s beautiful. Now it&#8217;s time to add more features, everything is planned out, all cogs have a place to be, it goes smoothly for a]]></description>
				<content:encoded><![CDATA[<p>It all starts so pretty isn&#8217;t it?<br />
A clean project, a quick prototype, it works! It&#8217;s beautiful.</p>
<p><img class="alignnone size-full wp-image-1984" title="prototype phase " src="http://www.david-amador.com/wp-content/uploads/2012/07/house-of-cards.jpg" alt="" width="294" height="391" /></p>
<p>Now it&#8217;s time to add more features, everything is planned out, all cogs have a place to be, it goes smoothly for a while.</p>
<p><img class="alignnone size-full wp-image-1985" title="robust prototype" src="http://www.david-amador.com/wp-content/uploads/2012/07/robust-prototype.jpg" alt="" width="362" height="539" /></p>
<p>Now you realize other small components are needed, no problem, let&#8217;s make them&#8230;</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/07/small-components.jpg" rel="shadowbox[sbpost-1983];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/07/small-components.jpg" alt="" title="small components" width="230" height="308" class="alignnone size-full wp-image-1986" /></a></p>
<p>Eventually you do need to plug them into the game itself, and that&#8217;s when the problems start, most of the other stuff wasn&#8217;t built considering these new components. Will they break?</p>
<p><img src="http://www.david-amador.com/wp-content/uploads/2012/07/building-on-top.jpg" alt="" title="building on top" width="570" height="631" class="alignnone size-full wp-image-1987" /></p>
<p>What&#8217;s worse, if at some point you need to radically change something in the gameplay, this might happen. You changed it so much that most of the code just has to be thrown away. It has no place.</p>
<p><img src="http://www.david-amador.com/wp-content/uploads/2012/07/different-base.jpg" alt="" title="different base" width="621" height="443" class="alignnone size-full wp-image-1988" /></p>
<p>Not to mention that eventually trying to remove/replace some function or a core component can have serious consequences.</p>
<p><img src="http://www.david-amador.com/wp-content/uploads/2012/07/remove-a-component.jpg" alt="" title="remove/replace a component" width="578" height="443" class="alignnone size-full wp-image-1996" /></p>
<p>Well, I hope you all have a nice week!<br />
I&#8217;m going back to work #gamedev</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/07/gamedev-is-like-a-house-of-cards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dary&#8217;s Legend development Timelapse sample</title>
		<link>http://www.david-amador.com/2012/07/darys-legend-development-timelapse-sample/</link>
		<comments>http://www.david-amador.com/2012/07/darys-legend-development-timelapse-sample/#comments</comments>
		<pubDate>Sun, 01 Jul 2012 20:32:14 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Daily Things]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[darys legend]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Different Pixel]]></category>
		<category><![CDATA[timelapse]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1964</guid>
		<description><![CDATA[Working on Dary&#8217;s Legend has been my daily routine so I decided to make a time lapse. So this is a video compiled using Chronolapse, by taking a screenshot every 60s during a couple of days while I&#8217;m working on]]></description>
				<content:encoded><![CDATA[<p>Working on Dary&#8217;s Legend has been my daily routine so I decided to make a time lapse.</p>
<p>So this is a video compiled using Chronolapse, by taking a screenshot every 60s during a couple of days while I&#8217;m working on Dary&#8217;s Legend, the new game from Different Pixel. The video is being played back at 10 real minutes per second.</p>
<p>This was recorded between 14-06-2012 and 30-06-2012 (some days are missing)</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/STazyKAMBsE?rel=0" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/07/darys-legend-development-timelapse-sample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting C++ memory leaks in Visual Studio &#8211; again</title>
		<link>http://www.david-amador.com/2012/06/detecting-c-memory-leaks-in-visual-studio-again/</link>
		<comments>http://www.david-amador.com/2012/06/detecting-c-memory-leaks-in-visual-studio-again/#comments</comments>
		<pubDate>Sun, 03 Jun 2012 19:00:01 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Application & Software]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1957</guid>
		<description><![CDATA[I made a small post about detecting C++ memory leaks in Visual Studio in 2010. At the time that seemed to suffice, but some months ago someone told me about Visual Leak Detector and boy does it work. According to]]></description>
				<content:encoded><![CDATA[<p>I made a small post about detecting C++ <a title="Tracking memory leaks in Visual Studio" href="http://www.david-amador.com/2010/10/tracking-memory-leaks-in-visual-studio/">memory leaks in Visual Studio</a> in 2010. At the time that seemed to suffice, but some months ago someone told me about <a href="http://vld.codeplex.com/">Visual Leak Detector</a> and boy does it work.</p>
<p>According to the website itself</p>
<blockquote><p>Visual Leak Detector is a free, robust, open-source memory leak detection system for Visual C++.</p>
<p>It&#8217;s pretty easy to use. After installing it, you just need to tell Visual C++ where to find the included header and library file.</p>
<p>Then it can be used with any C/C++ project simply by adding the following line to your code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &quot;vld.h&quot;</span></pre></td></tr></table></div>

</blockquote>
<p>It&#8217;s very easy to use and I tracked down a bunch of memory leaks hidden inside my code since the time I released Vizati.</p>
<p>As expected this is a heavy beast and debbuding while using VLD required much more memory, but totally worth it. You can even output to a file</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/06/vld.png" rel="shadowbox[sbpost-1957];player=img;"><img src="http://www.david-amador.com/wp-content/uploads/2012/06/vld-300x149.png" alt="" title="vld" width="300" height="149" class="alignnone size-medium wp-image-1960" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/06/detecting-c-memory-leaks-in-visual-studio-again/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dary&#8217;s Legend First Teaser</title>
		<link>http://www.david-amador.com/2012/06/darys-legend-first-teaser/</link>
		<comments>http://www.david-amador.com/2012/06/darys-legend-first-teaser/#comments</comments>
		<pubDate>Fri, 01 Jun 2012 10:44:17 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[darys legend]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1948</guid>
		<description><![CDATA[So, yeah I know I&#8217;ve been a little lazy about my blog it&#8217;s for a good cause. We decided to release a small teaser showing what we have. I can&#8217;t stress this enough, it&#8217;s a work in progress. I can&#8217;t]]></description>
				<content:encoded><![CDATA[<p>So, yeah I know I&#8217;ve been a little lazy about my blog it&#8217;s for a good cause.<br />
We decided to release a small teaser showing what we have. I can&#8217;t stress this enough, it&#8217;s a work in progress.</p>
<p>I can&#8217;t find out how to embed the video with HD by default so don&#8217;t forget to see in 720p</p>
<p><iframe src="http://www.youtube.com/embed/1sd07tBgrrc?rel=0" frameborder="0" width="560" height="315"></iframe></p>
<p>Lately I&#8217;ve been working mostly on small UI stuff, pixel tuning every menu/button and graphical interfaces in the game. It&#8217;s a bit hard mixing a lot of menus keeping a consistent and nice user experience.</p>
<p>Also I&#8217;m tackling on the algorithm for the dungeon/rooms/items generation in order to keep things interesting and fresh each time the game is started.<br />
Most of the items have a probability of showing up but still there&#8217;s much more rules that I want to place.</p>
<p>See you in a couple of weeks&#8230;</p>
<p>Oh, almost forget&#8230;</p>
<p><a href="http://www.david-amador.com/wp-content/uploads/2012/06/AuO2bo5CAAAlrXF.jpg-large.jpg" rel="shadowbox[sbpost-1948];player=img;"><img class="alignnone  wp-image-1954" title="Dary's Legend" src="http://www.david-amador.com/wp-content/uploads/2012/06/AuO2bo5CAAAlrXF.jpg-large.jpg" alt="" width="614" height="461" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/06/darys-legend-first-teaser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xbox 360 Controller Input in C++ via XInput</title>
		<link>http://www.david-amador.com/2012/04/xbox-360-controller-input-in-c-via-xinput/</link>
		<comments>http://www.david-amador.com/2012/04/xbox-360-controller-input-in-c-via-xinput/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 10:41:27 +0000</pubDate>
		<dc:creator>David Amador</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[directX]]></category>
		<category><![CDATA[Xbox360]]></category>
		<category><![CDATA[xInput]]></category>

		<guid isPermaLink="false">http://www.david-amador.com/?p=1915</guid>
		<description><![CDATA[So you have that Xbox360 controller laying around and want to connect it to your game? On XNA this is an out of the box option but if you&#8217;re using C++ you have a bit more work to do first.]]></description>
				<content:encoded><![CDATA[<p>So you have that Xbox360 controller laying around and want to connect it to your game?</p>
<p>On XNA this is an out of the box option but if you&#8217;re using C++ you have a bit more work to do first.</p>
<p>First of all, you will need the DirecX 9.0+ sdk.</p>
<p>The includes.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#define WIN32_LEAN_AND_MEAN // We don't want the extra stuff like MFC and such</span>
<span style="color: #339900;">#include &lt;windows&gt;</span>
<span style="color: #339900;">#include &lt;XInput.h&gt;     // XInput API</span>
<span style="color: #339900;">#pragma comment(lib, &quot;XInput.lib&quot;)   // Library. If your compiler doesn't support this type of lib include change to the corresponding one</span></pre></td></tr></table></div>

<p>Let&#8217;s define the buttons</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">enum</span>
<span style="color: #008000;">&#123;</span>
	GamePad_Button_DPAD_UP          <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>,
	GamePad_Button_DPAD_DOWN        <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span>,
	GamePad_Button_DPAD_LEFT        <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span>,
	GamePad_Button_DPAD_RIGHT       <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span>,
	GamePad_Button_START            <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span>,
	GamePad_Button_BACK             <span style="color: #000080;">=</span> <span style="color: #0000dd;">5</span>,
	GamePad_Button_LEFT_THUMB       <span style="color: #000080;">=</span> <span style="color: #0000dd;">6</span>,
	GamePad_Button_RIGHT_THUMB      <span style="color: #000080;">=</span> <span style="color: #0000dd;">7</span>,
	GamePad_Button_LEFT_SHOULDER    <span style="color: #000080;">=</span> <span style="color: #0000dd;">8</span>,
	GamePad_Button_RIGHT_SHOULDER   <span style="color: #000080;">=</span> <span style="color: #0000dd;">9</span>,
	GamePad_Button_A                <span style="color: #000080;">=</span> <span style="color: #0000dd;">10</span>,
	GamePad_Button_B                <span style="color: #000080;">=</span> <span style="color: #0000dd;">11</span>,
	GamePad_Button_X                <span style="color: #000080;">=</span> <span style="color: #0000dd;">12</span>,
	GamePad_Button_Y                <span style="color: #000080;">=</span> <span style="color: #0000dd;">13</span>,
	GamePadButton_Max <span style="color: #000080;">=</span>             <span style="color: #0000dd;">14</span>
<span style="color: #008000;">&#125;</span>GamePadButton<span style="color: #008080;">;</span></pre></td></tr></table></div>

<p><img src="http://www.david-amador.com/wp-content/uploads/2012/04/450px-360_controller.svg_.jpg" alt="" title="450px-360_controller.svg" width="450" height="208" class="alignnone size-full wp-image-1932" /></p>
<p>After some digging I don&#8217;t think Microsoft exposes access to the Guide button, let me know if you find anything. Anyway it&#8217;s not something we need on Windows.</p>
<p>Now the GamePadIndexes</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// GamePad Indexes</span>
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">enum</span>
<span style="color: #008000;">&#123;</span>
	GamePadIndex_One <span style="color: #000080;">=</span>  <span style="color: #0000dd;">0</span>,
	GamePadIndex_Two <span style="color: #000080;">=</span>  <span style="color: #0000dd;">1</span>,
	GamePadIndex_Three <span style="color: #000080;">=</span><span style="color: #0000dd;">2</span>,
	GamePadIndex_Four <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span>,
<span style="color: #008000;">&#125;</span>GamePadIndex<span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>The GamePadIndex is to define the player position. Like on the Xbox360, this way we can control up to 4 controllers.</p>
<p>We need something to store the GamePad state</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// The GamePad State Stuct, were we store the buttons positions</span>
<span style="color: #0000ff;">struct</span> GamePadState 
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">bool</span>		_buttons<span style="color: #008000;">&#91;</span>GamePadButton_Max<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
	Vector2 	_left_thumbstick<span style="color: #008080;">;</span>               <span style="color: #666666;">// &lt;= I'm using a Vector2 (floats) class but you can replaced it with a float X and Y or whatever your Vector2 class is</span>
	Vector2	        _right_thumbstick<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span>		_left_trigger<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">float</span>		_right_trigger<span style="color: #008080;">;</span>	
        <span style="color: #666666;">// Just to clear all values to default</span>
	<span style="color: #0000ff;">void</span> reset<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>i<span style="color: #000080;">&lt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>GamePadButton_Max<span style="color: #008080;">;</span><span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> _buttons<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		_left_thumbstick.<span style="color: #007788;">set</span><span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		_right_thumbstick.<span style="color: #007788;">set</span><span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		_left_trigger <span style="color: #000080;">=</span> _right_trigger <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>Now a small class</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff;">class</span> GamePadXbox 
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span> 
	GamePadXbox<span style="color: #008000;">&#40;</span>GamePadIndex player<span style="color: #008000;">&#41;</span>			
	<span style="color: #008000;">&#123;</span>
                  _playerIndex <span style="color: #000080;">=</span> player<span style="color: #008080;">;</span>
                  State.<span style="color: #007788;">reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">virtual</span> ~GamePadXbox<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">// We don't want the controller to be vibrating accidentally when we exit the app</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> vibrate<span style="color: #008000;">&#40;</span><span style="color:#800080;">0.0f</span>,<span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">bool</span> is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">void</span> vibrate<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> leftmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span>, <span style="color: #0000ff;">float</span> rightmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
 <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
   GamePadState	State<span style="color: #008080;">;</span>
 <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
   XINPUT_STATE _controllerState<span style="color: #008080;">;</span>
   GamePadIndex _playerIndex<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>Now, onto the GamePadXbox::is_connected()</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
     <span style="color: #666666;">// clean the state</span>
     <span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>_controllerState,<span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>XINPUT_STATE<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Get the state</span>
     DWORD Result <span style="color: #000080;">=</span> XInputGetState<span style="color: #008000;">&#40;</span>_controllerNum, <span style="color: #000040;">&amp;</span>_controllerState<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>Result <span style="color: #000080;">==</span> ERROR_SUCCESS<span style="color: #008000;">&#41;</span>	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
     <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Documentation for the XInputGetState is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinputgetstate%28v=vs.85%29.aspx">here</a>.</p>
<p>Onto the vibrate function. Now, the Vibration accepts values between 0 and 65535. But we don&#8217;t want to be typing that every time so the vibrate accepts from a range of 0.0f (0) to 1.0f (65535);</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> vibrate<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> leftmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span>, <span style="color: #0000ff;">float</span> rightmotor <span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// Create a new Vibraton </span>
	XINPUT_VIBRATION Vibration<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>Vibration, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>XINPUT_VIBRATION<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> leftVib <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>leftmotor<span style="color: #000040;">*</span><span style="color:#800080;">65535.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> rightVib <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>rightmotor<span style="color: #000040;">*</span><span style="color:#800080;">65535.0f</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Set the Vibration Values</span>
	Vibration.<span style="color: #007788;">wLeftMotorSpeed</span> <span style="color: #000080;">=</span> leftVib<span style="color: #008080;">;</span>
	Vibration.<span style="color: #007788;">wRightMotorSpeed</span> <span style="color: #000080;">=</span> rightVib<span style="color: #008080;">;</span>
        <span style="color: #666666;">// Vibrate the controller</span>
	XInputSetState<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>_controllerNum, <span style="color: #000040;">&amp;</span>Vibration<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>On the destructor I&#8217;ve placed the vibrate at 0.0f otherwise the controller may be left vibrating after your game exits until the user unplugs it.</p>
<p>Finally, the update() function. Now this one is more out of convenience, since you could get the state straight out of  XINPUT_STATE but I think this is a more consistent way of doing it. You can decide how you want on yours.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	State.<span style="color: #007788;">reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">// The values of the Left and Right Triggers go from 0 to 255. We just convert them to 0.0f=&gt;1.0f</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bRightTrigger</span> <span style="color: #000040;">&amp;&amp;</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bRightTrigger</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_TRIGGER_THRESHOLD<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		State._right_trigger <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bRightTrigger</span><span style="color: #000040;">/</span><span style="color:#800080;">255.0f</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bLeftTrigger</span> <span style="color: #000040;">&amp;&amp;</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bLeftTrigger</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_TRIGGER_THRESHOLD<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		State._left_trigger <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">bLeftTrigger</span><span style="color: #000040;">/</span><span style="color:#800080;">255.0f</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
       <span style="color: #666666;">// Get the Buttons</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_A<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_A<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_B<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_B<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_X<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_X<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_Y<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_Y<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">wButtons</span> <span style="color: #000040;">&amp;</span> XINPUT_GAMEPAD_DPAD_DOWN<span style="color: #008000;">&#41;</span> State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_DPAD_DOWN<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #666666;">// The Rest is missing, you can figure out the rest :)</span>
&nbsp;
....
             <span style="color: #008000;">&#40;</span>ThumbSticks code below<span style="color: #008000;">&#41;</span>   
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>For getting all buttons here are the official flags according to msdn</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">XINPUT_GAMEPAD_DPAD_UP          <span style="color: #208080;">0x00000001</span>
XINPUT_GAMEPAD_DPAD_DOWN        <span style="color: #208080;">0x00000002</span>
XINPUT_GAMEPAD_DPAD_LEFT        <span style="color: #208080;">0x00000004</span>
XINPUT_GAMEPAD_DPAD_RIGHT       <span style="color: #208080;">0x00000008</span>
XINPUT_GAMEPAD_START            <span style="color: #208080;">0x00000010</span>
XINPUT_GAMEPAD_BACK             <span style="color: #208080;">0x00000020</span>
XINPUT_GAMEPAD_LEFT_THUMB       <span style="color: #208080;">0x00000040</span>
XINPUT_GAMEPAD_RIGHT_THUMB      <span style="color: #208080;">0x00000080</span>
XINPUT_GAMEPAD_LEFT_SHOULDER    <span style="color: #208080;">0x0100</span>
XINPUT_GAMEPAD_RIGHT_SHOULDER   <span style="color: #208080;">0x0200</span>
XINPUT_GAMEPAD_A                <span style="color: #208080;">0x1000</span>
XINPUT_GAMEPAD_B                <span style="color: #208080;">0x2000</span>
XINPUT_GAMEPAD_X                <span style="color: #208080;">0x4000</span>
XINPUT_GAMEPAD_Y                <span style="color: #208080;">0x8000</span></pre></td></tr></table></div>

<p>The ThumbSticks are a bit more tricky. They return 2 axis each but you have to make sure they are not in the deadzone. The deadzone pretty much are values !=0 but that are not relevant and can lead to errors.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
  <span style="color: #666666;">// Check to make sure we are not moving during the dead zone</span>
  <span style="color: #666666;">// Let's check the Left DeadZone</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE <span style="color: #000040;">&amp;&amp;</span>
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span> <span style="color: #000080;">&gt;</span> <span style="color: #000040;">-</span>XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE<span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
	<span style="color: #008000;">&#40;</span>_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span> <span style="color: #000080;">&lt;</span> XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE <span style="color: #000040;">&amp;&amp;</span>
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span> <span style="color: #000080;">&gt;</span> <span style="color: #000040;">-</span>XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>    
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	_controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// Check left thumbStick</span>
&nbsp;
  <span style="color: #0000ff;">float</span> leftThumbY <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLY</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>leftThumbY<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
        State._left_thumbstick.<span style="color: #007788;">Y</span> <span style="color: #000080;">=</span> leftThumbY<span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">float</span> leftThumbX <span style="color: #000080;">=</span> _controllerState.<span style="color: #007788;">Gamepad</span>.<span style="color: #007788;">sThumbLX</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>leftThumbX<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
	State._left_thumbstick.<span style="color: #007788;">X</span> <span style="color: #000080;">=</span> leftThumbX<span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>    
&nbsp;
  <span style="color: #666666;">// For the rightThumbstick it's pretty much the same.</span></pre></td></tr></table></div>

<p>So how would we use this then?</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
     GamePadXbox<span style="color: #000040;">*</span> pad <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> GamePadXbox<span style="color: #008000;">&#40;</span>GamePadIndex_One<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
       <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pad<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>is_connected<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
       <span style="color: #008000;">&#123;</span>
          pad<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>update<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
          <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pad<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>State._buttons<span style="color: #008000;">&#91;</span>GamePad_Button_BACK<span style="color: #008000;">&#93;</span><span style="color: #000080;">==</span><span style="color: #0000ff;">true</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span>
       <span style="color: #008000;">&#125;</span>   
     <span style="color: #008000;">&#125;</span>
     <span style="color: #0000dd;">delete</span> pad<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Anyway, most of this code is not elegant or &#8220;pretty&#8221; but it should work, the idea is for you to understand the concept, the rest is up to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.david-amador.com/2012/04/xbox-360-controller-input-in-c-via-xinput/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.137 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-19 18:18:59 -->
