<?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>CodeSampler.com</title>
	<atom:link href="http://www.codesampler.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codesampler.com</link>
	<description>Delicious bits of code...</description>
	<lastBuildDate>Thu, 14 Apr 2011 04:09:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>My Apologies&#8230;</title>
		<link>http://www.codesampler.com/2011/03/25/my-apologies/</link>
		<comments>http://www.codesampler.com/2011/03/25/my-apologies/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 14:58:13 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.codesampler.com/?p=398</guid>
		<description><![CDATA[I’m not sure how or for how long, but the ability to post replies on my blog was disabled until today. I started noticing that no one was replying to anything. The whole blog was strangely silent – not that it’s super busy anyway, but it was still noticeable none the less. Finally, after wasting [...]]]></description>
			<content:encoded><![CDATA[<p>I’m not sure how or for how long, but the ability to post replies on my blog was  disabled until today. I  started noticing that no one was replying to anything. The whole blog  was strangely silent – not that it’s super busy anyway, but it was still  noticeable none the less.</p>
<p>Finally, after wasting an hour hacking around inside my theme’s PHP  code, I realize that discussions on all of my posts had been disabled in  my WordPress Admin panel. I can only guess, but it appears that one of  the last two WordPress updates screwed up my settings during the patch  install and left my entire site in a disabled state.</p>
<p>Either way, it’s fixed, so if you have any replies you wish to leave,  please do, unless, its questions about why you couldn’t post replies  last week. I think we&#8217;ve already covered that!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codesampler.com/2011/03/25/my-apologies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Asynchronous read-back of pixel data using a Frame Buffer Object and two Pixel Buffer Objects</title>
		<link>http://www.codesampler.com/2011/01/21/asynchronous-read-back-of-pixel-data-using-a-frame-buffer-object-and-two-pixel-buffer-objects/</link>
		<comments>http://www.codesampler.com/2011/01/21/asynchronous-read-back-of-pixel-data-using-a-frame-buffer-object-and-two-pixel-buffer-objects/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 17:55:59 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Frame Buffer Object]]></category>
		<category><![CDATA[glReadPixels]]></category>
		<category><![CDATA[Pixel Buffer Object]]></category>

		<guid isPermaLink="false">http://www.codesampler.com/?p=358</guid>
		<description><![CDATA[It was my intention to write a full article on this new sample, but who am I kidding – I barely have enough time to write this simple little blog post. So, instead of just sitting on the sample and deluding myself that I will someday have enough free-time to write something substantial concerning it [...]]]></description>
			<content:encoded><![CDATA[<p>It was my intention to write a full article on this new sample, but who am I kidding – I barely have enough time to write this simple little blog post. So, instead of just sitting on the sample and deluding myself that I will someday have enough free-time to write something substantial concerning it – I will just toss it out the door with a brief announcement of, “Come and get it!”</p>
<p>Recently, I was struggling with an OpenGL feature that required me to research faster ways of reading pixel data back to the CPU from the GPU where I could perform some post processing on it. Typically, you should try very hard to keep your post processing on the GPU instead trying to read it back across the bus, but in this case I wanted to fetch the pixel data back so I could load it into a WPF app and I had no choice. It must come back and as fast as possible.</p>
<p>After much research, I settled on a solution that does an off-screen rendering to a FBO (frame buffer object) and then uses two alternating PBOs (pixel buffer objects) to perform an asynchronous read-back to system memory via DMA transfers. The beauty of this approach is that it disables the blocking behavior which is typically associated with calling glReadPixels, and this is always the prime culprit when it comes to bad read-back performance for pixel data that is being shuttled back across the bus. If you’re researching something similar, I hope this <strong><a href="http://www.codesampler.com/source/ogl_fbo_pbo_readback.zip">research sample</a></strong> proves useful.</p>
<p>The sample targets the regular desktop version of OpenGL and was coded and tested in Visual Studio 2005 and 2008 on both Windows Xp and Windows 7.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.codesampler.com/images/ogl_fbo_pbo_readback.png" alt="" width="400" height="300" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codesampler.com/2011/01/21/asynchronous-read-back-of-pixel-data-using-a-frame-buffer-object-and-two-pixel-buffer-objects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introduction to OpenGL ES 2.0</title>
		<link>http://www.codesampler.com/2010/11/02/introduction-to-opengl-es-2-0/</link>
		<comments>http://www.codesampler.com/2010/11/02/introduction-to-opengl-es-2-0/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 20:21:45 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[OpenGL ES 2.0]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[PowerVR]]></category>

		<guid isPermaLink="false">http://www.codesampler.com/?p=272</guid>
		<description><![CDATA[Ever since I started developing for the iPhone and iPad I&#8217;ve had to re-learn OpenGL in its new mobile form as OpenGL ES 2.0. With that said, I still like being able to do my basic research on my Windows 7 laptop instead of hacking around inside XCode, which I&#8217;m still getting used to. Therefore, [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I started developing for the iPhone and iPad I&#8217;ve had to re-learn OpenGL in its new mobile form as OpenGL ES 2.0. With that said, I still like being able to do my basic research on my Windows 7 laptop instead of hacking around inside XCode, which I&#8217;m still getting used to.</p>
<p><img class="alignright" src="http://www.codesampler.com/images/imagination_technologies_powervr_logo.png" alt="PowerVR Logo" width="200" height="219" /></p>
<p>Therefore, I decided to create some really simple, stand-alone OpenGL ES 2.0 samples that can run on Windows through PowerVR&#8217;s OpenGL ES 2.0 emulator.</p>
<p>Yes, I know that the emulator is part of a SDK that has a ton of samples, but I like small, self-contained samples that stand on their own and do not rely on a massive common samples library that hides most of the detail. And, yes, I also know that all this abstraction is meant to help me, but somehow it makes things seem even more mysterious when certain aspects of OpenGL ES are tucked away out of sight. Anyway, I just like tiny, bare-bone samples that get straight to the point.</p>
<p>If that&#8217;s you, read on.</p>
<p><span id="more-272"></span></p>
<p>First off, you&#8217;ll need to download <a href="http://www.imgtec.com/powervr/insider/sdkdownloads/index.asp">PowerVR&#8217;s OpenGL ES 2.0 emulator SDK</a> since OpenGL ES is intended for mobile devices &#8211; not full-size computers that normally run regular OpenGL. The actual downland link is under the header of <em>PC Emulation</em> and is titled <a href="http://www.imgtec.com/powervr/insider/powervr-login.asp?SDK=WindowsXPOGLES2">Windows Vista/XP &#8211; OpenGL ES 2.0</a>.</p>
<p>Once you&#8217;ve installed their SDK you&#8217;ll be able to run all of the PowerVR samples right away because they all reference the SDK through relative paths, but the samples I offer do not use relative paths so you&#8217;ll need to add a few paths to Visual Studio to get to them to compile and link, and you&#8217;ll need to add one path to your system&#8217;s <strong>PATH </strong>environment variable to get them to run on the emulator. Here&#8217;s how you do it.</p>
<ol>
<li>In the menu of Visual Studio select <em>Tools-&gt;Options</em> to launch the <em>Options </em>dialog.</li>
<li>On the <em>Options </em>dialog, open or expand the<em> Project and Solutions </em>category and select <em>VC++ Directories</em>.</li>
<li>In the <em>Show directories for</em> drop down box select <em>Include files</em> and add the following paths. Of course, your paths may vary depending on where you install the SDK and the version you downloaded.
<ol>
<li><span style="color: #ff0000;">C:\Imagination Technologies\POWERVR SDK\OGLES2_WINDOWS_PCEMULATION_2.07.27.0484\Builds\OGLES2\WindowsPC</span></li>
<li><span style="color: #ff0000;">C:\Imagination Technologies\POWERVR SDK\OGLES2_WINDOWS_PCEMULATION_2.07.27.0484\Builds\OGLES2\Include</span></li>
</ol>
</li>
<li>Next, In the <em>Show directories for</em> drop down box select <em>Library files</em> and add this path:
<ol>
<li><span style="color: #ff0000;">C:\Imagination Technologies\POWERVR SDK\OGLES2_WINDOWS_PCEMULATION_2.07.27.0484\Builds\OGLES2\WindowsPC\Lib</span></li>
</ol>
</li>
</ol>
<p>Finally, you&#8217;re going to add a path to your system&#8217;s <strong>PATH </strong>variable so you can run the samples on the emulator no matter where you run your samples from. This path will point to the .dlls for the emulator which are stored in the SDK&#8217;s lib directory.</p>
<ol>
<li>To do this, hold down the <em>Windows</em> key on your keyboard and hit the <em>Pause/Break</em> key to bring up the <em>System Properties</em> dialog.</li>
<li>On the <em>System Properties</em> dialog select the <em>Advanced</em> tab and click the <em>Environment Variables</em> button.</li>
<li>Under<em> System Variables</em> double click the <strong>PATH </strong>variable and append this path to the end of the long list of other paths. Make sure to separate our new path from the last path with a semicolon.
<ol>
<li><span style="color: #ff0000;">;C:\Imagination Technologies\POWERVR SDK\OGLES2_WINDOWS_PCEMULATION_2.07.27.0484\Builds\OGLES2\WindowsPC\Lib</span></li>
</ol>
</li>
</ol>
<p>If you get all this right, you&#8217;ll now be able to download, compile and run the OpenGL ES 2.0 samples from my site. Now, to get the ball rolling, here are two samples to test out your new OpenGL ES 2.0 emulation environment.</p>
<p>This first sample is super simple and is focused on <a href="http://www.codesampler.com/source/ogles2_initialization.zip">setting up and initializing OpenGL ES 2.0</a>. I&#8217;m not going to elaborate much here since there are tons of blogs that discuss the basics of using of EGL to create an OpenGL ES 2.0 window from a system specific Window, so download the sample, read through the code, and start Googling if you have questions.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.codesampler.com/images/ogles2_initialization.png" alt="" width="400" height="300" /></p>
<p>The second sample is a little more advanced and <a href="http://www.codesampler.com/source/ogles2_texture.zip">adds textured geometry</a> to the mix which is pretty cool because it shows how to load a PNG image with transparency using the <a href="http://members.gamedev.net/lode/projects/LodePNG/">LodePNG library</a> so we can create an OpenGL texture from it.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.codesampler.com/images/ogles2_texture.png" alt="" width="400" height="300" /></p>
<p style="text-align: left;">Here are the basics of using <a href="http://members.gamedev.net/lode/projects/LodePNG/">LodePNG library</a> to create an OpenGL texture.</p>
<pre class="brush: cpp; title: ; notranslate">
//
// Load and decode a PNG file so we can make a texture out of it.
//

std::vector&lt; unsigned char &gt; rawImage;
LodePNG::loadFile( rawImage, &quot;test_alpha.png&quot; );

LodePNG::Decoder decoder;
std::vector&lt; unsigned char &gt; image;
decoder.decode( image, rawImage.empty() ? 0 : &amp;rawImage[0],
                (unsigned)rawImage.size() );
</pre>
<p>Unfortunately, OpenGL likes to load things completely opposite from everybody else, so you&#8217;ll also need some code to flip and invert the image data before loading it into an OpenGL texture array:</p>
<pre class="brush: cpp; title: ; notranslate">

//
// Flip and invert the PNG image since OpenGL likes to load everything
// backwards from what is considered normal!
//

unsigned char *imagePtr = &amp;image[0];
int halfTheHeightInPixels = decoder.getHeight() / 2;
int heightInPixels = decoder.getHeight();

// Assuming RGBA for 4 components per pixel.
int numColorComponents = 4;

// Assuming each color component is an unsigned char.
int widthInChars = decoder.getWidth() * numColorComponents;

unsigned char *top = NULL;
unsigned char *bottom = NULL;
unsigned char temp = 0;

for( int h = 0; h &lt; halfTheHeightInPixels; ++h )
{
    top = imagePtr + h * widthInChars;
    bottom = imagePtr + (heightInPixels - h - 1) * widthInChars;

    for( int w = 0; w &lt; widthInChars; ++w )
    {
        // Swap the chars around.
        temp = *top;
        *top = *bottom;
        *bottom = temp;

        ++top;
        ++bottom;
    }
}
</pre>
<p>Once that&#8217;s done, you can move forward and create an OpenGL texture out of the flipped over PNG data:</p>
<pre class="brush: cpp; title: ; notranslate">

//
// Create the OpenGL texture and fill it with our PNG image.
//

// Allocates one texture handle
glGenTextures( 1, &amp;g_uiTexture );

// Binds this texture handle so we can load the data into it
glBindTexture( GL_TEXTURE_2D, g_uiTexture );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(),
              decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
              &amp;image[0] );
</pre>
<p>Well, that concludes my little introduction to setting up an OpenGL ES 2.0 emulation environment on Windows. I hope it helps you get a little further down the road of mobile 3D development with OpenGL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codesampler.com/2010/11/02/introduction-to-opengl-es-2-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lua Tutorial #1 &#8211; The Setup</title>
		<link>http://www.codesampler.com/2010/10/17/lua-tutorial-1-the-setup/</link>
		<comments>http://www.codesampler.com/2010/10/17/lua-tutorial-1-the-setup/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 20:39:46 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Lua Tutorials]]></category>
		<category><![CDATA[ConTEXT]]></category>
		<category><![CDATA[Lua]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.codesampler.com/?p=111</guid>
		<description><![CDATA[I’m guessing by now that my regular visitors have grown tired of watching my new blog change WordPress themes from day-to-day and occasionally go berserk as I fiddle with all the blog settings and break the PHP code. With that said, I’ve decided to set things right by writing a series of tutorials on the [...]]]></description>
			<content:encoded><![CDATA[<p>I’m guessing by now that my regular visitors have grown tired of watching my new blog change WordPress themes from day-to-day and occasionally go berserk as I fiddle with all the blog settings and break the PHP code. With that said, I’ve decided to set things right by writing a series of tutorials on the Lua scripting which is loosely based on the course that I teach at the <a href="http://guildhall.smu.edu/">Guildhall at SMU</a>.</p>
<p><img class="alignright" src="http://www.codesampler.com/images/lua.gif" alt="Lua Logo" width="154" height="153" /><br />
<a href="http://www.lua.org/">Lua </a>is a rather popular scripting language for game design. If you don&#8217;t believe me just check out this <a href="http://en.wikipedia.org/wiki/Category:Lua-scripted_video_games">list of games that use Lua</a>. Clearly, anyone serious about game programming and especially learning scripting for level design, which is where Lua shines brightest, should take a moment out of their busy schedule and get too know Lua.</p>
<p>Ok, enough with the sales pitch.. let’s just jump in and gets this party started!</p>
<h2><span id="more-111"></span></h2>
<h2>Installing Lua for Windows</h2>
<p>The first thing I need you to do is download Lua and get it installed on your system and the fasted way to do this is to simply install the <a href="http://code.google.com/p/luaforwindows/">Windows for Lua</a> binaries which not only contains Lua already compiled and ready to go but includes  numerous other libraries that you may find helpful in the future. The version that I downloaded was <a href="http://luaforwindows.googlecode.com/files/LuaForWindows_v5.1.4-40.exe">LuaForWindows_v5.1.4-40.exe</a>. Other than downloading it, the install is the standard fare&#8230; click next, next, next, etc&#8230; you know the drill.</p>
<h2>Install the ConTEXT editor</h2>
<p><img class="alignright" src="http://www.codesampler.com/images/context.gif" alt="" width="100" height="100" />Next, we need a text editor (preferably free) aimed at programmers which will make coding and running our Lua scripts a bit more organized. The text editor I use for my Guildhall course is <a href="http://www.contexteditor.org/">ConTEXT </a>which allows me customize the highlight of my Lua code and execute scripts from the editor with a simple push of a button. The version of ConTEXT that I downloaded was <a href="http://cdn.contextstatic.org/downloads/ConTEXTv0_986.exe">ConTEXTv0_986.exe</a>. If there is another text editor you would prefer to use, please feel free to use it, but keep in mind that these tutorials will be written as if you were using ConTEXT.</p>
<p>Once you&#8217;ve downloaded and installed both Lua and the ConTEXT editor please follow these steps to finish the setup.</p>
<ol>
<li>First off, we need to setup ConTEXT to execute our Lua scripts by pressing the F11 key.
<ol>
<li>Open ConTEXT and select from the menu <em>Options-&gt;Environment Options</em>.</li>
<li>On the <em>Environment Options</em> dialog select the <em>Execute Keys</em> tab.</li>
<li>Click the <em>Add </em>button and add a new extension called &#8220;Lua&#8221;</li>
<li>Select the new Lua extension in the tree view and set the <em>Execute </em>path to &#8220;C:\Program Files (x86)\Lua\5.1\lua.exe&#8221; This path maybe different on your computer depending on your OS version where you installed <em>Lua For Windows</em>.</li>
<li>Set the <em>Parameters </em>edit box to &#8220;%n&#8221;.</li>
<li>Click the <em>Apply </em>button and close the <em>Environment Options</em> dialog.</li>
</ol>
</li>
<li>Finally, add my custom <a href="http://www.codesampler.com/source/lua_context_highlighter.zip">Lua highlighter file</a> to ConTEXT. This is optional, but it makes the code look really sweet instead of plain ol&#8217; black-on-white and who doesn&#8217;t want that? Further instructions are included in the zip  file.</li>
</ol>
<p>When done, the <em>Environment Options</em> dialog of ConTEXT should look like this:</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.codesampler.com/images/context_lua_setup.png" alt="" width="464" height="574" /></p>
<h2 style="text-align: left;">Testing Our Development Setup</h2>
<p style="text-align: left;">The last thing we&#8217;re going to do is test our development setup by creating a new Lua script and attempting to execute it from ConTEXT. To accomplish this, follow theses steps:</p>
<ol>
<li>Open ConTEXT and create a new file by selecting from the menu <em>File-&gt;New</em>.</li>
<li>In this new file type the following line: <strong><em>print( &#8220;Hello Lua!&#8221; ) </em></strong></li>
<li>Save the file by selecting from the menu<em> File-&gt;Save</em> and name it &#8220;hello.lua&#8221;. You can save it anywhere you want.</li>
<li>Finally, hit the F11 key to execute the script.</li>
<li>If everything works, you should see the the words &#8220;Hello Lua!&#8221; printed out in ConTEXT&#8217;s <em>Output Console</em>.</li>
</ol>
<p>When done, ConTEXT should look something like this:</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.codesampler.com/images/context_test.png" alt="ConTEXT + Lua Test" width="592" height="576" /></p>
<p style="text-align: left;">In the next tutorial, we&#8217;ll start leveraging our new development setup to learn the basic syntax of Lua. If you have any troubles getting any of this working, please feel free to reply below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codesampler.com/2010/10/17/lua-tutorial-1-the-setup/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>CodeSampler.com goes blog!</title>
		<link>http://www.codesampler.com/2010/09/25/codesampler-com-goes-blog/</link>
		<comments>http://www.codesampler.com/2010/09/25/codesampler-com-goes-blog/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 01:41:27 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://kharris.globat.com/?p=4</guid>
		<description><![CDATA[Well, if things around here look different… that’s because they are. I’ve finally decided to get off my lazy duff and upgrade my old site into a blog. This not only gives me a great excuse to use cool new techno words like blog, blog rolls, blogosphere and flux capacitor, in everyday conversation, but it [...]]]></description>
			<content:encoded><![CDATA[<p>Well, if things around here look different… that’s because they are. I’ve finally decided to get off my lazy duff and upgrade my<strong> </strong>old site into a blog. This not only gives me a great excuse to use cool new techno words like blog, blog rolls, blogosphere and flux capacitor, in everyday conversation, but it allows me to post new code samples in a cool new interactive format where people can complain… um… I mean interact with each other about the code being posted.</p>
<p>Now, while the site undergoes this incredible metamorphosis into something even cooler, all the code from the old site can still be accessed under the<strong> <a href="http://www.codesampler.com/code/">Code</a></strong> tab of the navigation bar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codesampler.com/2010/09/25/codesampler-com-goes-blog/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

