<?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>Last Stop &#187; programming</title>
	<atom:link href="http://laststop.spaceislimited.org/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://laststop.spaceislimited.org</link>
	<description>it&#039;s going to be a long ride</description>
	<lastBuildDate>Wed, 28 Jan 2009 13:21:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A New Way To Surf &#8211; LP</title>
		<link>http://laststop.spaceislimited.org/2008/10/12/a-new-way-to-surf-lp/</link>
		<comments>http://laststop.spaceislimited.org/2008/10/12/a-new-way-to-surf-lp/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 19:09:42 +0000</pubDate>
		<dc:creator>Timothy M. Rodriguez</dc:creator>
				<category><![CDATA[LPlayer]]></category>
		<category><![CDATA[Technical Nonsense]]></category>
		<category><![CDATA[LP]]></category>
		<category><![CDATA[lpxml]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[standard]]></category>
		<category><![CDATA[tv]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://laststop.spaceislimited.org/?p=8</guid>
		<description><![CDATA[Everyone&#8217;s talking about IP TV and how it&#8217;s going to revolutionize things. We&#8217;ll be able to get our TV anywhere, any way, but the reality has fallen short of the promise. Your ISP may be beaming Digital channels down to you over IP, but the experience is largely unique to your ISP. Your cable box [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://laststop.spaceislimited.org/wp-content/uploads/2008/10/video-tv.png"><img class="size-full wp-image-32 aligncenter" title="Old School TV" src="http://laststop.spaceislimited.org/wp-content/uploads/2008/10/video-tv.png" alt="Gotta love it!" width="314" height="346" /></a></p>
<p>Everyone&#8217;s talking about IP TV and how it&#8217;s going to revolutionize things.  We&#8217;ll be able to get our TV anywhere, any way, but the reality has fallen short of the promise.   Your ISP may be beaming Digital channels down to you over IP, but the experience is largely unique to your ISP.  <strong>Your cable box is not a TV Content browser</strong>, no matter how much it tries to be.  Heck, you can&#8217;t even take your Time Warner Cable box and easily connect it to a Comcast user&#8217;s home.  The <em>spirit</em> of the IP in <em>IP</em>TV is sorely missing.</p>
<p>That&#8217;s why I&#8217;m working on a better way&#8211;and I need your help.</p>
<p>There are several standards regarding IPTV (and they are used), but while they focus on <em>delivering</em> the content, they do not focus on the <em>programming</em>.  If you&#8217;re looking at the web to solve your problem, don&#8217;t look there either.  Every single news or content producer has their own site with their own way of accessing it.  You need accounts, you need a pretty hefty browser, and you need to wade through a different interface each and every time.</p>
<h3>There is no way to channel surf on the web.</h3>
<h2><span id="more-8"></span></h2>
<h2>What about RSS?</h2>
<p>RSS is great!  I love it, but it drastically changes consumption of media, albeit in a very Web way.  TiVO&#8217;s and DVR&#8217;s help bridge this gap on the classic TV side, but what about programming?  Sometimes I don&#8217;t want to pick what to watch.  Sometimes I just want to flip through channels and see what&#8217;s on.  RSS does not replace programming.  (I&#8217;d also like to take this moment to give a big shout-out to <a title="Miro" href="http://www.miro.com" target="_blank">Miro</a>, which is an amazing application for automagically downloading and managing video RSS feeds.) We need something more.</p>
<h2>A New Way to <em>Surf</em></h2>
<p>What we need is a format for serving up programming that goes beyond a fixed stream.  We need a way of mixing up content, and the web.  We also need a better way of consuming it all.  Without giving it an official name, I&#8217;m going to call this protocol LP.  Imagine if you could pull down a link to your favorite channel&#8217;s programming and view content live.  It&#8217;s not a stream, it&#8217;s a url your LP player goes to and it contains all the information you need to find out what&#8217;s playing now on your favorite channel.  Heck, why stop with now?  Maybe it&#8217;s all pre-recorded and you can skip to what&#8217;s playing later?  Maybe, you want to see what was on before?  Who needs a DVR?  The content should stay available and you should be able to consume it.  What I&#8217;m talking about is a REST API for navigating video and audio content.</p>
<h3><strong>A Trudge Through the Mud</strong></h3>
<p><span style="text-decoration: line-through;">I first started writing this post four months ago and I kept putting it off.</span> Then I wrote some more and put it off a few more months.  I had all these ideas in my head and I wanted to get them all out in one go.  I wanted to have a working prototype of an LP Server and Player, of the &#8220;LPXML&#8221; format, and have all the whizz-bang features I wanted to put into it.  The fact of the matter is I&#8217;m busy and it will take me forever to settle my ideas if I don&#8217;t just start and get something out there.  So I&#8217;m going to start with just the basics of what I think this &#8220;informal&#8221; standard should look like.</p>
<p>And I&#8217;m definitely looking for feedback.</p>
<p>What I&#8217;m proposing is that an LP player take a link to a website (e.g. www.spaceislimited.org/lplayer/) and this will be the root of the lplayer REST interface for my site (the link is hypothetical btw).  The Lplayer application (this could even be Miro if this catches on) would then know the following structure for the REST inteface.</p>
<p>lplayer/now/ &#8211; This verb will respond with a page that will contain the URL of the content that is currently now playing.  For example, the Lplayer goes to lplayer/now/ and get this response:</p>
<p>&lt;code&gt;</p>
<p>&lt;a href=&#8221;http://spaceislimited.org/videos/awesomevid1.lpxml&#8221; /&gt;</p>
<p>That&#8217;s it.  Nothing else.  Maybe eventually we&#8217;ll specify an XML doctype and wrap it in something like:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;</p>
<p>&lt;lp version=&#8221;0.1&#8243; xmlns:lpxml=&#8221;http://www.lpxml.org/lpxml.dtd&#8221;&gt;</p>
<p>&lt;program&gt;http://spaceislimited.org/videos/awesomevid1.lpxml&lt;/program&gt;</p>
<p>&lt;elapsed&gt;20&lt;/elapsed&gt;</p>
<p>&lt;/lp&gt;</p>
<p>&lt;/code&gt;</p>
<p>The player would then follow that link to get the content and some meta data about the content.  It would also  use the elapsed value to sync up with how far into the program everyone is.  Of course, if it&#8217;s a live stream, the elapsed value may not be necessary.  The program link might look something like this:</p>
<p>&lt;code&gt;</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;</p>
<p>&lt;lp version=&#8221;0.1&#8243; xmlns:lpxml=&#8221;http://www.lpxml.org/lpxml.dtd&#8221;&gt;</p>
<p>&lt;content size=&#8221;small&#8221; codec=&#8221;quicktime&#8221; bitrate=&#8221;100k&#8221;&gt;http://spaceislimited.org/videos/awesomevid1_lowres.mov&lt;content/&gt;</p>
<p>&lt;content size=&#8221;medium&#8221; codec=&#8221;quicktime&#8221; bitrate=&#8221;200k&#8221;&gt;http://spaceislimited.org/videos/awesomevid1_mediumres.mov&lt;content/&gt;</p>
<div>
<p>&lt;content size=&#8221;high&#8221; codec=&#8221;quicktime&#8221; bitrate=&#8221;300k&#8221;&gt;http://spaceislimited.org/videos/awesomevid1_highres.move&lt;content/&gt;</p>
<p>&lt;language&gt;en-us&lt;/language&gt;</p>
<p>&lt;title&gt;Awesome Vid &#8211; 1&lt;/title&gt;</p>
<p>&lt;description&gt;This is part one of an awesome video I made and you should check it out.&lt;/description&gt;</p></div>
<p>&lt;/lp&gt;</p>
<p>&lt;/code&gt;</p>
<p>Depending on the player, it can choose one of three files to stream, each with a different bitrate.  For example, if you had an LPlayer on your iPhone, maybe it would choose the 100k stream, while your home computer might opt for the 300k stream.  Also, the rest of the meta-data is standard stuff which could be used within the application.</p>
<p>So what happens when the video is done?  Simple, the player would then go fetch the /lplayer/now/ link again and get what&#8217;s playing now!  If it still sees the same entry, it might wait a few seconds and try again (maybe your lp server site is so awesome it&#8217;s having trouble responding).  Or the application could try /lplayer/next/ and get what&#8217;s playing next.  That way, your iPhone can start buffering what&#8217;s next a few seconds before!</p>
<h2>A Call to Arms</h2>
<p>I&#8217;m publishing this as an informal standard and I&#8217;d love to see your comments behind this.  More than that, I&#8217;d love to see people who are willing to work on this with me on setting up a community around this and implementing a free server and player for the &#8220;LP&#8221; standard.  For this standard to work, it needs to be open, simple, and platform and codec agnostic.  I haven&#8217;t said anything about needing to use the QuickTime codec or having to choose a standard bitrate.  This is about discovery and enabling the player to make the right choice.  Attached is the standard&#8211;plain and simple for now.  In the coming weeks I&#8217;m going to work on <span style="text-decoration: line-through;">getting a site</span> (<a title="LPXML.ORG" href="http://www.lpxml.org" target="_blank">lpxml.org</a>), wiki, forum, and <span style="text-decoration: line-through;">mailing list</span> (lpxml [at] googlegroups [dot] com) setup so we as a community can work on this.  I hope you&#8217;ll join me.</p>
]]></content:encoded>
			<wfw:commentRss>http://laststop.spaceislimited.org/2008/10/12/a-new-way-to-surf-lp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming Pong in C and OpenGL &#8211; Part IV</title>
		<link>http://laststop.spaceislimited.org/2008/07/01/programming-pong-in-c-and-opengl-part-iv/</link>
		<comments>http://laststop.spaceislimited.org/2008/07/01/programming-pong-in-c-and-opengl-part-iv/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 13:00:29 +0000</pubDate>
		<dc:creator>Timothy M. Rodriguez</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[glut]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://laststop.spaceislimited.org/?p=21</guid>
		<description><![CDATA[OpenGL OpenGL is the Open Graphics Library and it is maintained by the Kronos Group, which is a consortium of top-tier companies that include board members such as ATI nVidia, Apple, IBM, and more. Microsoft used to be on the consortium, but left and decided to make DirectX, a competing closed graphics library that only [...]]]></description>
			<content:encoded><![CDATA[<h2>OpenGL</h2>
<p>OpenGL is the Open Graphics Library and it is maintained by the Kronos Group, which is a consortium of top-tier companies that include board members such as ATI nVidia, Apple, IBM, and more.  Microsoft used to be on the consortium, but left and decided to make DirectX, a competing closed graphics library that only runs on Windows (at least without some sort of emulation layer or wrapper like Wine or Cedega).</p>
<p><span id="more-21"></span></p>
<p>First off, OpenGL is a huge thing to master (and I am nowhere near mastery).  I can’t explain everything about it in one post (or even in hundreds), but I strongly encourage you to get the OpenGL “<a type="amzn">Red Book</a>” to start out.  The “Red Book” is the official and definitive guide to OpenGL and is a must have for any graphics programmer.  I also recommend the <a type="amzn">K&amp;R C Programming book</a> and, if you’re interested in the back-end math, the <a type="amzn">Real-Time Rendering book</a>.</p>
<p>That being said, in our pong clone, we only use a few OpenGL functions.  I’m going to  list them and tell you what they do, but it may take until the next post to really understand how they work.</p>
<p>First, a word about primitives.  OpenGL has only a few key primitives that you can draw with, but that&#8217;s okay, because you can use the primitives to draw more complex shapes!</p>
<p>The OpenGL primitives are:</p>
<ul>
<li>Points &#8211; a simple point in space</li>
<li>Lines &#8211; a 2-dimension line (although it can occupy 3-dimensional space)</li>
<li>Polygons &#8211; a polygon is a simple 2-dimensional shape comprised of 3 or more points.  Triangles, or 3-point polygons, deserve special attention, because OpenGL will break up any other polygon into a combination of triangles.  For example, a square can be broken up into two triangles along its diagonal.  Just about every object you see in OpenGL is comprised of triangles!</li>
</ul>
<p>So let&#8217;s draw a simple quadrilateral!  In OpenGL, you draw polygons by calling a function whenever you want to draw a polygon and then creating a bunch of points in space to create that polygon.  Once you&#8217;re done, you call another function to say you&#8217;re done.</p>
<p>Here&#8217;s an example for drawing a rectangle (our pong paddle):</p>
<blockquote><p><span>glBegin</span><span>(</span>GL_QUADS<span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(-</span><span>10</span><span>, -</span><span>50</span><span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(-</span><span>10</span><span>, </span><span>50</span><span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(</span><span>10</span><span>, </span><span>50</span><span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(</span><span>10</span><span>, -</span><span>50</span><span>);</span></p>
<p><span><span> </span></span>glEnd<span>();</span></p></blockquote>
<p>We start by calling glBegin() and sending it GL_QUADS to indicate we want to draw a quadrilateral.  This basically tells OpenGL take every four points I send you and make a quad out of it.  We then call glVertex2f() and send it the coordinates of a two-dimensional point.  the 2f indicates that this is the glVertex function which takes 2 floating point values as its arguments (or inputs).  We then call glVertex2f() once for all four of each of our points and then call glEnd() when we&#8217;re done.</p>
<p>We could have optionally set a color before we began to draw that quadrilateral (the default is black on black) by calling this function:</p>
<blockquote><p>glColor3ub<span>(</span><span>255</span><span>, </span><span>0</span><span>, </span><span>0</span><span>);<span> </span></span><span>//red</span></p></blockquote>
<p>Again we see the OpenGL naming convention of starting off a function with gl and then ending it with letters and numbers that indicate its arguments.  In this case the 3ub means 3 unsigned bytes.  Each unsigned byte is positive (hence unsigned) and can go from 0 to 255.  The order of the bytes indicate the amount of Red, Green, and Blue respectively that will mix to give you your final color.  (Color theory is another big subject matter I can post more about in another post, so let me know in the comments!)</p>
<p>Two other functions that are usually called at the beginning of every display function are:</p>
<blockquote><p><span>glClear</span><span>(</span>GL_COLOR_BUFFER_BIT<span> | </span>GL_DEPTH_BUFFER_BIT<span>);</span></p>
<p><span><span> </span></span>glShadeModel<span>(</span><span>GL_FLAT</span><span>);</span></p></blockquote>
<p>glClear(), quite simply is a function that clears the screen and uses the values specified as its argument for doing so.</p>
<p>glShadeModel() specifies the shading model for how vertexes (points) are shaded or lit.  In this case, we&#8217;re going for a simple flat colored 2-d look so we use GL_FLAT.  This paints everything on screen with whatever colors specified and doesn&#8217;t do anything fancy.  It&#8217;s sort of like painting in mspaint on Windows.</p>
<blockquote><p>glPushMatrix<span>();</span></p>
<p>glPopMatrix();</p>
<p><span><span> </span></span>glTranslatef<span>(</span><span>30.0f</span><span>, 10.</span><span>0f, 0.0f</span><span>);</span></p></blockquote>
<p>glPush and Pop Matrix() are important functions.  They allow you to draw something as if you are starting from scratch with a new coordinate system.  Think about our pong paddle.  When you want to draw it some place else, do you really want to respecify the coordinates for how it&#8217;s drawn?  You could instead <em>push</em> a matrix (a set of points) on the stack, then <em>translate</em> (or move), to a new location and draw the object as you would anywhere else, and then finally <em>pop</em> the matrix which will draw the set of points translated (moved) by the glTranslatef() function.  This is a little hard to understand (and explain), so I&#8217;ll give an example.</p>
<p>In Part II we talked about drawing a box that moved across the screen.  We could draw our box as a point in a 2-dimensional plane.  For example, let&#8217;s make a square that is 4 across centered at the origin (0,0).  So it&#8217;s points are, going counter-clockwise, (1,1), (-1,1), (-1,-1), (1,-1).  Rather than figuring out how to move it along for every frame.  We can do this.</p>
<blockquote><p>glPushMatrix<span>();</span></p>
<p><span> </span></p>
<p><span><span> </span></span>glColor3ub<span>(</span><span>255</span><span>, </span><span>0</span><span>, </span><span>0</span><span>);<span> </span></span><span>//red</span></p>
<p><span> </span></p>
<p><span><span> </span></span>glTranslatef<span>(</span><span>x, 0.0f, </span><span>0.0f</span><span>);</span></p>
<p><span> </span></p>
<p><span><span> </span></span><span>glBegin</span><span>(</span>GL_QUADS<span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(1,1</span><span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(-1,1</span><span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(</span><span>-1,-1</span><span>);</span></p>
<p><span><span> </span></span>glVertex2f<span>(</span><span>1,-1</span><span>);</span></p>
<p><span><span> </span></span>glEnd<span>();</span></p>
<p><span> </span></p>
<p><span><span> </span></span>glPopMatrix<span>();</span></p></blockquote>
<p>So we push a matrix (a set of points) on the stack, switch the drawing color to red, then Translate x units in the x-direction (horizontal) and then set the drawing mode to GL_QUADS and push the points of our square as it is centered at the origin, and finally pop the matrix!  This has OpenGL do all the work of moving our square x units to the right.</p>
<p>Okay, that&#8217;s enough for now.  I encourage you to scour the web and read up more before we get to our next post, where I&#8217;ll finally post the code and go through it!</p>
]]></content:encoded>
			<wfw:commentRss>http://laststop.spaceislimited.org/2008/07/01/programming-pong-in-c-and-opengl-part-iv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Pong in C and OpenGL &#8211; Part III</title>
		<link>http://laststop.spaceislimited.org/2008/06/27/programming-pong-in-c-and-opengl-part-iii/</link>
		<comments>http://laststop.spaceislimited.org/2008/06/27/programming-pong-in-c-and-opengl-part-iii/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 15:35:17 +0000</pubDate>
		<dc:creator>Timothy M. Rodriguez</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[glut]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://laststop.spaceislimited.org/?p=20</guid>
		<description><![CDATA[Sorry for the delay in this post, but here’s Part III. For reference, you probably want to start out with Part’s II and I here and here. Last we left off I said I’d get into some of the basic mechanics of GLUT and OpenGL, so let’s hit the ground running. GLUT GLUT, or the [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the delay in this post, but here’s Part III.</p>
<p>For reference, you probably want to start out with Part’s II and I <a title="Programming Pong Part II" href="http://laststop.spaceislimited.org/2008/06/02/programming-pong-in-c-and-opengl-part-ii/" target="_blank">here</a> and <a title="Programming Pong in C and OpenGL - Part I" href="http://laststop.spaceislimited.org/2008/05/17/programming-a-pong-clone-in-c-and-opengl-part-i/" target="_blank">here</a>.</p>
<p>Last we left off I said I’d get into some of the basic mechanics of GLUT and OpenGL, so let’s hit the ground running.</p>
<h3>GLUT</h3>
<p>GLUT, or the Graphics Library Utility Toolkit, is a cross-platform C library for generating windows and handling IO events.  Basically, GLUT was written so you can get to learning OpenGL very quickly without having to spend enormous amounts of time learning how to handle mouse or keyboard actions in your current OS, or worse, learn how to setup a simple GUI just so you can see your work.  On top of making these tasks simpler, GLUT is, as I mentioned, cross-platform.  This means that you can take your code and recompile it on another OS as long as you have the appropriate GLUT library referenced in your IDE.  There are currently versions of GLUT created for Linux, OS X, Windows, and probably even more operating systems.</p>
<p>So how do we create a simple window?</p>
<p><span id="more-20"></span></p>
<p>Here’s a snippet of code for how to do just that!</p>
<blockquote><p>int main(int argc, char** argv)<br />
{<br />
glutInit(&amp;argc, argv);</p>
<p>glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);<br />
glutInitWindowSize(500, 500);</p>
<p>glutCreateWindow(&#8220;Tim GL&#8221;);</p>
<p>glutDisplayFunc(display);<br />
glutReshapeFunc(reshape);<br />
glutKeyboardFunc(keyboard);<br />
glutKeyboardUpFunc(keyboardup);<br />
glutIdleFunc(idle);</p>
<p>glutMainLoop();<br />
return EXIT_SUCCESS;<br />
}</p></blockquote>
<p>You start off with your regular main function in C.  Then you call the glutInit function and pass it is passed any parameters you may have passed to main.  For this tutorial you won’t be needing any, so don’t worry about it.  If you need to find out more, check out the GLUT Documentation.</p>
<p>Next, you pass the glutInitDisplayMode() function a “logically OR-ed” value of GLUT_RGBA, GLUT_DOUBLE, and GLUT_DEPTH.  If you don’t know what logically OR-ed means, just think of it as smooshing all these flags together to set the display mode with all of these properties.  (If you want an in-depth explanation of this, just ask and I’ll put up a post about it!).</p>
<p>After this, we set the pixel dimensions (size) of the window to 500&#215;500 pixels with the line “glutInitWindowSize(500,500);”.  We next set the window’s title bar with “glutCreateWindow(”Tim GL”);”  You can set either of these last two functions to whatever value you wish!</p>
<p>Next, is the pretty interesting part.  And to understand it you need to understand a little bit about Call-Back functions.  Call-Back functions are functions that hold a pointer to another function and call it when some event happens.  (This is also why Call-Back functions are usually regarded as “Event-Driven Programming”.)  To explain this it’s best to show you by example.  I’ll start with the glutKeyboardFunc(keyboard).  Whenever a key is pressed down, we have set glutKeyboardFunc() to call ANOTHER function called keyboard that WE have defined.  The function is not show here, but we will get to that in the next post!  Suffice it to say, our keyboard function will handle certain things like “what to do when the up arrow is pressed” in our Pong clone.</p>
<p>It is important to understand that we can’t just write a function that constantly checks the keyboard like this</p>
<blockquote><p>while(TRUE) {</p>
<p>whatIsTheKeyboardDoing();</p>
<p>}</p></blockquote>
<p>because we’d be in an infinite loop and never be able to do anything else.  The Call-Back function allows us to be “called back” whenever someone presses the keyboard.</p>
<p>Now that we’ve explained that, the rest of the functions are easy to describe:</p>
<ul>
<li>glutDisplayFunc() is called most of the time and is the function that paints our screen with whatever we tell it to with OpenGl</li>
<li>glutReshapeFunc() is what is called whenever the user resizes the window (In case we need to do anything special if the user all of a sudden changes the screen size on us.)</li>
<li>glutKeyboardFuncUp() is a tricky one, and it’s what is called whenever a key is “depressed”, or let go.  This is a subtle point, but it is useful to know when someone presses a key and let’s go of one.  Without this, you wouldn’t be able to tell when someone was holding a key.</li>
<li>glutIdleFunc()  this is the function that is called whenever there is nothing to do!</li>
</ul>
<p>So that’s it!  That’s about all you need to know for GLUT for now!  Check out the next post for OpenGL.</p>
]]></content:encoded>
			<wfw:commentRss>http://laststop.spaceislimited.org/2008/06/27/programming-pong-in-c-and-opengl-part-iii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Pong in C and OpenGL &#8211; Part II</title>
		<link>http://laststop.spaceislimited.org/2008/06/02/programming-pong-in-c-and-opengl-part-ii/</link>
		<comments>http://laststop.spaceislimited.org/2008/06/02/programming-pong-in-c-and-opengl-part-ii/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 01:50:22 +0000</pubDate>
		<dc:creator>Timothy M. Rodriguez</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[glut]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[This]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://laststop.spaceislimited.org/?p=17</guid>
		<description><![CDATA[This is the second part in what should be a four part series on how to program your very own Pong clone. The first article went over setting up your environment in your favorite OS, now this part gets into some of the mechanics or details on how to actually get started. Before I start [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part in what should be a four part series on how to program your very own Pong clone.  The first article went over setting up your environment in your favorite OS, now this part gets into some of the mechanics or details on how to actually get started.</p>
<p>Before I start with anything, we have to think about simple animation.  In fact, <a title="Animation" href="http://en.wikipedia.org/wiki/Animation" target="_blank">animation</a> is just simply a series of static images, with each image slightly displaced from the last.</p>
<p>So what does that mean?<span id="more-17"></span></p>
<p>For example, if I&#8217;m going to <span style="text-decoration: line-through;">draw</span> animate a ball falling from mid-air, I would first start with an image of the ball in mid-air, precisely as it would look the moment it began to fall.  The next <em>frame</em>, or image, would be exactly that, but with the ball a little bit lower down.  I would then continue to draw sequential images of the ball, with each image showing it a little bit further than the last.  This is how <strong>every</strong> moving image you see works (well, just about).  A series of images is drawn in front of you, quick enough that you can&#8217;t tell.</p>
<p>So the next question is, what&#8217;s quick enough?  It turns out, this isn&#8217;t such a simple question.  In fact, the answer is different for different animals!  But for humans, it turns out, about 30fps, or 30 frames-per-second, is what it takes to fool us.  The movies you see in the theatre are (at-the-moment anyways) displayed at 24fps, but most computer screens require 60fps to prevent you from seeing the flicker (some, like myself, need an 85Hz (fps) refresh rate, others up to 120!).  The reasons for these differences has a lot to do with the way the image is drawn and the way your eye views things.  It&#8217;s a pretty involved topic, but if you guys would like me to go into it more, let me know in the comments.</p>
<h3>A Simple Animation Loop</h3>
<p>Taking what we just learned, let&#8217;s think about how to draw a box moving across the screen.  Let&#8217;s pretend we have a function that draws a box centered at a point we specify on the screen (in 2-D Space).  It&#8217;s C function prototype would look something like this:</p>
<blockquote><p>void drawbox(int x, int y);</p></blockquote>
<p>So if we were going to draw a box that just infinitely moved to the right (or at least until it was off screen).  We might decide to create a loop that drew it a little bit further each time.  That might look something like this:</p>
<blockquote><p>#define TRUE 1</p>
<p>int x=0;</p>
<p>while(TRUE) {</p>
<p>drawbox(0+x, 0);</p>
<p>x++;</p>
<p>}</p></blockquote>
<p>This little snippet of code, runs an infinite loop and draws a box at a point 0+x, 0 and then increments x.  Let&#8217;s look a little further.  First it draws a box at point(0,0) since x is 0 on first count.  Then x is incremented and the loop goes on again.  Next, it draws a box at (1,0) and increments x.  And so on.  Congratulations, you just made your first animation loop!</p>
<h3>Marching Onward</h3>
<p>In the beginning, video games were hand-coded in assembly directly to a particular hardware.  This had a lot of benefits, primarily speed, which was very important when hardware was relatively expensive.  But as computers progressed and the market expanded, it became necessary to program for a multitude of different hardwares.  And this is when a nasty problem reared it&#8217;s head.  You see, when you decide to have the computer draw something on the screen, it doesn&#8217;t just do it instantaneously.  The computer has to go and draw each individual pixel on the screen (also a topic for another discussion).</p>
<p>This</p>
<p style="padding-left: 30px;">takes</p>
<p style="padding-left: 60px;">time.</p>
<p>Moreover, the time it takes on your brand-spanking new ultra-super processor is not the same time it takes your friend down the street who isn&#8217;t as <em>enthusiastic</em> as you are.  This is a problem, because if you set up all your animations expecting the processor to draw 30 frames per second on your machine.  It&#8217;s going to run at less than that on your friends machine.  (In fact, there&#8217;s some math that shows it will be a fraction/multiple of their refresh rate).  Great, so your fast-action shoot-em-up just got stuck in the mud.</p>
<h3>What&#8217;s a game programmer to do?</h3>
<p>There&#8217;s a really simple answer to all of this&#8211;use our friend (archenemy) time.  You see, rather than making your animation speed depend on the animation loop (which depends on your processor speed), have the your animation be a fixed function of time.</p>
<p>Take another look at our first example.  The movement speed of the box can really be expressed as 1 unit in the x direction per loop iteration.  Really what we want is for the box to move some number of units in the x direction per second (our hour if you like).  To do this we need to express our box movement as a function of time and then know how long its been since the computer last drew the box.  Essentially, we want our animation loop to look like this.</p>
<blockquote><p>#define TRUE 1</p>
<p>int speed = 1;     //1 unit per second</p>
<p>int x = 0;</p>
<p>startTime = 0;</p>
<p>elapsedTime = 0;</p>
<p>while(TRUE) {</p>
<p>startTime = getTime();</p>
<p>x += speed * elapsedTime;</p>
<p>drawbox(0+x, 0)</p>
<p>elapsedTime = getTime() &#8211; startTime;</p>
<p>}</p></blockquote>
<p>As you can see, this simple example becomes a lot more complicated once we add timing to the mix.  First, we defined a universal speed for our box.  We still kept the x value, as this represents the boxes point in space, not it&#8217;s speed.  Then we created variables for keep track when we started our animation loop and how long we were in it.  We&#8217;re also assuming we have a function that gives us the time, called getTime() here, and that it returns us the current time in seconds.</p>
<p>First we enter our loop and fetch our start time from the getTime() function.  Next we set our x position based on how long it&#8217;s been since our last loop.  We multiply our elapsedTime by the speed of our box and add that <em>distance</em> to our x-position.  Then, we draw our box at it&#8217;s new position.  Finally, we figure out how long it took us to draw that box by setting our elapsed time equal to the current time minus the time we started drawing the box.  Now, no matter the computer, our box will move along the screen at the same speed.  Note, this does not mean the animation is fluid!  If your friend&#8217;s computer is really slow (and I mean really if it can&#8217;t draw a box) it may only get to draw a box once every 5 seconds.  By then, our box may already be off the screen!</p>
<p>So I hope that&#8217;s enough for you to digest for a while. Stay tuned for my next post on some of the basic mechanics of GLUT and OpenGL.  Until then, it might be useful to brush up on your C programming on the interwebs!</p>
]]></content:encoded>
			<wfw:commentRss>http://laststop.spaceislimited.org/2008/06/02/programming-pong-in-c-and-opengl-part-ii/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Technology of a 3D Engine</title>
		<link>http://laststop.spaceislimited.org/2008/05/22/technology-of-a-3d-engine/</link>
		<comments>http://laststop.spaceislimited.org/2008/05/22/technology-of-a-3d-engine/#comments</comments>
		<pubDate>Thu, 22 May 2008 14:49:10 +0000</pubDate>
		<dc:creator>Timothy M. Rodriguez</dc:creator>
				<category><![CDATA[Technical Nonsense]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scenegraph]]></category>

		<guid isPermaLink="false">http://laststop.spaceislimited.org/?p=15</guid>
		<description><![CDATA[There&#8217;s a great article on Beyond3D about the technology of a 3D engine. The article&#8217;s split up into parts and part two was just released (after a several month wait!). Part one discusses a lot of the general concepts for a 3D engine design in an easy to read and abstract level, but part two [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://laststop.spaceislimited.org/wp-content/uploads/2008/05/400px-octree2.png"><img class="aligncenter size-full wp-image-16" title="400px-octree2" src="http://laststop.spaceislimited.org/wp-content/uploads/2008/05/400px-octree2.png" alt="Lions and Tigers and Octrees!  Oh My!" width="400" height="230" /></a></p>
<p>There&#8217;s a great article on Beyond3D about the technology of a 3D engine.  The article&#8217;s split up into parts and part two was just released (after a several month wait!).  Part one discusses a lot of the general concepts for a 3D engine design in an easy to read and abstract level, but part two goes into deeper detail.  Both make for interesting reads, though part two sort of jumps into an ocean at no discernible point.  (It covers scenegraphs I know, but why start there?  Why not animation?  Look for my own part two of programming a pong clone to animation and early concepts in game programming.)</p>
<ul>
<li><a title="Tech of a 3D Engine - Part 1" href="http://www.beyond3d.com/content/articles/98" target="_blank">Part One</a></li>
<li><a title="Tech of a 3d Engine - Part 2" href="http://beyond3d.com/content/articles/102" target="_blank">Part Two</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://laststop.spaceislimited.org/2008/05/22/technology-of-a-3d-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming Pong in C and OpenGL &#8211; Part I</title>
		<link>http://laststop.spaceislimited.org/2008/05/17/programming-a-pong-clone-in-c-and-opengl-part-i/</link>
		<comments>http://laststop.spaceislimited.org/2008/05/17/programming-a-pong-clone-in-c-and-opengl-part-i/#comments</comments>
		<pubDate>Sun, 18 May 2008 00:48:35 +0000</pubDate>
		<dc:creator>Timothy M. Rodriguez</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[glut]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[pong]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://laststop.spaceislimited.org/?p=13</guid>
		<description><![CDATA[If you ever wanted to program your own video game, this is a good place to start. I remember when I started learning programming it was surprisingly difficult to find out how to make an honest and simple game. In fact, after reading most programming books, the only type of game you could make would [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://laststop.spaceislimited.org/wp-content/uploads/2008/05/pongactionshot.png"><img class="aligncenter size-full wp-image-14" title="Pong" src="http://laststop.spaceislimited.org/wp-content/uploads/2008/05/pongactionshot.png" alt="Unbelievable Action!" width="499" height="518" /></a></p>
<p>If you ever wanted to program your own video game, this is a good place to start.  I remember when I started learning programming it was surprisingly difficult to find out how to make an honest and simple game.  In fact, after reading most programming books, the only type of game you could make would be a <a href="http://en.wikipedia.org/wiki/Zork">Zork</a> clone.</p>
<blockquote><p>You are in a dank cave and you can see nothing, but you hear a walrus in the distance.</p>
<p>What do you do?</p>
<ol>
<li>Look for the walrus.</li>
<li>Watch <a href="http://www.imdb.com/title/tt0118715/">The Big Lebowski</a></li>
<li>Decide that the walrus is Paul.</li>
</ol>
</blockquote>
<p>This is not to knock Zork in any way!  Zork is a clever, well written, and extremely well thought out game (even if my pseudo-quote isn&#8217;t).  But in a world where we&#8217;re spoiled by moving objects, you want to know how to move and interact with something on screen.  The problem is it takes a lot of different knowledge sets to get the job done.  But in this post, you&#8217;ll get started learning how to make your very own <a title="Pong" href="http://http//en.wikipedia.org/wiki/Pong" target="_blank">Pong</a> clone.<span id="more-13"></span></p>
<h3>A Few Notes..</h3>
<p>First, a few notes about setting up.  I&#8217;m writing this tutorial from the Mac OS X perspective.  However, everything we are about to code is, essentially, <strong>cross-platform</strong>.  This is because, it is written using plaing old C, OpenGL, and GLUT.  All of these things are themselves cross-platform, and therefore, can be compiled anywhere you have a C compiler (OpenGL and GLUT are just C libraries).</p>
<h3>Setting up your environment</h3>
<h4>Mac OS X</h4>
<p>For some reason, this always seems to be the hardest part whenever learning something new in programming.  Fortunately, I found a great blog post that makes setting up XCode for compiling an app using OpenGL and GLUT very easy.  Read all about setting up your <a title="XCode with OpenGL and GLUT" href="http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html" target="_blank">XCode</a>.</p>
<h4>Windows</h4>
<p>The process in Windows is actually a bit easier (gasp!) than in Mac OS X and there&#8217;s plenty of resources available on Google for getting setup.  Here&#8217;s one in <a title="Setting up OpenGL and GLUT in Windows" href="http://csf11.acs.uwosh.edu/cs371/visualstudio/" target="_blank">particular</a>.</p>
<h4>Linux</h4>
<p>Here&#8217;s something unusual, you guys get a <a title="OpenGL and GLUT in Linux" href="http://www.youtube.com/watch?v=p4hA-lcKTmE" target="_blank">video</a>.</p>
<p>Congratulations, the hardest part is done!  In my next blog post.  We&#8217;ll start to get knee deep in game programming concepts.</p>
<h2>Update!</h2>
<p><a title="Programming a Pong Clone - Part II" href="http://laststop.spaceislimited.org/2008/06/02/programming-pong-in-c-and-opengl-part-ii/" target="_self">Part II</a> is Up!</p>
]]></content:encoded>
			<wfw:commentRss>http://laststop.spaceislimited.org/2008/05/17/programming-a-pong-clone-in-c-and-opengl-part-i/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
