<?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>Wesley&#039;s Techblog &#187; Programming</title>
	<atom:link href="http://wesley.vidiqatch.org/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://wesley.vidiqatch.org</link>
	<description>This blog does not need a smart-ass tagline</description>
	<lastBuildDate>Wed, 09 Sep 2009 21:36:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>QPasm 1.1 RC1</title>
		<link>http://wesley.vidiqatch.org/09-09-2009/qpasm-1-1-rc1/</link>
		<comments>http://wesley.vidiqatch.org/09-09-2009/qpasm-1-1-rc1/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:11:27 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=537</guid>
		<description><![CDATA[The last few days I&#8217;ve been improving the small pseudo-assembler interpreter/IDE that I had created. I am quite happy with the result.

The new version of QPasm has the following new features:

Code editor with intelligent syntax highlighting, line numbering, visual breakpoints and undo/redo functionality
Debugging features: breakpoints, manual step, timed step, pausing
On-the-fly editing of data in the [...]]]></description>
			<content:encoded><![CDATA[<p>The last few days I&#8217;ve been improving the small pseudo-assembler interpreter/IDE that I had created. I am quite happy with the result.</p>
<p><a href="http://wesley.vidiqatch.org/images/qpasm_1.1_rc1.png"><img class="alignnone" title="QPasm 1.1 RC1" src="http://wesley.vidiqatch.org/images/qpasm_1.1_rc1.png" alt="" width="625" height="394" /></a></p>
<p>The new version of QPasm has the following <strong>new</strong> features:</p>
<ul>
<li>Code editor with intelligent syntax highlighting, line numbering, visual breakpoints and undo/redo functionality</li>
<li>Debugging features: breakpoints, manual step, timed step, pausing</li>
<li>On-the-fly editing of data in the register or the memory</li>
<li>On-the-fly symbol resolving: labels can be used in assembler apps, and when modifying memory when the program is running the labels are resolved automatically</li>
<li>Integrates well with light and dark system themes. Highlighter chooses its color theme based on the darkness of the theme automatically, but colors and fonts can be configured manually as well</li>
<li>Layout, font and color settings are stored locally in a portable config.ini file</li>
<li>Input format is very flexible: white space may occur before, after and between instructions, instructions are case insensitive, comments are supported anywhere</li>
<li>Pseudo-assembler apps which are run using the run-function run in a separate thread which has a system preventing the GUI from freezing by limiting the amount of simultaneous signals to the GUI. Assembler apps which cause an endless loop cannot freeze the GUI</li>
</ul>
<p>More information, binaries and source code are available at <a href="http://code.google.com/p/qpasm/">http://code.google.com/p/qpasm/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/09-09-2009/qpasm-1-1-rc1/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Small pseudo-assembler interpreter</title>
		<link>http://wesley.vidiqatch.org/30-08-2009/small-pseudo-assembler-interpreter/</link>
		<comments>http://wesley.vidiqatch.org/30-08-2009/small-pseudo-assembler-interpreter/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 14:02:56 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=527</guid>
		<description><![CDATA[I had to develop a pseudo-assembler interpreter for the course Microprocessing.
Since it was just lying around on my hard drive I figured I could just as well put it on-line. It contains a few things that might be interesting to developers:

Using a C library in C++/Qt applications and translating C function callbacks into Qt signals
Implementation [...]]]></description>
			<content:encoded><![CDATA[<p>I had to develop a <strong>pseudo-assembler interpreter</strong> for the course <em><strong>Microprocessing</strong></em>.</p>
<p>Since it was just lying around on my hard drive I figured I could just as well put it on-line. It contains a few things that might be interesting to developers:</p>
<ul>
<li>Using a C library in C++/Qt applications and translating C function callbacks into Qt signals</li>
<li>Implementation of virtual static and virtual dynamic memory</li>
<li>Converting between virtual signed and unsigned values (system independent)</li>
<li>Saving data and instructions in same virtual memory (Von Neumann architecture)</li>
</ul>
<p style="text-align: center;"><a href="http://wesley.vidiqatch.org/files/qpasm/qpasm_1.0_screen.png"><img class="aligncenter" title="QPasm 1.0" src="http://wesley.vidiqatch.org/files/qpasm/qpasm_1.0_screen.png" alt="" width="614" height="340" /></a></p>
<p>More information (and source code) is available here: <a href="http://wesley.vidiqatch.org/files/qpasm/">http://wesley.vidiqatch.org/files/qpasm/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/30-08-2009/small-pseudo-assembler-interpreter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Overriding dynamic library calls (function interposition)</title>
		<link>http://wesley.vidiqatch.org/18-08-2009/overriding-dynamic-library-calls-function-interposition/</link>
		<comments>http://wesley.vidiqatch.org/18-08-2009/overriding-dynamic-library-calls-function-interposition/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 07:32:57 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=497</guid>
		<description><![CDATA[About function interposition
I was wondering how I could override dynamic library calls in Linux, and I came across this technique known as function interposition. It is a powerful technique that allows you to override dynamic library calls. It might sound dull, but it can be very, very useful. There are some memory trace tools that [...]]]></description>
			<content:encoded><![CDATA[<h4>About function interposition</h4>
<p>I was wondering how I could <em>override dynamic library calls</em> in Linux, and I came across this technique known as <strong>function interposition</strong>. It is a powerful technique that allows you to override dynamic library calls. It might sound dull, but it can be very, very useful. There are some memory trace tools that make use of this technique to work, but perhaps a cooler example is the <a href="http://nullkey.ath.cx/projects/glc/">OpenGL capture system</a> which was created by <a href="nullkey.ath.cx">nullkey</a>: it can capture OpenGL frames by overriding certain OpenGL functions. Another example are cheat tools (wallhacks, aimbots) which also make use of this technique a lot.</p>
<h4>Some background</h4>
<p>While Googling <em>(did I spell that right?)</em> I came across <a href="http://www.jayconrod.com/cgi/view_post.py?23">this</a> recent blog article which explains the background very well. I will quote it here:</p>
<blockquote><p>First, some background. When a program that uses dynamic libraries is compiled, a list of undefined symbols is included in the binary, along with a list of libraries the program is linked with. There is no correspondence between the symbols and the libraries; the two lists just tell the loader which libraries to load and which symbols need to be resolved. At runtime, each symbol is resolved using the first library that provides it. This means that if we can get a library containing our wrapper functions to load before other libraries, the undefined symbols in the program will be resolved to our wrappers instead of the real functions.</p></blockquote>
<p>So if we create a custom shared library which overrides some of the functions of the original library, our functions will be called instead of those of the original library.</p>
<h4>How to do it</h4>
<ul>
<li>Write new functions which override existing functions</li>
<li>Compile the written code to a dynamic library that is linked to the dynamic linking interface library</li>
<li>Use the <em>LD_PRELOAD</em> environment variable when running an application to preload your custom library before all other dynamic libraries</li>
</ul>
<p><a href="http://www.jayconrod.com/cgi/view_post.py?23">The article by Jay Conrod</a> has an example which shows you the basic implementation of a simple memory allocation tracer.</p>
<p>I have also cooked up an example myself. Because I&#8217;ve been busy learning more about OpenGL, I thought that it shouldn&#8217;t be too hard to create a wallhack for one of my favourite games: <a href="http://en.wikipedia.org/wiki/Soldier_of_Fortune_II:_Double_Helix">Soldier of Fortune 2</a> running in Wine. Just for testing purposes of course! I am no cheater <img src='http://wesley.vidiqatch.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  It turned out to be relatively simple, although my first tries weren&#8217;t so very successful:</p>
<ul>
<li><a href="http://wesley.vidiqatch.org/images/hack_v1.png">Epic fail</a> &#8211; At least I know my library is used now.</li>
<li><a href="http://wesley.vidiqatch.org/images/hack_v2.png">Partial success</a> &#8211; Disabling depth testing completely was only a partial success.</li>
<li><a href="http://wesley.vidiqatch.org/images/hack_v3.png">Success</a> &#8211; A debugger can tell that players are drawn using glDrawElements(). By knowing the number of elements for each character, we can disable depth testing selectively.</li>
</ul>
<div class="wp-caption aligncenter" style="width: 568px"><a href="/images/hack_v3.png"><img title="SoF2 wallhack" src="/images/hack_v3.png" alt="Soldier of Fortune 2 wallhack example" width="558" height="430" /></a><p class="wp-caption-text">Soldier of Fortune 2 wallhack example</p></div>
<p>For those of you who are interested in the code:</p>
<div class="codecolorer-container cpp-qt default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="cpp-qt codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #888888; font-style: italic;">/*<br />
&nbsp; &nbsp; Simple wallhack example for Soldier of Fortune 2 (Wine) in Linux using function interposition<br />
<br />
&nbsp; &nbsp; This code snippet was written by Wesley Stessens (wesley@ubuntu.com)<br />
&nbsp; &nbsp; It is released in the Public Domain.<br />
<br />
&nbsp; &nbsp; Compilation: gcc -Wall -ansi -pedantic -shared -ldl -fPIC glhack.c -o glhack.so<br />
&nbsp; &nbsp; Usage: LD_PRELOAD=glhack.so wine game.exe<br />
*/</span><br />
<br />
<span style="color: #006E28;">#define _GNU_SOURCE</span><br />
<span style="color: #006E28;">#include &lt;dlfcn.h&gt;</span><br />
<span style="color: #006E28;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #006E28;">#include &lt;stdint.h&gt;</span><br />
<span style="color: #006E28;">#include &lt;GL/gl.h&gt;</span><br />
<br />
<span style="color: #888888; font-style: italic;">/* Override the glDrawElements function */</span><br />
GLAPI <span style="color: #0057AE;">void</span> GLAPIENTRY glDrawElements<span style="color: #006E28;">&#40;</span>GLenum mode<span style="color: #006E28;">,</span> GLsizei count<span style="color: #006E28;">,</span> GLenum type<span style="color: #006E28;">,</span> <span style="color: #0057AE;">const</span> GLvoid <span style="color: #006E28;">*</span>indices<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #888888; font-style: italic;">/* Store the actual function in a static function pointer */</span><br />
&nbsp; &nbsp; <span style="color: #0057AE;">static</span> <span style="color: #0057AE;">void</span> <span style="color: #006E28;">&#40;</span><span style="color: #006E28;">*</span>glDrawElements_<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#40;</span>GLenum mode<span style="color: #006E28;">,</span> GLsizei count<span style="color: #006E28;">,</span> GLenum type<span style="color: #006E28;">,</span> <span style="color: #0057AE;">const</span> GLvoid <span style="color: #006E28;">*</span>indices<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">=</span> NULL<span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span><span style="color: #006E28;">!</span>glDrawElements_<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; glDrawElements_ <span style="color: #006E28;">=</span> <span style="color: #006E28;">&#40;</span><span style="color: #0057AE;">void</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">*</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#40;</span>intptr_t<span style="color: #006E28;">&#41;</span>dlsym<span style="color: #006E28;">&#40;</span>RTLD_NEXT<span style="color: #006E28;">,</span> <span style="color: #BF0303;">&quot;glDrawElements&quot;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2B74C7;">puts</span><span style="color: #006E28;">&#40;</span><span style="color: #BF0303;">&quot;GLHack: glDrawElements call has been overridden&quot;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <span style="color: #006E28;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #888888; font-style: italic;">/* Disable depth testing if the number of elements to draw is one of the following, which means a player is being drawn */</span><br />
&nbsp; &nbsp; <span style="color: #888888; font-style: italic;">/* To avoid abuse of this code by cheaters, I have changed all count constants below to VALUEX */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span>count <span style="color: #006E28;">==</span> VALUE1 <span style="color: #006E28;">||</span> count <span style="color: #006E28;">==</span> VALUE2 <span style="color: #006E28;">||</span> count <span style="color: #006E28;">==</span> VALUE3 <span style="color: #006E28;">||</span> count <span style="color: #006E28;">==</span> VALUE4<span style="color: #006E28;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; glDisable<span style="color: #006E28;">&#40;</span>GL_DEPTH_TEST<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; glEnable<span style="color: #006E28;">&#40;</span>GL_DEPTH_TEST<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; glDrawElements_<span style="color: #006E28;">&#40;</span>mode<span style="color: #006E28;">,</span> count<span style="color: #006E28;">,</span> type<span style="color: #006E28;">,</span> indices<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<span style="color: #006E28;">&#125;</span></div></td></tr></tbody></table></div>
<h4>Interesting thought about multiplayer cheats and Wine</h4>
<p>If anti-cheat tools would perform a sanity check of the OpenGL or DirectX DLL, they would only find the virtual DLL&#8217;s when a game is run in Wine, right? I&#8217;m wondering whether this sort of cheats can be made undetectable then. In a way I hope not, because cheaters are very annoying when you&#8217;re playing a game, but on the other hand, it would be an amazing technological achievement. Anyway, anti-cheat tools like <em>PunkBuster</em> don&#8217;t even work with Wine at the moment, so it might be a non-issue. What are your thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/18-08-2009/overriding-dynamic-library-calls-function-interposition/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Code snippets</title>
		<link>http://wesley.vidiqatch.org/12-08-2009/code-snippets/</link>
		<comments>http://wesley.vidiqatch.org/12-08-2009/code-snippets/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 16:38:17 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=460</guid>
		<description><![CDATA[I&#8217;ve created a new page where I will upload small code snippets that I created and which might be useful for some. Most code snippets are released in the Public Domain. The code snippets might not have the highest quality, so feel free to propose improvements to them if you feel like it.
PS: I have [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a <a href="/code-snippets/">new page</a> where I will upload small code snippets that I created and which might be useful for some. Most code snippets are released in the <em>Public Domain</em>. The code snippets might not have the highest quality, so feel free to propose improvements to them if you feel like it.</p>
<p><em>PS: I have moved the &#8220;safe replacement for gets&#8221; blogpost to the code snippets page and have moved over all the comments as well.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/12-08-2009/code-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NeHe OpenGL lessons in Qt &#8211; Chapter 4</title>
		<link>http://wesley.vidiqatch.org/08-08-2009/nehe-opengl-lessons-in-qt-chapter-4/</link>
		<comments>http://wesley.vidiqatch.org/08-08-2009/nehe-opengl-lessons-in-qt-chapter-4/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 23:43:25 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=414</guid>
		<description><![CDATA[As promised, the fourth chapter of the NeHe OpenGL lessons ported to make use of the Qt toolkit.
 
Fourth chapter: fog, fonts revisited, quadrics, particle engine, triangle strips, masking
In the fourth chapter you will learn a few cooler tricks. You will learn how to create good-looking fog effects and how certain objects can easily be [...]]]></description>
			<content:encoded><![CDATA[<p>As promised, the fourth chapter of the <a href="http://nehe.gamedev.net/">NeHe OpenGL lessons</a> ported to make use of the <a href="http://www.qtsoftware.com/">Qt toolkit</a>.</p>
<p style="text-align: center;"><img title="OpenGL" src="http://www.fabioruini.eu/blog/wp-content/uploads/2008/07/opengl_logo.png" alt="" width="137" height="72" /> <img title="Qt 4" src="http://www.qtsoftware.com/logo.png" alt="" width="174" height="71" /></p>
<h4>Fourth chapter: fog, fonts revisited, quadrics, particle engine, triangle strips, masking</h4>
<p>In the <a href="http://nehe.gamedev.net/lesson.asp?index=04">fourth chapter</a> you will learn a few cooler tricks. You will learn how to create good-looking fog effects and how certain objects can easily be constructed using quadrics. But the coolest thing that you will learn is how to create a simple <strong>particle engine</strong> (during lesson 19). To end off the chapter, you will learn how you can use masking to create partial transparency using bitmap textures.</p>
<p><em>Some minor modifications were made to improve the visual appearance of some of the lessons.</em></p>
<p><img class="aligncenter" title="Particle engine" src="http://wesley.vidiqatch.org/images/particles_snapshot.png" alt="" width="386" height="269" /></p>
<h4>Videos and source code</h4>
<p><a href="http://www.youtube.com/watch?v=SksYPqFCj4M&amp;fmt=18">This video</a> shows the fog effect (lesson 16)<br />
<a href="http://www.youtube.com/watch?v=5TxEGk6W-YU&amp;fmt=18">This video</a> shows what you can achieve using quadrics (lesson 18)<br />
<a href="http://www.youtube.com/watch?v=0FfH9fx_hJo&amp;fmt=18">This video</a> shows the very cool particle engine that you will create! (lesson 19)<br />
<a href="http://www.youtube.com/watch?v=gfBfRVgi5FU&amp;fmt=18">This video</a> shows which effect masking has (lesson 20)<br />
You can download the Qt 4 source code for this chapter <a href="http://wesley.vidiqatch.org/files/chapter4.zip"><strong>here</strong></a>.</p>
<p><em>PS: The port of chapter 5 will take a while&#8230; I will be a bit busy the coming weeks, and the first lesson of chapter 5 is HUGE, so will require a lot of time to port.<br />
Oh, and apparently I forgot to upload the source code for the third chapter. I have uploaded it now <img src='http://wesley.vidiqatch.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/08-08-2009/nehe-opengl-lessons-in-qt-chapter-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NeHe OpenGL lessons in Qt – Chapter 3</title>
		<link>http://wesley.vidiqatch.org/04-08-2009/nehe-opengl-lessons-in-qt-chapter-3/</link>
		<comments>http://wesley.vidiqatch.org/04-08-2009/nehe-opengl-lessons-in-qt-chapter-3/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 19:57:01 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=409</guid>
		<description><![CDATA[Here is the third chapter of the NeHe OpenGL lessons ported to make use of the Qt toolkit.
 
Third chapter: waving texture, display lists and a lot of fonts
The third chapter starts off with a cool looking waving flag effect. After that you will learn about display lists. The last three lessons focus on different [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the third chapter of the <a href="http://nehe.gamedev.net/">NeHe OpenGL lessons</a> ported to make use of the <a href="http://www.qtsoftware.com/">Qt toolkit</a>.</p>
<p style="text-align: center;"><img title="OpenGL" src="http://www.fabioruini.eu/blog/wp-content/uploads/2008/07/opengl_logo.png" alt="" width="137" height="72" /> <img title="Qt 4" src="http://www.qtsoftware.com/logo.png" alt="" width="174" height="71" /></p>
<h4>Third chapter: waving texture, display lists and a lot of fonts</h4>
<p>The <a href="http://nehe.gamedev.net/lesson.asp?index=03">third chapter</a> starts off with a cool looking <strong>waving flag effect</strong>. After that you will learn about <strong>display lists</strong>. The last three lessons focus on different ways of <strong>displaying fonts</strong>. It is worth noting that rendering basic text at a chosen location, or translated into the OpenGL scene is extremely easy in Qt/OpenGL thanks to <a href="http://doc.qtsoftware.com/4.5/qglwidget.html#renderText">QGLWidget::renderText()</a>. For other basic text effects (such as rotated, skewed or otherwise transformed text) you could also use <a href="http://doc.qtsoftware.com/4.5/qpainter.html">QPainter</a> directly on a <a href="http://doc.qtsoftware.com/4.5/qglwidget.html">QGLWidget</a>. We won&#8217;t be doing this in our examples, but I just wanted to point out that it is possible.</p>
<p>I should also note that I have used an extra library in lesson 14 to display the 3D text. Qt itself is not able to display 3D text and doing this in a cross-platform way yourself would be rather hard. That&#8217;s why I have used the <a href="http://sourceforge.net/projects/ftgl/develop"><strong>FTGL</strong></a> library for this. FTGL is a very easy to use cross-platform library with the sole purpose of rendering (3D) text in OpenGL.</p>
<h4>Videos and source code</h4>
<p><a href="http://www.youtube.com/watch?v=jy3g5TV0WRg&amp;fmt=18">This video</a> shows the waving flag effect (lesson 11)<br />
<a href="http://www.youtube.com/watch?v=-uaRypjMJuo&amp;fmt=18">This video</a> shows the effect of using display lists (lesson 12)<br />
<a href="http://www.youtube.com/watch?v=MZlRzwxqw3c&amp;fmt=18">This video</a> shows rotated 3D text (lesson 14)<br />
You can download the Qt 4 source code for this chapter <a href="http://wesley.vidiqatch.org/files/chapter3.zip"><strong>here</strong></a>.</p>
<p><em>PS: You can expect chapter 4 in a few days <img src='http://wesley.vidiqatch.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/04-08-2009/nehe-opengl-lessons-in-qt-chapter-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Resizable photo frames in Qt</title>
		<link>http://wesley.vidiqatch.org/04-08-2009/resizable-photo-frames-in-qt/</link>
		<comments>http://wesley.vidiqatch.org/04-08-2009/resizable-photo-frames-in-qt/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 23:03:09 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=388</guid>
		<description><![CDATA[Today someone asked how to copy one image into another image in Qt. I thought it was a nice idea to write an example about how to do that, plus a few extra things. We will create a resizable photo frame from just one simple image of a photo frame! It works like this:

Reimplement QWidget::paintEvent() [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Today someone asked how to copy one image into another image in Qt. I thought it was a nice idea to write an example about how to do that, plus a few extra things. We will create a resizable photo frame from just one simple image of a photo frame!</strong> It works like this:</p>
<ul>
<li>Reimplement <a href="http://doc.qtsoftware.com/latest/qwidget.html#paintEvent">QWidget::paintEvent()</a> and construct a <a href="http://doc.qtsoftware.com/latest/qpainter.html">QPainter</a>(this) in the reimplementation so we can draw on the widget</li>
<li>Load the image of the photo frame and define 4 <a href="http://doc.qtsoftware.com/latest/qrect.html">QRect</a> objects to define the position of the frame borders &#8211; these borders are not allowed to scale</li>
<li>Draw something which will be contained inside of the frame &#8211; for example another image using <a href="http://doc.qtsoftware.com/latest/qpainter.html#drawPixmap">QPainter::drawPixmap()</a> or <a href="http://doc.qtsoftware.com/latest/qpainter.html#drawImage">QPainter::drawImage()</a></li>
<li>Generate and draw the frame bars (the pieces between the borders)
<ul>
<li>Make use of the <a href="http://doc.qtsoftware.com/latest/qimage.html#mirrored">QImage::mirrored()</a> function and another QPainter to create a new pixmap which contains the frame bar plus the mirrored frame bar.</li>
<li>This will make the bar look great when the frame bar is enlarged by tiling. This method is actually a very popular one in basic photo manipulation.</li>
</ul>
</li>
<li>Draw the four borders</li>
</ul>
<p><strong>The result looks like this:</strong></p>
<p><a href="http://wesley.vidiqatch.org/images/photowidget1.png">Photo frame in native size</a> &#8211; versus &#8211; <a href="http://wesley.vidiqatch.org/images/photowidget2.png">Enlarged photo frame</a></p>
<p><strong>The code looks like this:</strong></p>
<p style="text-align: center;">photowidget.h</p>
<div class="codecolorer-container cpp-qt default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="cpp-qt codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006E28;">#ifndef PHOTOWIDGET_H</span><br />
<span style="color: #006E28;">#define PHOTOWIDGET_H</span><br />
<br />
<span style="color: #006E28;">#include &lt;QtGui/QWidget&gt;</span><br />
<br />
<span style="color: #0057AE;">class</span> PhotoWidget <span style="color: #006E28;">:</span> <span style="color: #0057AE;">public</span> <a href="http://doc.trolltech.com/latest/qwidget.html"><span style="color: #22aadd;">QWidget</span></a> <span style="color: #006E28;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0057AE;">Q_OBJECT</span><br />
<br />
<span style="color: #0057AE;">public</span><span style="color: #006E28;">:</span><br />
&nbsp; &nbsp; PhotoWidget<span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qwidget.html"><span style="color: #22aadd;">QWidget</span></a> <span style="color: #006E28;">*</span>parent <span style="color: #006E28;">=</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
<span style="color: #0057AE;">protected</span><span style="color: #006E28;">:</span><br />
&nbsp; &nbsp; <span style="color: #0057AE;">void</span> paintEvent<span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpaintevent.html"><span style="color: #22aadd;">QPaintEvent</span></a> <span style="color: #006E28;">*</span>event<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
<span style="color: #0057AE;">private</span><span style="color: #006E28;">:</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> createBar<span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Orientation</span> orientation<span style="color: #006E28;">,</span> <span style="color: #0057AE;">const</span> <a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> <span style="color: #006E28;">&amp;</span>pixmap<span style="color: #006E28;">,</span> <span style="color: #0057AE;">const</span> <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a> <span style="color: #006E28;">&amp;</span>rect<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<span style="color: #006E28;">&#125;</span><span style="color: #006E28;">;</span><br />
<br />
<span style="color: #006E28;">#endif // PHOTOWIDGET_H</span></div></td></tr></tbody></table></div>
<p style="text-align: center;">photowidget.cpp</p>
<div class="codecolorer-container cpp-qt default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br /></div></td><td><div class="cpp-qt codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006E28;">#include &quot;photowidget.h&quot;</span><br />
<span style="color: #006E28;">#include &lt;QPainter&gt;</span><br />
<span style="color: #006E28;">#include &lt;QPaintEvent&gt;</span><br />
<br />
<span style="color: #006E28;">#define SIZE 108</span><br />
<br />
PhotoWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">PhotoWidget</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qwidget.html"><span style="color: #22aadd;">QWidget</span></a> <span style="color: #006E28;">*</span>parent<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">:</span> <a href="http://doc.trolltech.com/latest/qwidget.html"><span style="color: #22aadd;">QWidget</span></a><span style="color: #006E28;">&#40;</span>parent<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span><br />
&nbsp; &nbsp; resize<span style="color: #006E28;">&#40;</span>400<span style="color: #006E28;">,</span> 329<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; setWindowTitle<span style="color: #006E28;">&#40;</span><span style="color: #BF0303;">&quot;Photo Frame Example&quot;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<span style="color: #006E28;">&#125;</span><br />
<br />
<span style="color: #888888;">// This function generates a pixmap that can be used as a tiled bar.</span><br />
<span style="color: #888888;">// Note: We use a QPainter and the mirrored() function to make sure that the bar looks good when tiled.</span><br />
<span style="color: #888888;">// &nbsp; &nbsp; &nbsp; This technique is often applied in basic photo manipulation.</span><br />
<a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> PhotoWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">createBar</span><span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Orientation</span> orientation<span style="color: #006E28;">,</span> <span style="color: #0057AE;">const</span> <a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> <span style="color: #006E28;">&amp;</span>pixmap<span style="color: #006E28;">,</span> <span style="color: #0057AE;">const</span> <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a> <span style="color: #006E28;">&amp;</span>rect<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qimage.html"><span style="color: #22aadd;">QImage</span></a> barA <span style="color: #006E28;">=</span> pixmap.<span style="color: #2B74C7;">copy</span><span style="color: #006E28;">&#40;</span>rect<span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">toImage</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qimage.html"><span style="color: #22aadd;">QImage</span></a> barB <span style="color: #006E28;">=</span> barA.<span style="color: #2B74C7;">mirrored</span><span style="color: #006E28;">&#40;</span>orientation <span style="color: #006E28;">==</span> Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Horizontal</span> ? <span style="color: #0057AE;">true</span> <span style="color: #006E28;">:</span> <span style="color: #0057AE;">false</span><span style="color: #006E28;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; orientation <span style="color: #006E28;">==</span> Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Vertical</span> ? <span style="color: #0057AE;">true</span> <span style="color: #006E28;">:</span> <span style="color: #0057AE;">false</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qsize.html"><span style="color: #22aadd;">QSize</span></a> size<span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; size.<span style="color: #2B74C7;">setWidth</span><span style="color: #006E28;">&#40;</span>orientation <span style="color: #006E28;">==</span> Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Horizontal</span> ? barA.<span style="color: #2B74C7;">width</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&lt;&lt;</span> 1 <span style="color: #006E28;">:</span> barA.<span style="color: #2B74C7;">width</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; size.<span style="color: #2B74C7;">setHeight</span><span style="color: #006E28;">&#40;</span>orientation <span style="color: #006E28;">==</span> Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Vertical</span> ? barA.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&lt;&lt;</span> 1 <span style="color: #006E28;">:</span> barA.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> bar<span style="color: #006E28;">&#40;</span>size<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; bar.<span style="color: #2B74C7;">fill</span><span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">transparent</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qpainter.html"><span style="color: #22aadd;">QPainter</span></a> merger<span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&amp;</span>bar<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; merger.<span style="color: #2B74C7;">drawImage</span><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">,</span> barA<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight:bold;">if</span> <span style="color: #006E28;">&#40;</span>orientation <span style="color: #006E28;">==</span> Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Horizontal</span><span style="color: #006E28;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; merger.<span style="color: #2B74C7;">drawImage</span><span style="color: #006E28;">&#40;</span>barA.<span style="color: #2B74C7;">width</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> 0<span style="color: #006E28;">,</span> barB<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; merger.<span style="color: #2B74C7;">drawImage</span><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> barA.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> barB<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight:bold;">return</span> bar<span style="color: #006E28;">;</span><br />
<span style="color: #006E28;">&#125;</span><br />
<br />
<span style="color: #0057AE;">void</span> PhotoWidget<span style="color: #006E28;">::</span><span style="color: #2B74C7;">paintEvent</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpaintevent.html"><span style="color: #22aadd;">QPaintEvent</span></a> <span style="color: #006E28;">*</span>event<span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qpainter.html"><span style="color: #22aadd;">QPainter</span></a> p<span style="color: #006E28;">&#40;</span><span style="color: #000000; font-weight:bold;">this</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #888888;">// Our frame as one full image, and an image to put in the frame</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> frame<span style="color: #006E28;">&#40;</span><span style="color: #BF0303;">&quot;:/img/frame.png&quot;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qpixmap.html"><span style="color: #22aadd;">QPixmap</span></a> sky<span style="color: #006E28;">&#40;</span><span style="color: #BF0303;">&quot;:/img/palmtree.jpg&quot;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #888888;">// These four rectangles define the four borders of the frame</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a> topLeft<span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a> topRight<span style="color: #006E28;">&#40;</span>frame.<span style="color: #2B74C7;">width</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> SIZE<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a> bottomLeft<span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> frame.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a> bottomRight<span style="color: #006E28;">&#40;</span>frame.<span style="color: #2B74C7;">width</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> SIZE<span style="color: #006E28;">,</span> frame.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #888888;">// Draw the image first</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawPixmap</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span>40<span style="color: #006E28;">,</span> 40<span style="color: #006E28;">,</span> event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">width</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> 80<span style="color: #006E28;">,</span> event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">height</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> 80<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> sky<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #888888;">// Draw the bars</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawTiledPixmap</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">topRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">,</span> SIZE <span style="color: #006E28;">-</span> 1<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createBar<span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Horizontal</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame.<span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">topRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawTiledPixmap</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span>event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomLeft</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> <span style="color: #006E28;">-</span>SIZE <span style="color: #006E28;">-</span> 1<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createBar<span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Horizontal</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span>frame.<span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomLeft</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> <span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame.<span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawTiledPixmap</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomLeft</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> <span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createBar<span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Vertical</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame.<span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomLeft</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">+</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> <span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawTiledPixmap</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span>event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">topRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE <span style="color: #006E28;">+</span> 1<span style="color: #006E28;">,</span> <span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createBar<span style="color: #006E28;">&#40;</span>Qt<span style="color: #006E28;">::</span><span style="color: #2B74C7;">Vertical</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> <a href="http://doc.trolltech.com/latest/qrect.html"><span style="color: #22aadd;">QRect</span></a><span style="color: #006E28;">&#40;</span>frame.<span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">topRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> <span style="color: #006E28;">-</span>SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame.<span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #888888;">// Draw the borders</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawPixmap</span><span style="color: #006E28;">&#40;</span><a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> topLeft<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawPixmap</span><span style="color: #006E28;">&#40;</span>event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">topRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> 0<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> topRight<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawPixmap</span><span style="color: #006E28;">&#40;</span>event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomLeft</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>0<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> bottomLeft<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
&nbsp; &nbsp; p.<span style="color: #2B74C7;">drawPixmap</span><span style="color: #006E28;">&#40;</span>event<span style="color: #006E28;">-&gt;</span><span style="color: #2B74C7;">rect</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span>.<span style="color: #2B74C7;">bottomRight</span><span style="color: #006E28;">&#40;</span><span style="color: #006E28;">&#41;</span> <span style="color: #006E28;">-</span> <a href="http://doc.trolltech.com/latest/qpoint.html"><span style="color: #22aadd;">QPoint</span></a><span style="color: #006E28;">&#40;</span>SIZE<span style="color: #006E28;">,</span> SIZE<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">,</span> frame<span style="color: #006E28;">,</span> bottomRight<span style="color: #006E28;">&#41;</span><span style="color: #006E28;">;</span><br />
<span style="color: #006E28;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/04-08-2009/resizable-photo-frames-in-qt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NeHe OpenGL lessons in Qt &#8211; Chapter 1 and 2</title>
		<link>http://wesley.vidiqatch.org/03-08-2009/nehe-opengl-lessons-in-qt-chapter-1-and-2/</link>
		<comments>http://wesley.vidiqatch.org/03-08-2009/nehe-opengl-lessons-in-qt-chapter-1-and-2/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 17:16:38 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=365</guid>
		<description><![CDATA[Last week I have ported two chapters (the first 10 lessons) of the NeHe OpenGL lessons to make use of the Qt toolkit. You will notice that the code in Qt is much cleaner and simpler than the code in the original NeHe lessons. There is no need to create a rendering or device context [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I have ported two chapters (the first 10 lessons) of the <a href="http://nehe.gamedev.net/">NeHe OpenGL lessons</a> to make use of the <a href="http://www.qtsoftware.com/">Qt toolkit</a>. You will notice that the code in Qt is much <strong>cleaner</strong> and <strong>simpler</strong> than the code in the original NeHe lessons. There is no need to create a rendering or device context yourself or anything like that, and input support like input from keyboard or mouse can simply be implemented by reimplementing one function. As an added bonus, your 3D applications will run on pretty much any platform.</p>
<p style="text-align: center;"><img title="OpenGL" src="http://www.fabioruini.eu/blog/wp-content/uploads/2008/07/opengl_logo.png" alt="" width="137" height="72" /> <img title="Qt 4" src="http://www.qtsoftware.com/logo.png" alt="" width="174" height="71" /></p>
<h4>First chapter: setting up an OpenGL window, polygons, colors, rotation, 3D shapes</h4>
<p>After completing the <a href="http://nehe.gamedev.net/lesson.asp?index=01">first chapter</a>, you will end up with a rotating pyramid and cube&#8230;<a href="http://www.youtube.com/watch?v=dE3_vgnm7Ck&amp;fmt=18"></a></p>
<p><a href="http://www.youtube.com/watch?v=dE3_vgnm7Ck&amp;fmt=18">This video</a> shows the end result (lesson 5).<br />
You can download the Qt 4 source code for this chapter <a href="http://wesley.vidiqatch.org/files/chapter1.zip"><strong>here</strong></a>.</p>
<h4>Second chapter: texture mapping, texture filters, lighting, keyboard control, blending, moving bitmaps in 3D space, loading and moving through a 3D world</h4>
<p>In the <a href="http://nehe.gamedev.net/lesson.asp?index=02">second chapter</a> you will learn a lot about textures, among some other things. Sometimes we make use of <a href="http://doc.qtsoftware.com/4.5/qglcontext.html#bindTexture">QGLContext::bindTexture()</a> to load an image, morph it into a texture and bind it to OpenGL all in one go. Other times we will do it manually because we want to specify the texture filter ourselves (but we do have <a href="http://doc.qtsoftware.com/4.5/qglwidget.html#convertToGLFormat">QGLWidget::convertToGLFormat()</a> which makes that easy as well). To handle keypresses we simply reimplement <a href="http://doc.qtsoftware.com/4.5/qwidget.html#keyPressEvent">keyPressEvent()</a>. To load in the 3D world from the file we make use of the excellent <a href="http://doc.qtsoftware.com/4.5/qfile.html">QFile</a> and <a href="http://doc.qtsoftware.com/4.5/qtextstream.html">QTextStream</a> classes. As an added <strong>bonus</strong>, we also make use of <a href="http://doc.qtsoftware.com/4.5/qglwidget.html#renderText">QGLWidget::renderText()</a> to show the user what has changed when a key is pressed inside the OpenGL window. Lesson 9 also features a <strong>bonus</strong> fade-in effect for the revived stars. This makes the effect look much cooler.</p>
<p><a href="http://www.youtube.com/watch?v=_apiJu9oF8A&amp;fmt=18">This video</a> shows the result of adding texture filters, lighting and keyboard control (lesson 7)<br />
<a href="http://www.youtube.com/watch?v=uoa8x4Vwxco&amp;fmt=18">This video</a> shows the result of all the above plus blending (lesson 8<em></em>)<br />
<a href="http://www.youtube.com/watch?v=MoFNngz7_qg&amp;fmt=18">This video</a> shows the result of moving bitmaps in 3D space (lesson 9)<br />
<a href="http://www.youtube.com/watch?v=JSybmJKGu1k&amp;fmt=18">This video</a> shows the result of moving through a very simple 3D world (lesson 10)<br />
You can download the Qt 4 source code for this chapter <a href="http://wesley.vidiqatch.org/files/chapter2.zip"><strong>here</strong></a>.</p>
<p>The <strong>third and fourth chapter</strong> are almost complete as well, but I will give you the Qt ports of those chapters another time. Perhaps tomorrow.</p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/03-08-2009/nehe-opengl-lessons-in-qt-chapter-1-and-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>x86 Linux assembler</title>
		<link>http://wesley.vidiqatch.org/02-08-2009/x86-linux-assembler/</link>
		<comments>http://wesley.vidiqatch.org/02-08-2009/x86-linux-assembler/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 20:00:04 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://wesley.vidiqatch.org/?p=355</guid>
		<description><![CDATA[The last few days I&#8217;ve been looking at x86 Linux assembler programming. I think it&#8217;s important to know how the code which you write in higher-level languages gets translated to low-level instructions and in what way things like libc or the kernel are involved. With some knowledge of assembler you can not only directly optimize [...]]]></description>
			<content:encoded><![CDATA[<p>The last few days I&#8217;ve been looking at <strong>x86 Linux assembler </strong>programming. I think it&#8217;s important to know how the code which you write in <em>higher-level</em> languages gets translated to <em>low-level instructions</em> and in what way things like <em>libc</em> or the <em>kernel</em> are involved. With some knowledge of assembler you can not only directly optimize some slower operations by implementing them in low-level assembly and by utilizing specific processor features, but in general you will also learn in which ways you can optimize your software by just writing the high-level code a little bit different &#8211; by anticipating how your code will translate into low-level assembler instructions.</p>
<p>That was my motivation for trying to do a few things with the Netwide Assembler (NASM). The result is a simple demo which utilizes <em>libc</em>, <em>GLUT</em> and <em>OpenGL</em> to display a rotating pyramid and cube.</p>
<div class="wp-caption alignnone" style="width: 535px"><img title="ogl.asm" src="http://wesley.vidiqatch.org/images/ogl.png" alt="ogl.asm" width="525" height="359" /><p class="wp-caption-text">compiled ogl.asm application running in Ubuntu 8.04</p></div>
<p>The resulting code can be viewed here:</p>
<div class="codecolorer-container asm default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br /></div></td><td><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">; OpenGL example in x86 Linux assembler / NASM using Glut</span><br />
<span style="color: #666666; font-style: italic;">; Author: Wesley Stessens (wesley@ubuntu.com)</span><br />
<span style="color: #666666; font-style: italic;">;</span><br />
<span style="color: #666666; font-style: italic;">; OpenGL calls to create pyramid and cube are from Jeff Molofee's OpenGL tutorial</span><br />
<span style="color: #666666; font-style: italic;">; See: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05</span><br />
<span style="color: #666666; font-style: italic;">;</span><br />
<span style="color: #666666; font-style: italic;">; Features:</span><br />
<span style="color: #666666; font-style: italic;">; &nbsp;- Calling C functions by cdecl conventions</span><br />
<span style="color: #666666; font-style: italic;">; &nbsp;- Using GLUT and OpenGL calls to perform 3D graphics</span><br />
<span style="color: #666666; font-style: italic;">; &nbsp;- Low-level framerate control</span><br />
<span style="color: #666666; font-style: italic;">;</span><br />
<span style="color: #666666; font-style: italic;">; Sample compile instructions:</span><br />
<span style="color: #666666; font-style: italic;">; nasm -felf ogl.asm &amp;&amp; ld -lglut -s -I/lib/ld-linux.so.2 -o ogl ogl.o</span><br />
<span style="color: #666666; font-style: italic;">;</span><br />
<span style="color: #666666; font-style: italic;">; This code is released as sample code in the public domain. Use it for whatever you want.</span><br />
<span style="color: #666666; font-style: italic;">; Feel free to let me know if you found this code useful in any way.</span><br />
<br />
<span style="color: #666666; font-style: italic;">; Glut</span><br />
<span style="color: #000000; font-weight: bold;">extern</span> glutInit<span style="color: #339933;">,</span> glutInitDisplayMode<span style="color: #339933;">,</span> glutInitWindowSize<span style="color: #339933;">,</span> glutInitWindowPosition<br />
<span style="color: #000000; font-weight: bold;">extern</span> glutCreateWindow<span style="color: #339933;">,</span> glutMainLoop<br />
<span style="color: #000000; font-weight: bold;">extern</span> glutDisplayFunc<span style="color: #339933;">,</span> glutIdleFunc<span style="color: #339933;">,</span> glutReshapeFunc<span style="color: #339933;">,</span> glutKeyboardFunc<br />
<span style="color: #000000; font-weight: bold;">extern</span> glutSwapBuffers<br />
<br />
<span style="color: #666666; font-style: italic;">; Glu</span><br />
<span style="color: #000000; font-weight: bold;">extern</span> gluPerspective<br />
<br />
<span style="color: #666666; font-style: italic;">; OpenGL</span><br />
<span style="color: #000000; font-weight: bold;">extern</span> glClearColor<span style="color: #339933;">,</span> glClearDepth<span style="color: #339933;">,</span> glDepthFunc<span style="color: #339933;">,</span> glEnable<span style="color: #339933;">,</span> glShadeModel<br />
<span style="color: #000000; font-weight: bold;">extern</span> glClear<span style="color: #339933;">,</span> glLoadIdentity<span style="color: #339933;">,</span> glMatrixMode<span style="color: #339933;">,</span> glViewport<br />
<span style="color: #000000; font-weight: bold;">extern</span> glTranslatef<span style="color: #339933;">,</span> glRotatef<span style="color: #339933;">,</span> glBegin<span style="color: #339933;">,</span> glEnd<span style="color: #339933;">,</span> glVertex3f<span style="color: #339933;">,</span> glColor3f<br />
<br />
<span style="color: #666666; font-style: italic;">; Needed for framerate control</span><br />
<span style="color: #000000; font-weight: bold;">extern</span> usleep<br />
<br />
<span style="color: #666666; font-style: italic;">; Macros</span><br />
<span style="color: #339933;">%</span><span style="color: #000000; font-weight: bold;">macro</span> _3call 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>3<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>2<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #339933;">%</span>1<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 12<br />
<span style="color: #339933;">%</span>endmacro<br />
<span style="color: #339933;">%</span><span style="color: #000000; font-weight: bold;">macro</span> _4call 5<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>5<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>3<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #339933;">%</span>2<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #339933;">%</span>1<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 16<br />
<span style="color: #339933;">%</span>endmacro<br />
<br />
section <span style="color: #000000; font-weight: bold;">.data</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">title</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">db</span> <span style="color: #7f007f;">'OpenGL in x86 Linux assembler / NASM using Glut'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Data for FP math with 4 bytes</span><br />
&nbsp; &nbsp; n7<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #339933;">-</span>7<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; n6<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #339933;">-</span>6<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; n1p5<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #339933;">-</span>1<span style="color: #339933;">.</span>5<br />
&nbsp; &nbsp; n1<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #339933;">-</span>1<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; p0p4<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> 0<span style="color: #339933;">.</span>4<br />
&nbsp; &nbsp; p0p5<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> 0<span style="color: #339933;">.</span>5<br />
&nbsp; &nbsp; p1<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> 1<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; p1p5<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> 1<span style="color: #339933;">.</span>5<br />
&nbsp; &nbsp; p3<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> 3<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; rottrm<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> 4<span style="color: #339933;">.</span>5<br />
&nbsp; &nbsp; rotsqm<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #339933;">-</span><span style="color: #0000ff;">3.0</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Data for FP math with 8 bytes</span><br />
&nbsp; &nbsp; q0p1<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dq</span> 0<span style="color: #339933;">.</span>1<br />
&nbsp; &nbsp; q1<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dq</span> 1<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; q45<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dq</span> 45<span style="color: #339933;">.</span>0<br />
&nbsp; &nbsp; q100<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dq</span> <span style="color: #0000ff;">100.0</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Data for framerate control</span><br />
&nbsp; &nbsp; mspf<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #0000ff;">20000</span> <span style="color: #666666; font-style: italic;">; ms per frame</span><br />
<br />
section <span style="color: #339933;">.</span>bss<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Vars for rotation</span><br />
&nbsp; &nbsp; rottr<span style="color: #339933;">:</span> resd <span style="color: #0000ff;">1</span><br />
&nbsp; &nbsp; rotsq<span style="color: #339933;">:</span> resd <span style="color: #0000ff;">1</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Var for aspect ratio</span><br />
&nbsp; &nbsp; aspr<span style="color: #339933;">:</span> resq <span style="color: #0000ff;">1</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Vars for framerate control</span><br />
&nbsp; &nbsp; time<span style="color: #339933;">:</span> resd 2<br />
&nbsp; &nbsp; usecs<span style="color: #339933;">:</span> resd 1<br />
&nbsp; &nbsp; oldslp<span style="color: #339933;">:</span> resd 1<br />
<br />
section <span style="color: #339933;">.</span>text<br />
&nbsp; &nbsp; global _start<br />
<br />
fpsmanager<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ebx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ecx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">edx</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">78</span> <span style="color: #666666; font-style: italic;">; sys_gettimeofday</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span> time<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">int</span> 80h<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>time <span style="color: #339933;">+</span> 4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">sub</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>usecs<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>mspf<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">sub</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">test</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">js</span> keep_sleep<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">test</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span> <span style="color: #00007f;">ebx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">js</span> keep_sleep<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ebx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> usleep<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>oldslp<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">ebx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">jmp</span> done_sleep<br />
<br />
keep_sleep<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>oldslp<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> usleep<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
<br />
done_sleep<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>time <span style="color: #339933;">+</span> 4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>usecs<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">edx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ecx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ebx</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">ret</span><br />
<br />
display<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Prepare for drawing</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">4100h</span> <span style="color: #666666; font-style: italic;">; GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glClear<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glLoadIdentity<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Draw pyramid on the left of the screen</span><br />
&nbsp; &nbsp; _3call glTranslatef<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1p5<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n6<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _4call glRotatef<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rottr<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">9h</span> <span style="color: #666666; font-style: italic;">; GL_POLYGON</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glBegin<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">4</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing front face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing right face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing back face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing right face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glEnd<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Draw cube on the right of the screen</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glLoadIdentity<br />
&nbsp; &nbsp; _3call glTranslatef<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1p5<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n7<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _4call glRotatef<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rotsq<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p0p4<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p0p5<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">7h</span> <span style="color: #666666; font-style: italic;">; GL_QUADS</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glBegin<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">4</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing top face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p0p5<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing bottom face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing front face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; Start drawing back face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span> <span style="color: #666666; font-style: italic;">; Start drawing left face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glColor3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span> <span style="color: #666666; font-style: italic;">; Start drawing right face</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; _3call glVertex3f<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>p1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>n1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glEnd<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Update rotation</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fld</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rottr<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fadd</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rottrm<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fstp</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rottr<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fld</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rotsq<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fadd</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rotsqm<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fstp</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rotsq<span style="color: #009900; font-weight: bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutSwapBuffers <span style="color: #666666; font-style: italic;">; Swap buffers and display</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> fpsmanager <span style="color: #666666; font-style: italic;">; Cap framerate if necessary</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">ret</span><br />
<br />
reshape<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ebp</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebp</span><span style="color: #339933;">,</span> <span style="color: #00007f;">esp</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Prevent division by zero</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">cmp</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>8<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">jne</span> reshape_2<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">inc</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>8<span style="color: #009900; font-weight: bold;">&#93;</span><br />
<br />
reshape_2<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fild</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>8<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fidiv</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>12<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff; font-weight: bold;">fstp</span> <span style="color: #000000; font-weight: bold;">qword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>aspr<span style="color: #009900; font-weight: bold;">&#93;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>12<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span>8<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glViewport<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 16<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">1701h</span><span style="color: #666666; font-style: italic;">; GL_PROJECTION</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glMatrixMode<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glLoadIdentity<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q100<span style="color: #339933;">+</span>4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q100<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q0p1<span style="color: #339933;">+</span>4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q0p1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>aspr<span style="color: #339933;">+</span>4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>aspr<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q45<span style="color: #339933;">+</span>4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q45<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> gluPerspective<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 32<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">1700h</span><span style="color: #666666; font-style: italic;">; GL_MODELVIEW</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glMatrixMode<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ebp</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">ret</span><br />
<br />
keyhandler<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">ret</span><br />
<br />
_start<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Initialize glut</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span>8<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span>8<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutInit<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 8<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">1ah</span> <span style="color: #666666; font-style: italic;">; GLUT_RGBA|GLUT_DOUBLE|GLUT_ALPHA|GLUT_DEPTH</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutInitDisplayMode<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 480<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 640<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutInitWindowSize<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 8<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutInitWindowPosition<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">8</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Create window</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">title</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutCreateWindow<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">4</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Register functions</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> display<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutDisplayFunc<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutIdleFunc<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> reshape<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutReshapeFunc<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> keyhandler<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutKeyboardFunc<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">4</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Initialize OpenGL</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glClearColor<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 16<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q1<span style="color: #339933;">+</span>4<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>q1<span style="color: #009900; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glClearDepth<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 8<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">203h</span><span style="color: #666666; font-style: italic;">; GL_LEQUAL</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glDepthFunc<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">0b71h</span><span style="color: #666666; font-style: italic;">; GL_DEPTH_TEST</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glEnable<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> 4<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">1d01h</span><span style="color: #666666; font-style: italic;">; GL_SMOOTH</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glShadeModel<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">4</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Frame rate cap initialization</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span>oldslp<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Enter main loop</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">call</span> glutMainLoop<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">; Exit (return with error code 0)</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">1</span> <span style="color: #666666; font-style: italic;">; sys_exit</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span> 0<br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">int</span> <span style="color: #0000ff;">80h</span></div></td></tr></tbody></table></div>
<p>I have also written two other smaller examples:<br />
- <a href="/code-snippets/ideal-statistical-sample-formula/">marketing.asm</a> is a really simple statistics application which calculates the ideal sample size given a few parameters<br />
- <a href="/code-snippets/simple-audio-playback-using-alsa/">alsawav.asm</a> is a simple audio library which utilizes ALSA to play an unbuffered raw WAV/PCM sample</p>
<p>Please note that all these examples require an x86 Linux distribution. These examples will not work on any other operating system.</p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/02-08-2009/x86-linux-assembler/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Open source DJ mixxx&#8217;ing</title>
		<link>http://wesley.vidiqatch.org/06-01-2008/open-source-dj-mixxxing/</link>
		<comments>http://wesley.vidiqatch.org/06-01-2008/open-source-dj-mixxxing/#comments</comments>
		<pubDate>Sun, 06 Jan 2008 15:33:16 +0000</pubDate>
		<dc:creator>Wesley</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mixxx]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://wesley.debianbox.be/2008/01/06/open-source-dj-mixxxing/</guid>
		<description><![CDATA[Sinds vorige week ben ik begonnen met mee te helpen aan de ontwikkeling van het open source DJ programma mixxx. Mixxx is een stabiel programma waarmee men live muziek kan mixen. Het heeft een aantal zeer interessante features, zoals bijvoorbeeld automatische ritmedetectie en ondersteuning voor een heleboel hardware.

Waar staan we vandaag? 1.6.0
Ik werk mee aan [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #000000;"><strong>Sinds vorige week ben ik begonnen met mee te helpen aan de ontwikkeling van het open source DJ programma mixxx. Mixxx is een stabiel programma waarmee men live muziek kan mixen. Het heeft een aantal zeer interessante features, zoals bijvoorbeeld automatische ritmedetectie en ondersteuning voor een heleboel hardware.</strong></span></p>
<p style="text-align: center;"><a href="http://wesley.vidiqatch.org/images/mixxx.png"><span style="color: #000080;"><img style="border: 0pt none;" src="http://wesley.vidiqatch.org/images/mixxx_thumb.png" border="1" alt="Mixxx 1.6.0 with Collusion/WS/Green skin" align="bottom" /></span></a></p>
<p style="margin-bottom: 0cm"><span style="color: #0066cc;"><span style="font-size: medium;"><strong>Waar staan we vandaag? 1.6.0</strong></span></span></p>
<p>Ik werk mee aan de nieuwe versie waarvan twee weken geleden een eerste bètaversie werd gelanceerd. Voor de nieuwe 1.6.0 versie zijn een heleboel nieuwe features gepland. Ik som even de belangrijkste veranderingen op:</p>
<ul>
<li>Scratchen via <strong>timecoded 	vinyl</strong>-platen <em>[ <a href="http://www.youtube.com/watch?v=U2ZPSSXlK60">link 	naar flash video 1</a>, <a href="http://www.youtube.com/watch?v=9dRLNT2yspg">video 2</a> ]</em></li>
<li><strong>Kleurenschema&#8217;s</strong> voor skins</li>
<li>Nieuwe <strong>muziekbibliotheek</strong> (muziekbrowser)</li>
<li>Verbeterde <strong>ritmedetectie</strong></li>
<li>Verbeterde ondersteuning voor <strong>MIDI-controllers</strong> (hardware)</li>
<li><strong>HQ-equalizer</strong> toegevoegd</li>
<li>Audio core herschreven/vernieuwd</li>
<li>Ondersteuning voor <strong>LADSPA geluidseffecten</strong></li>
<li><strong>Live broadcasten</strong> over internet (Icecast, Shoutcast)</li>
<li><strong>Rechtstreeks opnemen</strong> naar MP3, Ogg Vorbis, Wav, Flac</li>
</ul>
<p>Ik werk momenteel aan de laatste twee punten. Het is niet zeker of het helemaal af zal raken voor de <em>Hardy freeze</em> in februari (het moment waarop programma&#8217;s naar <em>Ubuntu 8.04 Hardy Heron</em> geupload worden en niet meer aangepast mogen worden) maar Ogg Vorbis Icecast/Shoutcast-ondersteuning is zo goed als af, dus dat zal er waarschijnlijk zeker inzitten.</p>
<p>Zelf kijk ik uit naar de ondersteuning voor LADSPA geluidseffecten, maar ik vermoed dat dat niet af zal raken voor de 1.6.0-versie. Dan maar wat langer wachten&#8230;</p>
<p style="margin-bottom: 0cm"><span style="font-size: medium;"><span style="color: #0066cc;"><strong>Evolutie van de broadcasting code</strong></span></span></p>
<p style="margin-bottom: 0cm; text-align: center;"><a href="http://wesley.vidiqatch.org/images/mixxx_broadcast_prefs.png"><img title="Mixxx Live Broadcasting Preferences" src="http://wesley.vidiqatch.org/images/mixxx_broadcast_prefs_thumb.png" alt="Mixxx Live Broadcasting Preferences" /></a></p>
<p>Zoals eerder gezegd ben ik momenteel bezig met het implementeren van Icecast/Shoutcast ondersteuning zodat we een mix rechtstreeks over internet kunnen broadcasten. Aanvankelijk dachten we dat het simpel zou zijn om dit systeem te implementeren (gewoon <em>libshout</em> gebruiken) maar al snel bleek dat we eerst nog een encoder moesten schrijven. Ik ben de laatste dagen dus vooral bezig geweest met het schrijven van een Ogg Vorbis-encoder met behulp van <em>libvorbis</em>, <em>libogg</em> en <em>libvorbisenc</em>.</p>
<p>Afgezien van het feit dat er voor libvorbis <strong>geen technische API-documentatie</strong> beschikbaar is, is het ons uiteindelijk toch gelukt om de encoder werkend te krijgen. Alles ging goed, maar de audio latency was nu wel verhoogd omdat de &#8216;audio callback thread&#8217; voor een korte periode geblokkeerd werd wanneer de encoder zijn werk deed. Toen we ook nog beseften dat we om metadata te updaten een nieuwe stream moesten initialiseren was het onvermijdelijk om een nieuw systeem te ontwerpen om de encoder parallel in een aparte thread te laten draaien <em>(</em><em><strong>multithreaded</strong></em><em>)</em> met een eigen buffer.</p>
<p>Albert ging hiermee aan de slag en na twee of drie dagen knoeien presenteerde hij een nieuwe &#8216;engine&#8217; <em>(de SideChain-engine)</em> aan ons die de audio buffert voor andere engines (zoals de broadcast engine) en deze engines in een aparte thread draait. <strong>Het resultaat is lage audio latency en geen enkel performanceprobleem meer.</strong> Ook werd het totale CPU-verbruik verlaagd omdat de encoder nu iets minder vaak aangeroepen wordt.</p>
<p>Om het schematisch voor te stellen:</p>
<p><strong>voor: </strong><em><strong>[</strong></em><em> afbeelding:</em><em><strong> <a href="http://wesley.vidiqatch.org/images/mixxx_broadcast_scheme.png">Oorspronkelijke Broadcast Implementatie</a> ]</strong></em><strong><br />
na: </strong><em><strong>[ </strong></em><em>afbeelding:</em><em><strong> <a href="http://wesley.vidiqatch.org/images/mixxx_broadcast_scheme_threaded.png">Threaded Broadcast Implementatie</a> ]</strong></em></p>
<p><strong>Wat moet er nog gedaan worden?</strong> De <em>SideChain-engine</em> moet nog een klein beetje aangepast worden, er moet nog een <em>MP3-encoder</em> worden geschreven, het instellingenvenster moet afgemaakt worden, en tenslotte moet de code wat opgeschoond worden, en moet alles grondig getest worden!</p>
]]></content:encoded>
			<wfw:commentRss>http://wesley.vidiqatch.org/06-01-2008/open-source-dj-mixxxing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
