<?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>GaanZa &#187; Tutorials</title>
	<atom:link href="http://www.gaanza.com/blog/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gaanza.com</link>
	<description></description>
	<lastBuildDate>Sat, 04 Sep 2010 07:55:44 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing Nvidia Driver on Ubuntu 10.04</title>
		<link>http://www.gaanza.com/blog/installing-nvidia-driver-on-ubuntu-10-04/</link>
		<comments>http://www.gaanza.com/blog/installing-nvidia-driver-on-ubuntu-10-04/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 09:03:41 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Installing Nvidia Driver on Ubuntu 10.04]]></category>
		<category><![CDATA[Nvidia drivers]]></category>
		<category><![CDATA[removing nouveau]]></category>
		<category><![CDATA[stopping X SERVER]]></category>
		<category><![CDATA[Ubuntu 10.04]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=505</guid>
		<description><![CDATA[

I just upgraded to Ubuntu 10.04 Lucid Lynx. I liked 10.04 more than previous versions. Anyway here i&#8217;l guide how to install drivers manually for your nvidia card on Ubuntu 10.04. I have intel machine with Nvidia 9500 GT card.
While installing Nvidia Driver for my card i faced two primary problems:
1) I need To Stop/Kill [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Finstalling-nvidia-driver-on-ubuntu-10-04%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><a href="http://www.gaanza.com/wp-content/uploads/2010/08/Ubuntu-logo.jpg"><img class="aligncenter size-full wp-image-530" title="Ubuntu-logo" src="http://www.gaanza.com/wp-content/uploads/2010/08/Ubuntu-logo.jpg" alt="" width="366" height="341" /></a></p>
<p>I just upgraded to Ubuntu 10.04 Lucid Lynx. I liked 10.04 more than previous versions. Anyway here i&#8217;l guide how to install drivers manually for your nvidia card on Ubuntu 10.04. I have intel machine with Nvidia 9500 GT card.</p>
<p>While installing Nvidia Driver for my card i faced two primary problems:<br />
<strong>1)</strong> I need To Stop/Kill X SERVER. (I didn&#8217;t know howto at the time)<br />
<strong>2)</strong> I need to uninstall <strong>Nouveau </strong>because it stopped my installation (I didn&#8217;t know howto at   the time lol)<br />
( <strong>Noveau</strong> is a new open-source driver with 3D acceleration for NVIDIA cards that ships with Ubuntu 10.04. )</p>
<p>So <strong>First Step</strong> of Installation: Download the Nvidia Driver for your card from Nvidia <a href="http://www.nvidia.com/Download/index.aspx?lang=en-us" target="_blank">official site</a>.</p>
<p>i had downloaded the driver into /home/padam/Downloads (here padam is my username on ubuntu).</p>
<p><strong>Second</strong>, when i ran nvidia driver setup sh file after just killing X SERVER, then during the installation an error came saying Nouveau must be removed. So my installation was cancelled. I had to remove nouveau from my system. Here is the command to remove nouveau :<br />
<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;"><strong>sudo apt-get &#8211;purge remove xserver-xorg-video-nouveau</strong></span></p>
<p><strong>Third</strong>, Now to install driver i had to stop/kill the X SERVER. so to kill it i opened the terminal, typed this command: sudo <strong>/etc/init.d/gdm</strong> <strong>stop</strong><br />
That did it. after executing that command on terminal window, i killed X and gets a command prompt/terminal type full screen <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .<br />
Okie i also want to tell that i re-installed the driver, just to write down the steps for tutorial hehe <img src='http://www.gaanza.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . So during re-installation when i tried to killed X server by executing above command, i got the orange color screen with UBUNTU written at the center and few dots below that, and i waited for few minutes, nothing happened. So i just did this: CTRL + ALT + F1 yeah i pressed those keys and viola i got command prompt/terminal type full screen. so if u face this problem then u know how to deal with it.<br />
But this command  sudo <strong>/etc/init.d/gdm</strong> <strong>stop</strong> is necessary/must/compulsory to kill X SERVER.</p>
<p>So here are the above steps that must be done to install nvidia drivers: remove nouveau first from system, then Kill the X SERVER.</p>
<p>After killing X SERVER, you get a command prompt/terminal type Full screen. So use a cd command and navigate to the location where nvidia driver setup file is present. In my case my location was /home/padam/Downloads</p>
<p>so i typed /home/padam/Downloads and pressed Enter.</p>
<p>Name of my nvidia driver setup  file was NVIDIA-Linux-x86-256.44.run. Now i ran a driver setup file using this command:<br />
<strong>sudo sh NVIDIA-LINUX-x86-256.44.run -k $(uname -r)</strong></p>
<p>And after that setup runs, then follow the instructions and your driver will be installed.</p>
<p><strong>Note:</strong> <em>i also ran the file using just this command: sudo sh NVIDIA-LINUX-x86-256.44.run This works and driver was installed but there was a default. When i applyed screen resolution of my screen to 1024 * 768 then it didn&#8217;t worked properly, there was wide black space at the left of my screen.</em></p>
<p>When installation get complete, you are returned to same command prompt/terminal type screen. Now execute this command to start X SERVER back:<br />
<strong>sudo /etc/init.d/gdm start</strong><br />
This will start the X SERVER and you gets the old UBUNTU LOGIN SCREEN. You better restart the computer then, it would be better. So after restart, You are done. You can check the Nvidia settings by going at <strong>System -&gt; Preferences -&gt; NVIDIA X Server Settings.</strong></p>
<p>So this is it. This is how i installed my nvidia driver for my Nvidia 9500 GT. I hope this also works for you.</p>
<p><strong>Gracias.</strong></p>
<p><a name="fb_share"></a><br />
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/installing-nvidia-driver-on-ubuntu-10-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2D Rain Effect</title>
		<link>http://www.gaanza.com/blog/2d-rain-effect/</link>
		<comments>http://www.gaanza.com/blog/2d-rain-effect/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 05:40:10 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Slick 2D]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[2d rain effect]]></category>
		<category><![CDATA[lwjgl]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=382</guid>
		<description><![CDATA[
Hola Everyone.
I am working on a level for 2d game where i needed to add a rain effects. I am using Slick 2D library for making my 2d game. Before i started working on making  2D rain effect , i discussed this topic on slick 2d forum for how to get started ? Here [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2F2d-rain-effect%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><strong>Hola Everyone.</strong><br />
I am working on a level for 2d game where i needed to add a rain effects. I am using Slick 2D library for making my 2d game. Before i started working on making  2D rain effect , i discussed this topic on slick 2d forum for how to get started ? Here is the <a href="http://slick.javaunlimited.net/viewtopic.php?p=13771#13771" target="_blank">forum thread</a>. You can check it out.<br />
So i wrote a simple code to create a rain effect:<br />
1)	Make a Rain Drop, i wrote a class for Rain Drop that extends Polygon class. Yes i m creating rain drops with polygons.<br />
2)	Create number of drops at random coordinates  and simulate it across the screen i.e make them fall. You can use wind factor also for providing bit more interesting.</p>
<p><a href="http://www.gaanza.com/wp-content/uploads/2010/03/rain1.png"><img class="alignnone size-full wp-image-388" title="rain" src="http://www.gaanza.com/wp-content/uploads/2010/03/rain1.png" alt="" width="599" height="768" /></a><br />
So this is the way i started.</p>
<p>Here is the Rain Drop class:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co2">import org.newdawn.slick.geom.Polygon;</span></p>
<p><span class="kw2">public</span> <span class="kw2">class</span> RainDrop <span class="kw2">extends</span> <a href="http://www.google.com/search?q=allinurl%3APolygon+java.sun.com&#038;bntl=1"><span class="kw3">Polygon</span></a><span class="br0">&#123;</span><br />
<span class="kw2">public</span> RainDrop<span class="br0">&#40;</span><span class="kw4">int</span> size<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
super<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/** coordinates of vertices of polygon(rain drop) */</span><br />
<span class="kw2">this</span>.<span class="me1">addPoint</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
<span class="kw2">this</span>.<span class="me1">addPoint</span><span class="br0">&#40;</span><span class="nu0">0</span>, size<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>This is the main class where we are using rain drops and simulating it to create a simple rain effect, nothing fancy.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co2">import java.util.logging.Level;</span><br />
<span class="co2">import java.util.logging.Logger;</span><br />
<span class="co2">import org.newdawn.slick.AppGameContainer;</span><br />
<span class="co2">import org.newdawn.slick.BasicGame;</span><br />
<span class="co2">import org.newdawn.slick.Color;</span><br />
<span class="co2">import org.newdawn.slick.GameContainer;</span><br />
<span class="co2">import org.newdawn.slick.Graphics;</span><br />
<span class="co2">import org.newdawn.slick.Image;</span><br />
<span class="co2">import org.newdawn.slick.SlickException;</span></p>
<p><span class="kw2">public</span> <span class="kw2">class</span> Rainy <span class="kw2">extends</span> BasicGame<span class="br0">&#123;</span></p>
<p><span class="kw2">private</span> RainDrop<span class="br0">&#91;</span><span class="br0">&#93;</span> drops;<br />
<span class="kw2">private</span> <a href="http://www.google.com/search?q=allinurl%3AImage+java.sun.com&#038;bntl=1"><span class="kw3">Image</span></a> background;</p>
<p><span class="kw2">public</span> Rainy<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp;super<span class="br0">&#40;</span><span class="st0">&#8220;&#8221;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">public</span> <span class="kw4">static</span> <span class="kw4">void</span> main<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
<span class="kw2">try</span> <span class="br0">&#123;</span><br />
AppGameContainer app = <span class="kw2">new</span> AppGameContainer<span class="br0">&#40;</span><span class="kw2">new</span> Rainy<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
app.<span class="me1">setDisplayMode</span><span class="br0">&#40;</span><span class="nu0">1024</span>, <span class="nu0">768</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;<br />
app.<span class="me1">setTargetFrameRate</span><span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;<br />
app.<span class="me1">setShowFPS</span><span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span>;<br />
app.<span class="me1">start</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span> <span class="kw2">catch</span> <span class="br0">&#40;</span>SlickException ex<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
Logger.<span class="me1">getLogger</span><span class="br0">&#40;</span>Rainy.<span class="kw2">class</span>.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">log</span><span class="br0">&#40;</span>Level.<span class="me1">SEVERE</span>, <span class="kw2">null</span>, ex<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p>@Override<br />
<span class="kw2">public</span> <span class="kw4">void</span> init<span class="br0">&#40;</span>GameContainer gc<span class="br0">&#41;</span> <span class="kw2">throws</span> SlickException <span class="br0">&#123;</span><br />
background=<span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AImage+java.sun.com&#038;bntl=1"><span class="kw3">Image</span></a><span class="br0">&#40;</span><span class="st0">&#8220;data/jungle.jpg&#8221;</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/** creating 700 rain drops and placing it on random location across the screen */</span><br />
initializeRain<span class="br0">&#40;</span><span class="nu0">900</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p>@Override<br />
<span class="kw2">public</span> <span class="kw4">void</span> update<span class="br0">&#40;</span>GameContainer gc, <span class="kw4">int</span> delta<span class="br0">&#41;</span> <span class="kw2">throws</span> SlickException <span class="br0">&#123;</span></p>
<p><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;drops.<span class="me1">length</span>-<span class="nu0">1</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">setY</span><span class="br0">&#40;</span>drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getY</span><span class="br0">&#40;</span><span class="br0">&#41;</span>+<span class="nu0">4</span>.0f<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">setX</span><span class="br0">&#40;</span>drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getX</span><span class="br0">&#40;</span><span class="br0">&#41;</span>-<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getY</span><span class="br0">&#40;</span><span class="br0">&#41;</span>&gt;<span class="nu0">768</span><span class="br0">&#41;</span><span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">setX</span><span class="br0">&#40;</span><span class="br0">&#40;</span>float<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&#038;bntl=1"><span class="kw3">Math</span></a>.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">2000</span><span class="br0">&#41;</span>+<span class="nu0">30</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">setY</span><span class="br0">&#40;</span><span class="br0">&#40;</span>float<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&#038;bntl=1"><span class="kw3">Math</span></a>.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">5</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p><span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></p>
<p><span class="kw2">public</span> <span class="kw4">void</span> render<span class="br0">&#40;</span>GameContainer gc, <a href="http://www.google.com/search?q=allinurl%3AGraphics+java.sun.com&#038;bntl=1"><span class="kw3">Graphics</span></a> g<span class="br0">&#41;</span> <span class="kw2">throws</span> SlickException <span class="br0">&#123;</span><br />
g.<span class="me1">drawImage</span><span class="br0">&#40;</span>background, <span class="nu0">0</span>, <span class="nu0">0</span><span class="br0">&#41;</span>;<br />
g.<span class="me1">setColor</span><span class="br0">&#40;</span><span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AColor+java.sun.com&#038;bntl=1"><span class="kw3">Color</span></a><span class="br0">&#40;</span><span class="nu0">188</span>.0f,<span class="nu0">227</span>.0f,<span class="nu0">229</span>.0f,<span class="nu0">0</span>.3f<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;drops.<span class="me1">length</span>-<span class="nu0">1</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;g.<span class="me1">draw</span><span class="br0">&#40;</span>drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="coMULTI">/** creating rain drops */</span><br />
<span class="kw4">void</span> initializeRain<span class="br0">&#40;</span><span class="kw4">int</span> num_of_drops<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
drops=<span class="kw2">new</span> RainDrop<span class="br0">&#91;</span>num_of_drops<span class="br0">&#93;</span>;<br />
<span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;drops.<span class="me1">length</span>-<span class="nu0">1</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>=<span class="kw2">new</span> RainDrop<span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&#038;bntl=1"><span class="kw3">Math</span></a>.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">10</span> + <span class="nu0">4</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">setX</span><span class="br0">&#40;</span><span class="br0">&#40;</span>float<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&#038;bntl=1"><span class="kw3">Math</span></a>.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">2000</span><span class="br0">&#41;</span>+<span class="nu0">30</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; drops<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">setY</span><span class="br0">&#40;</span><span class="br0">&#40;</span>float<span class="br0">&#41;</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AMath+java.sun.com&#038;bntl=1"><span class="kw3">Math</span></a>.<span class="me1">random</span><span class="br0">&#40;</span><span class="br0">&#41;</span> * <span class="nu0">750</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p>So what i am doing  :<br />
1)	initializeRain(int num_of_drops) takes an int parameter which denotes the number of rain drops. This function creates a number of rain drops(instance of raindrop class) and assigns the random x and y position to each rain drops.<br />
2)	Then we simply iterate the array of rain drops and translate them across the screen. When drops reaches the bottom of screen then we simply restore back to random initial starting postion. This keeps going on and gives the impression of rainy effect.</p>
<p>This is very simple 2d effect that i started with. You can write your own optimized version and can add more feature to give fancy impression like adding alpha values  for each rain drop etc.</p>
<p><strong>Gracias.</strong></p>
<p><a name="fb_share" type="box_count share_url="http://www.gaanza.com/blog/2d-rain-effect/"></a><br />
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
        type="text/javascript">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/2d-rain-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Nearest Sprite For 2D Collision</title>
		<link>http://www.gaanza.com/blog/finding-nearest-sprite-for-2d-collision/</link>
		<comments>http://www.gaanza.com/blog/finding-nearest-sprite-for-2d-collision/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:04:08 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Slick 2D]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[2d collision]]></category>
		<category><![CDATA[collision detection]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/?p=368</guid>
		<description><![CDATA[
Hola EveryOne.
There are various methods/ways to detect a collision between two objects. Each having its own advantage and disadvantage and based on our requirement we implement one of the collsion detection algorithm.
Here i am not going to talk about collision algorithm. I am going to talk about determining the nearest object with which collision will [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Ffinding-nearest-sprite-for-2d-collision%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><strong>Hola EveryOne.</strong></p>
<p>There are various methods/ways to detect a collision between two objects. Each having its own advantage and disadvantage and based on our requirement we implement one of the collsion detection algorithm.</p>
<p>Here i am not going to talk about collision algorithm. I am going to talk about determining the nearest object with which collision will take place. Suppose there are many objects across the screen and u have to detect the collision between your game character and those objects. And you run the algorithm to detect collision with each of every object in every frame. So it decreases the efficiency of your program. Its better to detremine the nearest object to your game character and detect collision with that determined nearest object.</p>
<p>Here i m using bounding rectangle concept for collision detection.<br />
<a href="http://www.gaanza.com/wp-content/uploads/2010/02/near2.png"><img src="http://www.gaanza.com/wp-content/uploads/2010/02/near2.png" alt="" title="concept diagram" width="567" height="523" class="alignnone size-full wp-image-373" /></a></p>
<p>Code Example:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw2">public</span> <span class="kw4">static</span> Sprite getNearestGroundSprite<span class="br0">&#40;</span>ArrayList&lt;Sprite&gt; sprites,Sprite hero<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; Sprite sprite=<span class="kw2">null</span>;<br />
&nbsp; &nbsp; float minDistance=<span class="nu0">9999</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>hero!=<span class="kw2">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;sprites.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;i++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
<span class="coMULTI">/* ignore all those objects which are not visible across the screen */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getSX</span><span class="br0">&#40;</span><span class="br0">&#41;</span>&gt;screenWidth || <span class="br0">&#40;</span>sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getSX</span><span class="br0">&#40;</span><span class="br0">&#41;</span>+sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span>&lt;<span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
<span class="coMULTI">/* ignore all those objects which are located above the game character */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>hero.<span class="me1">getSY</span><span class="br0">&#40;</span><span class="br0">&#41;</span>&gt;sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getSY</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
<span class="coMULTI">/* ignore all those objects that are located at the left side of game character */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>hero.<span class="me1">getSX</span><span class="br0">&#40;</span><span class="br0">&#41;</span>&gt;<span class="br0">&#40;</span>sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getSX</span><span class="br0">&#40;</span><span class="br0">&#41;</span>+sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
<span class="coMULTI">/* ignore all those objects that are located at right side of game character */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span>hero.<span class="me1">getSX</span><span class="br0">&#40;</span><span class="br0">&#41;</span>+hero.<span class="me1">getWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>&lt;sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getSX</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>&nbsp; <br />
<span class="coMULTI">/* calculate the distance between remaining objects and game character */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; float dist=sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">getSY</span><span class="br0">&#40;</span><span class="br0">&#41;</span>-hero.<span class="me1">getSY</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="coMULTI">/* determine the nearest sprite from remaining sprites */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>dist&lt;minDistance<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minDistance=dist;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprite=sprites.<span class="me1">get</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="coMULTI">/* nearest object found or return null if not found */</span><br />
&nbsp; &nbsp; <span class="kw2">return</span> sprite;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Sprite is just a class representing characters of game. getSX() and getSY() returns the x and y coordinate location of that sprite. getWidth() simply returns the width of the sprite image.</p>
<p>In above code i am ignoring all those sprites that are located at left, right and top of my game character because i need bottom sprite to check collision with i.e when character falls down. This way the number of sprites decreases for checking collisions. You can write function for finding nearest left and right sprites also. You need to call this function at right place and when needed.</p>
<p>This is very simple and basic way i started and it gets the job done. You can write your own optimized code. This is how i started. I have written my optimized code for finding nearest sprite but right now i won&#8217;t be posting it but i&#8217;l share it soon in near future.</p>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/finding-nearest-sprite-for-2d-collision/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Loading image/Texture Mapping in LWJGL</title>
		<link>http://www.gaanza.com/blog/loading-imagetexture-mapping-in-lwjgl/</link>
		<comments>http://www.gaanza.com/blog/loading-imagetexture-mapping-in-lwjgl/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 15:35:40 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[loading image]]></category>
		<category><![CDATA[loading image/texture mapping in lwjgl]]></category>
		<category><![CDATA[lwjgl]]></category>
		<category><![CDATA[texture mapping]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=318</guid>
		<description><![CDATA[

Hola everyone.
I am currently working on my own two game projects: one project is of mobile phone game and other is 2.5 or side-scrolling 3d game, not much sure. So for second project i am making an small engine that will be used to make 2.5D game or side scrolling 3d game, Just simple and [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Floading-imagetexture-mapping-in-lwjgl%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><img class="alignnone size-full wp-image-323" title="box" src="http://www.gaanza.com/wp-content/uploads/2009/10/box.png" alt="box" width="550" height="400" /></p>
<p>Hola everyone.</p>
<p>I am currently working on my own two game projects: one project is of mobile phone game and other is 2.5 or side-scrolling 3d game, not much sure. So for second project i am making an small engine that will be used to make 2.5D game or side scrolling 3d game, Just simple and fun game. I have chosen LWJGL, which is a java binding for Opengl to make my game. So first thing i need to work on loading images.texture mapping in lwjgl. I found some pretty much useful tutorials and great help from lwjgl forums. But atlast i got something that i was looking for from the <a href="http://lwjgl.org/forum/index.php/topic,3073.0.html" target="_blank">forum</a>.</p>
<p>I came to know about slick-util which is free and open source lib to <strong>load images and play sounds</strong>. Its very easy to pick up and implement it. Its just worked flawlessly and smoothly for me. You can <a href="http://slick.cokeandcode.com/downloads/util/" target="_blank">download the slick-util from here</a>.<strong> PNG, GIF, JPG, TGA are supported and WAV, OGG, XM sounds are supported by slick-util.</strong></p>
<p>So here i&#8217;l show u how easily i loaded images and mapped to a 3D BOX. First u have to setup lwjgl and slick-util with netbeans. Yeah i am using netbeans to write my program. You <a href="http://www.gaanza.com/blog/setting-up-lwjgl-with-netbeans/" target="_blank">can see my post to setup lwjgl with netbeans</a>. Now we will set up slick-util, its a continuation to the steps that we did to setup lwjgl.</p>
<p><strong>Continued&#8230;</strong></p>
<p>Step 1: We just have to configure the project properties so that project can find the lib to compile and run.</p>
<p><img class="alignnone size-full wp-image-319" title="1" src="http://www.gaanza.com/wp-content/uploads/2009/10/1.png" alt="1" width="501" height="206" /></p>
<p><img class="alignnone size-full wp-image-320" title="2" src="http://www.gaanza.com/wp-content/uploads/2009/10/2.png" alt="2" width="462" height="254" /></p>
<p>Ok that was it. Now slick-util lib has been set up.Now first i&#8217;l show u how to load image and bind it , full source will be at the end.</p>
<p><strong>Texture texture;</strong></p>
<p>Texture is an interface having description of texture which will be loaded.</p>
<p><strong>texture = TextureLoader.getTexture(&#8220;PNG&#8221;, new FileInputStream(&#8220;Data/Crate.png&#8221;));</strong></p>
<p>now we are loading the texture using TextureLoader utility class. Just smooth and simple.</p>
<p><strong>texture.bind();</strong></p>
<p>Now we are binding the texture.</p>
<p>So thats what u need to load the image and map them to objects. Download this image to use it in this program.</p>
<p><img class="alignnone size-full wp-image-321" title="Crate" src="http://www.gaanza.com/wp-content/uploads/2009/10/Crate.png" alt="Crate" width="256" height="256" /></p>
<p><strong>Full Code:</strong></p>
<div class="codesnip-container" >
<div class="codesnip"><span class="coMULTI">/*<br />
&nbsp;* To change this template, choose Tools | Templates<br />
&nbsp;* and open the template in the editor.<br />
&nbsp;*/</span></p>
<p>package com.<span class="me1">gaanza</span>.<span class="me1">engine</span>.<span class="me1">test2</span>;</p>
<p><span class="co2">import java.io.FileInputStream;</span><br />
<span class="co2">import java.io.IOException;</span><br />
<span class="co2">import java.util.logging.Level;</span><br />
<span class="co2">import java.util.logging.Logger;</span><br />
<span class="co2">import org.lwjgl.LWJGLException;</span><br />
<span class="co2">import org.lwjgl.Sys;</span><br />
<span class="co2">import org.lwjgl.opengl.Display;</span><br />
<span class="co2">import org.lwjgl.opengl.DisplayMode;</span><br />
<span class="co2">import org.lwjgl.opengl.GL11;</span><br />
<span class="co2">import org.lwjgl.util.glu.GLU;</span><br />
<span class="co2">import org.newdawn.slick.opengl.Texture;</span><br />
<span class="co2">import org.newdawn.slick.opengl.TextureLoader;</span></p>
<p><span class="coMULTI">/**<br />
&nbsp;*<br />
&nbsp;* @author Java Guy<br />
&nbsp;*/</span><br />
<span class="kw2">public</span> <span class="kw2">class</span> EngineTest <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">static</span> <span class="kw4">boolean</span> gameRunning=<span class="kw2">true</span>;<br />
&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">static</span> <span class="kw4">int</span> targetWidth = <span class="nu0">800</span>;<br />
&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">static</span> <span class="kw4">int</span> targetHeight = <span class="nu0">600</span>;</p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> float xrot=<span class="nu0">0</span>.1f;<br />
&nbsp; &nbsp; <span class="kw2">private</span> float yrot=<span class="nu0">0</span>.1f;<br />
&nbsp; &nbsp; <span class="kw2">private</span> float zrot=<span class="nu0">0</span>.1f;</p>
<p>&nbsp; &nbsp; <span class="coMULTI">/** The texture that&#8217;s been loaded */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">private</span> Texture texture;</p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">static</span> <span class="kw4">void</span> main<span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&#038;bntl=1"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; EngineTest app=<span class="kw2">new</span> EngineTest<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; initDisplay<span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; initGL<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; app.<span class="me1">init</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; app.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">static</span> <span class="kw4">void</span> initDisplay<span class="br0">&#40;</span><span class="kw4">boolean</span> fullscreen<span class="br0">&#41;</span><span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; DisplayMode chosenMode = <span class="kw2">null</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DisplayMode<span class="br0">&#91;</span><span class="br0">&#93;</span> modes = Display.<span class="me1">getAvailableDisplayModes</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i=<span class="nu0">0</span>;i&lt;modes.<span class="me1">length</span>;i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>modes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span> == targetWidth<span class="br0">&#41;</span> &amp;&amp; <span class="br0">&#40;</span>modes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">getHeight</span><span class="br0">&#40;</span><span class="br0">&#41;</span> == targetHeight<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chosenMode = modes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw2">catch</span> <span class="br0">&#40;</span>LWJGLException e<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Sys.<span class="me1">alert</span><span class="br0">&#40;</span><span class="st0">&#8220;Error&#8221;</span>, <span class="st0">&#8220;Unable to determine display modes.&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&#038;bntl=1"><span class="kw3">System</span></a>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// at this point if we have no mode there was no appropriate, let the user know</span><br />
&nbsp; &nbsp; <span class="co1">// and give up</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>chosenMode == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sys.<span class="me1">alert</span><span class="br0">&#40;</span><span class="st0">&#8220;Error&#8221;</span>, <span class="st0">&#8220;Unable to find appropriate display mode.&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&#038;bntl=1"><span class="kw3">System</span></a>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display.<span class="me1">setDisplayMode</span><span class="br0">&#40;</span>chosenMode<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display.<span class="me1">setFullscreen</span><span class="br0">&#40;</span>fullscreen<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display.<span class="me1">setTitle</span><span class="br0">&#40;</span><span class="st0">&#8220;LWJGL window&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display.<span class="me1">create</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">catch</span> <span class="br0">&#40;</span>LWJGLException e<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sys.<span class="me1">alert</span><span class="br0">&#40;</span><span class="st0">&#8220;Error&#8221;</span>,<span class="st0">&#8220;Unable to create display.&#8221;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&#038;bntl=1"><span class="kw3">System</span></a>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">static</span> <span class="kw4">boolean</span> initGL<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glMatrixMode</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_PROJECTION</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glLoadIdentity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="co1">//&nbsp; &nbsp; &nbsp; &nbsp; Calculate the aspect ratio of the window</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GLU.<span class="me1">gluPerspective</span><span class="br0">&#40;</span><span class="nu0">45</span>.0f,<span class="br0">&#40;</span><span class="br0">&#40;</span>float<span class="br0">&#41;</span>targetWidth<span class="br0">&#41;</span>/<span class="br0">&#40;</span><span class="br0">&#40;</span>float<span class="br0">&#41;</span>targetHeight<span class="br0">&#41;</span>,<span class="nu0">0</span>.1f,<span class="nu0">100</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glMatrixMode</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_MODELVIEW</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glLoadIdentity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glEnable</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_TEXTURE_2D</span><span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Enable Texture Mapping ( NEW )</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glShadeModel</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_SMOOTH</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glClearColor</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glClearDepth</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glEnable</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_DEPTH_TEST</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glDepthFunc</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_LEQUAL</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glHint</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_PERSPECTIVE_CORRECTION_HINT</span>, GL11.<span class="me1">GL_NICEST</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">true</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">try</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; texture = TextureLoader.<span class="me1">getTexture</span><span class="br0">&#40;</span><span class="st0">&#8220;PNG&#8221;</span>, <span class="kw2">new</span> <a href="http://www.google.com/search?q=allinurl%3AFileInputStream+java.sun.com&#038;bntl=1"><span class="kw3">FileInputStream</span></a><span class="br0">&#40;</span><span class="st0">&#8220;Data/grass.png&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw2">catch</span> <span class="br0">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AIOException+java.sun.com&#038;bntl=1"><span class="kw3">IOException</span></a> ex<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Logger.<span class="me1">getLogger</span><span class="br0">&#40;</span>EngineTest.<span class="kw2">class</span>.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">log</span><span class="br0">&#40;</span>Level.<span class="me1">SEVERE</span>, <span class="kw2">null</span>, ex<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> run<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span><span class="br0">&#40;</span>gameRunning<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; render<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display.<span class="me1">update</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// finally check if the user has requested that the display be</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// shutdown</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>Display.<span class="me1">isCloseRequested</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gameRunning = <span class="kw2">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Display.<span class="me1">destroy</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&#038;bntl=1"><span class="kw3">System</span></a>.<span class="me1">exit</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> update<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xrot+=<span class="nu0">0</span>.1f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; yrot+=<span class="nu0">0</span>.1f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; zrot+=<span class="nu0">0</span>.1f;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">private</span> <span class="kw4">void</span> render<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glClear</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_COLOR_BUFFER_BIT</span>|GL11.<span class="me1">GL_DEPTH_BUFFER_BIT</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glLoadIdentity</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTranslatef</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f,<span class="nu0">0</span>.0f,-<span class="nu0">5</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;<span class="co1">// Move Into The Screen 5 Units</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glRotatef</span><span class="br0">&#40;</span>xrot,<span class="nu0">1</span>.0f,<span class="nu0">0</span>.0f,<span class="nu0">0</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Rotate On The X Axis</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glRotatef</span><span class="br0">&#40;</span>yrot,<span class="nu0">0</span>.0f,<span class="nu0">1</span>.0f,<span class="nu0">0</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Rotate On The Y Axis</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glRotatef</span><span class="br0">&#40;</span>zrot,<span class="nu0">0</span>.0f,<span class="nu0">0</span>.0f,<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Rotate On The Z Axis</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; texture.<span class="me1">bind</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// or GL11.glBind(texture.getTextureID());</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glBegin</span><span class="br0">&#40;</span>GL11.<span class="me1">GL_QUADS</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Front Face</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Left Of The Texture and Quad</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Back Face</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Left Of The Texture and Quad</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Top Face</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Right Of The Texture and Quad</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Bottom Face</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Right Of The Texture and Quad</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Right face</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span> <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Left Of The Texture and Quad</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Left Face</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">0</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Bottom Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">1</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Right Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glTexCoord2f</span><span class="br0">&#40;</span><span class="nu0">0</span>.0f, <span class="nu0">1</span>.0f<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glVertex3f</span><span class="br0">&#40;</span>-<span class="nu0">1</span>.0f,&nbsp; <span class="nu0">1</span>.0f, -<span class="nu0">1</span>.0f<span class="br0">&#41;</span>;&nbsp; &nbsp;<span class="co1">// Top Left Of The Texture and Quad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; GL11.<span class="me1">glEnd</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p><strong>Gracias.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/loading-imagetexture-mapping-in-lwjgl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting Up LWJGL with Netbeans</title>
		<link>http://www.gaanza.com/blog/setting-up-lwjgl-with-netbeans/</link>
		<comments>http://www.gaanza.com/blog/setting-up-lwjgl-with-netbeans/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 04:41:05 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[lwjgl]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[setting up lwjgl with netbeans]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=285</guid>
		<description><![CDATA[
On Forums, people keeps asking about setting up lwjgl library with netbeans. So here i am going to show the steps to do that.
STEP 1: Go to Tools-&#62; Libariries.Now create new library. Give it a name say &#8220;lwjgl21&#8243;.

STEP 2: Now we have to configure the library. Click the classpath tab, then click add jars, and [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Fsetting-up-lwjgl-with-netbeans%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>On Forums, people keeps asking about setting up lwjgl library with netbeans. So here i am going to show the steps to do that.</p>
<p><strong>STEP 1: </strong>Go to Tools-&gt; Libariries.Now create new library. Give it a name say &#8220;lwjgl21&#8243;.</p>
<p><img class="alignnone size-full wp-image-286" title="step1" src="http://www.gaanza.com/wp-content/uploads/2009/09/step1.png" alt="step1" width="535" height="213" /></p>
<p><strong>STEP 2:</strong> Now we have to configure the library. Click the classpath tab, then click add jars, and add all the jars shown below:</p>
<p><img class="alignnone size-full wp-image-287" title="step2" src="http://www.gaanza.com/wp-content/uploads/2009/09/step2.png" alt="step2" width="534" height="406" /></p>
<p><strong>STEP 3:</strong> If u want to add java doc than click the javadoc tab, and then add the javadoc folder. Then finally click oK and lwjgl21 library that we have just created is done.</p>
<p><strong>STEP 4:</strong> Now create a empty java project.</p>
<p><img class="alignnone size-full wp-image-288" title="step3" src="http://www.gaanza.com/wp-content/uploads/2009/09/step3.png" alt="step3" width="305" height="144" /></p>
<p><strong>STEP 5:</strong> Now we have to set the properties so that our newly created project can find the lwjgl library and jar files. So Right-Click the project-&gt; Properties. Now check the image carefully and configure accordingly. So first select libraries on the categories section and then click compile tab, and then add jar file for compilation step. This step is very important so check image properly below.</p>
<p><img class="alignnone size-full wp-image-289" title="step4" src="http://www.gaanza.com/wp-content/uploads/2009/09/step4.png" alt="step4" width="578" height="189" /></p>
<p><strong>STEP 6:</strong> Okie now click run tab, and add the library that we had just created. Check the image very properly.</p>
<p><img class="alignnone size-full wp-image-294" title="step5" src="http://www.gaanza.com/wp-content/uploads/2009/09/step51.png" alt="step5" width="548" height="177" /></p>
<p><strong>STEP 7:</strong> Now the final step. We have to provide the argument so that project cud find the necessary dll files. So first select the Run at caregories section then go to vm-options. Check the image properly and follow.</p>
<p><img class="alignnone size-full wp-image-291" title="step6" src="http://www.gaanza.com/wp-content/uploads/2009/09/step6.png" alt="step6" width="565" height="207" /></p>
<p>Okie thats it. Now click ok. So you have just set up lwjgl with your netbeans ide. So now you can compile and run your lwjgl app. I am using netbeans ide 6.7.</p>
<p><strong>Gracias</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/setting-up-lwjgl-with-netbeans/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing or Setting up JOGL on Ubuntu</title>
		<link>http://www.gaanza.com/blog/setting-up-jogl-in-ubuntu/</link>
		<comments>http://www.gaanza.com/blog/setting-up-jogl-in-ubuntu/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 03:50:38 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jogl]]></category>
		<category><![CDATA[jogl on ubuntu]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=118</guid>
		<description><![CDATA[

Here are the detailed steps to set up or install JOGL on your ubuntu. First of all you have to download the jogl library(according to your machine) from here . I am using Ubuntu 8.04 on intel board so i downloaded jogl-1.1.1-linux-i586.zip.
So extract the zip file. Now open the folder that you have just now [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Fsetting-up-jogl-in-ubuntu%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><img class="aligncenter size-full wp-image-143" title="gl_java_ubuntu1" src="http://www.gaanza.com/wp-content/uploads/2009/06/gl_java_ubuntu1.png" alt="gl_java_ubuntu1" width="500" height="150" /></p>
<p>Here are the detailed steps to set up or install JOGL on your ubuntu. First of all you have to <a href="https://jogl.dev.java.net/servlets/ProjectDocumentList?folderID=9260&amp;expandFolder=9260&amp;folderID=0" target="_self">download</a> the jogl library(according to your machine) from <a href="https://jogl.dev.java.net/servlets/ProjectDocumentList?folderID=9260&amp;expandFolder=9260&amp;folderID=0" target="_blank">here</a> . I am using Ubuntu 8.04 on intel board so i downloaded jogl-1.1.1-linux-i586.zip.</p>
<p>So extract the zip file. Now open the folder that you have just now extracted. Go to lib folder.</p>
<p><strong>STEP 1</strong>: Now you have to copy four .so files i.e libjogl.so, libjogl_awt.so, libjogl_cg.so, libgluegen-rt.so to [javainstalation directory]/jre/lib/i386</p>
<p>Open the terminal window and type: sudo cp libjogl.so /usr/lib/java/jdk1.6.0_13/jre/lib/i386</p>
<p>similarly you have to copy other three .so files.</p>
<p>*you have to provide you java installation path*</p>
<p><img class="alignnone size-full wp-image-120" title="jogl1" src="http://www.gaanza.com/wp-content/uploads/2009/06/jogl1.png" alt="jogl1" width="659" height="125" /></p>
<p>Now you can check the destination if files has been copied.</p>
<p><img class="alignnone size-full wp-image-122" title="jogl21" src="http://www.gaanza.com/wp-content/uploads/2009/06/jogl21.png" alt="jogl21" width="572" height="458" /></p>
<p><strong>STEP 2:</strong> Now copy jogl.jar and gluegen-rt.jar to [java installation di]/jre/lib/ext</p>
<p>run this command to copy: sudo cp jogl.jar /usr/lib/java/jdk1.6.0_13/jre/lib/ext</p>
<p>simillarly copy gluegen-rt.jar</p>
<p>*you have to provide your java installation path*</p>
<p><img class="alignnone size-full wp-image-123" title="jogl3" src="http://www.gaanza.com/wp-content/uploads/2009/06/jogl3.png" alt="jogl3" width="593" height="196" /></p>
<p>You can check:</p>
<p><img class="alignnone size-full wp-image-124" title="jogl4" src="http://www.gaanza.com/wp-content/uploads/2009/06/jogl4.png" alt="jogl4" width="566" height="326" /></p>
<p><strong>STEP 3</strong>: SO thats it. Now lets test the simple jogl code.</p>
<p><em>import javax.media.opengl.GLCapabilities;</em></p>
<p><em>public class Hello{<br />
public static void main (String args[]) {<br />
try {<br />
System.loadLibrary(&#8220;jogl&#8221;);<br />
System.out.println(<br />
&#8220;Hello World! (The native libraries are installed.)&#8221;<br />
);<br />
GLCapabilities caps = new GLCapabilities();<br />
System.out.println(<br />
&#8220;Hello JOGL! (The jar appears to be available.)&#8221;<br />
);<br />
} catch (Exception e) {<br />
System.out.println(e);<br />
}<br />
}<br />
} </em></p>
<p>Now compile this Hello.java and the run it. Here is the output:</p>
<p><img class="alignnone size-full wp-image-125" title="jogl-final" src="http://www.gaanza.com/wp-content/uploads/2009/06/jogl-final.png" alt="jogl-final" width="529" height="125" /></p>
<p>So thats it. Now your are off to fly and write your jogl apps.</p>
<p><strong>Thanks.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/setting-up-jogl-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Alpha Blending using OpenGL with SDL</title>
		<link>http://www.gaanza.com/blog/alpha-blending/</link>
		<comments>http://www.gaanza.com/blog/alpha-blending/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 14:53:11 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Opengl with SDL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[alpha blending]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[sdl]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=88</guid>
		<description><![CDATA[

Alpha Blending is a convex combination of two colors allowing for transparency effects in computer graphics. Blending is used to combine the color of a given pixel that is about to be drawn with the pixel that is already on the screen.  How the colors are combined is based on the alpha value of [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Falpha-blending%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><img class="aligncenter size-full wp-image-137" title="sdl_opengl" src="http://www.gaanza.com/wp-content/uploads/2009/06/sdl_opengl1.png" alt="sdl_opengl" width="480" height="150" /></p>
<p>Alpha Blending is a convex combination of two colors allowing for transparency effects in computer graphics. <span class="text">Blending is used to combine the color of a given pixel that is about to be drawn with the pixel that is already on the screen.  How the colors are combined is based on the alpha value of the colors, and/or the blending function that is being used.  Alpha is a 4th color component usually specified at the end.<br />
</span></p>
<p>Alpha Blending in SDL is slow because its not a hardware accelerated. To get a better performance there is OpenGL which is hardware accelerated. So here i&#8217;l show you how to use alpha blending using opengl with sdl.</p>
<div class="codesnip-container" >
<div class="codesnip">glColor4f<span class="br0">&#40;</span><span class="nu0">1</span>.0f,<span class="nu0">1</span>.0f,<span class="nu0">1</span>.0f,alpha<span class="br0">&#41;</span>; <span class="co1">// full Brightness, Alpha</span></p>
<p>glBlendFunc<span class="br0">&#40;</span>GL_SRC_ALPHA,GL_ONE<span class="br0">&#41;</span>; <span class="co1">// Blending Function for  translucency based on source alpha value&gt; </span><br />
&nbsp;</div>
</div>
<p>First line set the color to full brightness with alpha value. An alpha value of 0.0 would mean that the material is completely transparent . A value of 1.0 would be totally opaque. The primitive&#8217;s opacity is specified using glColor4*(). RGB specifies the color, and the alpha parameter specifies the opacity.</p>
<div class="codesnip-container" >
<div class="codesnip">glEnable<span class="br0">&#40;</span>GL_BLEND<span class="br0">&#41;</span>;                      <span class="co1">// Turn Blending on</span></p>
<p>glDisable<span class="br0">&#40;</span>GL_DEPTH_TEST<span class="br0">&#41;</span>;        <span class="co1">//Turn Depth Testing off </span><br />
&nbsp;</div>
</div>
<p>So this is it what you will required to achieve alpha blending.</p>
<p>Below code is a simple FADE IN/FADE OUT program. When UP arow key is pressed then 2d sprite will fade out and when DOWN key is pressed then 2d sprite will fade in.</p>
<p><img class="alignnone size-full wp-image-115" title="alpha" src="http://www.gaanza.com/wp-content/uploads/2009/06/alpha.png" alt="alpha" width="572" height="428" /></p>
<p>Here is the full Source Code:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co2">#include &quot;SDL.h&quot;</span><br />
<span class="co2">#include &quot;SDL_image.h&quot;</span><br />
<span class="co2">#include &quot;SDL_opengl.h&quot;</span></p>
<p><span class="co2">#include &amp;lt;stdio.h&amp;gt;</span></p>
<p>GLuint texture=<span class="kw2">NULL</span>;     <span class="co1">//this is a handle to our texture object</span><br />
GLenum texture_format=<span class="kw2">NULL</span>;<br />
GLint nofcolors;</p>
<p>SDL_Event event;</p>
<p><span class="kw4">float</span> alpha=<span class="nu0">1</span>.0f;<br />
bool UP=<span class="kw2">false</span>;         <span class="co1">//Up key is pressed/released</span><br />
bool DOWN=<span class="kw2">false</span>;       <span class="co1">//DOWN key is pressed/released&lt;/em&gt;</span></p>
<p>&lt;em&gt;int loadImage<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
SDL_Surface *surface; <span class="co1">// this surface will tell us the details of the image</span></p>
<p><span class="kw1">if</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span>surface = IMG_Load<span class="br0">&#40;</span><span class="st0">&#8220;flower.png&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p><span class="co1">// Check that the image&#8217;s width is a power of 2</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span>surface-&amp;gt;w &amp;amp; <span class="br0">&#40;</span>surface-&amp;gt;w &#8211; <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> != <span class="nu0">0</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&#8220;warning: image.bmp&#8217;s width is not a power of 2<span class="es0">\n</span>&#8220;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// Also check if the height is a power of 2</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span>surface-&amp;gt;h &amp;amp; <span class="br0">&#40;</span>surface-&amp;gt;h &#8211; <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> != <span class="nu0">0</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&#8220;warning: image.bmp&#8217;s height is not a power of 2<span class="es0">\n</span>&#8220;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="co1">//get number of channels in the SDL surface</span><br />
nofcolors=surface-&amp;gt;format-&amp;gt;BytesPerPixel;</p>
<p><span class="co1">//contains an alpha channel</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>nofcolors==<span class="nu0">4</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>surface-&amp;gt;format-&amp;gt;Rmask==0&#215;000000ff<span class="br0">&#41;</span><br />
texture_format=GL_RGBA;<br />
<span class="kw1">else</span><br />
texture_format=GL_BGRA;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>nofcolors==<span class="nu0">3</span><span class="br0">&#41;</span> <span class="co1">//no alpha channel</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>surface-&amp;gt;format-&amp;gt;Rmask==0&#215;000000ff<span class="br0">&#41;</span><br />
texture_format=GL_RGB;<br />
<span class="kw1">else</span><br />
texture_format=GL_BGR;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span><br />
<span class="br0">&#123;</span><br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&#8220;warning: the image is not truecolor&#8230;this will break &#8220;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// Have OpenGL generate a texture object handle for us</span><br />
glGenTextures<span class="br0">&#40;</span> <span class="nu0">1</span>, &amp;amp;texture <span class="br0">&#41;</span>;</p>
<p><span class="co1">// Bind the texture object</span><br />
glBindTexture<span class="br0">&#40;</span> GL_TEXTURE_2D, texture <span class="br0">&#41;</span>;</p>
<p><span class="co1">// Set the texture&#8217;s stretching properties</span><br />
glTexParameteri<span class="br0">&#40;</span> GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR <span class="br0">&#41;</span>;<br />
glTexParameteri<span class="br0">&#40;</span> GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR <span class="br0">&#41;</span>;</p>
<p>glTexImage2D<span class="br0">&#40;</span> GL_TEXTURE_2D, <span class="nu0">0</span>, nofcolors, surface-&amp;gt;w, surface-&amp;gt;h, <span class="nu0">0</span>,<br />
texture_format, GL_UNSIGNED_BYTE, surface-&amp;gt;pixels <span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span> <span class="br0">&#123;</span><br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&#8220;SDL could not load image.bmp: %s<span class="es0">\n</span>&#8220;</span>, SDL_GetError<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
SDL_Quit<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> <span class="nu0">1</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// Free the SDL_Surface only if it was successfully created</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span> surface <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
SDL_FreeSurface<span class="br0">&#40;</span> surface <span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw4">void</span> drawImage<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
glClear<span class="br0">&#40;</span> GL_COLOR_BUFFER_BIT <span class="br0">&#41;</span>;   <span class="co1">// Clear the screen before drawing</span></p>
<p>glTranslatef<span class="br0">&#40;</span><span class="nu0">300</span>.<span class="nu0">0</span>,<span class="nu0">200</span>.<span class="nu0">0</span>,<span class="nu0">0</span>.<span class="nu0">0</span><span class="br0">&#41;</span>;</p>
<p>glBindTexture<span class="br0">&#40;</span> GL_TEXTURE_2D, texture <span class="br0">&#41;</span>;   <span class="co1">// Bind the texture to which subsequent calls refer to</span></p>
<p>glColor4f<span class="br0">&#40;</span><span class="nu0">1</span>.0f,<span class="nu0">1</span>.0f,<span class="nu0">1</span>.0f,alpha<span class="br0">&#41;</span>;            <span class="co1">// Full Brightness, Alpha</span><br />
glBlendFunc<span class="br0">&#40;</span>GL_SRC_ALPHA,GL_ONE<span class="br0">&#41;</span>;           <span class="co1">// // Blending Function For Translucency Based On Source Alpha Value</span></p>
<p>glBegin<span class="br0">&#40;</span> GL_QUADS <span class="br0">&#41;</span>;<br />
<span class="co1">// Top-left vertex (corner)</span><br />
glTexCoord2i<span class="br0">&#40;</span> <span class="nu0">0</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;<br />
glVertex3f<span class="br0">&#40;</span> -<span class="nu0">64</span>, -<span class="nu0">64</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;</p>
<p><span class="co1">// Bottom-left vertex (corner)</span><br />
glTexCoord2i<span class="br0">&#40;</span> <span class="nu0">1</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;<br />
glVertex3f<span class="br0">&#40;</span> <span class="nu0">64</span>, -<span class="nu0">64</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;</p>
<p><span class="co1">// Bottom-right vertex (corner)</span><br />
glTexCoord2i<span class="br0">&#40;</span> <span class="nu0">1</span>, <span class="nu0">1</span> <span class="br0">&#41;</span>;<br />
glVertex3f<span class="br0">&#40;</span> <span class="nu0">64</span>, <span class="nu0">64</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;</p>
<p><span class="co1">// Top-right vertex (corner)</span><br />
glTexCoord2i<span class="br0">&#40;</span> <span class="nu0">0</span>, <span class="nu0">1</span> <span class="br0">&#41;</span>;<br />
glVertex3f<span class="br0">&#40;</span> -<span class="nu0">64</span>, <span class="nu0">64</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;<br />
glEnd<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
glLoadIdentity<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>SDL_GL_SwapBuffers<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw4">int</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
SDL_Surface *screen;</p>
<p><span class="co1">// Slightly different SDL initialization</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span> SDL_Init<span class="br0">&#40;</span>SDL_INIT_VIDEO<span class="br0">&#41;</span> != <span class="nu0">0</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&#8220;Unable to initialize SDL: %s<span class="es0">\n</span>&#8220;</span>, SDL_GetError<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> <span class="nu0">1</span>;<br />
<span class="br0">&#125;</span></p>
<p>SDL_GL_SetAttribute<span class="br0">&#40;</span> SDL_GL_DOUBLEBUFFER, <span class="nu0">1</span> <span class="br0">&#41;</span>;</p>
<p>screen = SDL_SetVideoMode<span class="br0">&#40;</span> <span class="nu0">640</span>, <span class="nu0">480</span>, <span class="nu0">16</span>, SDL_OPENGL<span class="br0">&#41;</span>;<br />
<span class="kw1">if</span> <span class="br0">&#40;</span> !screen <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span class="kw3">printf</span></a><span class="br0">&#40;</span><span class="st0">&#8220;Unable to set video mode: %s<span class="es0">\n</span>&#8220;</span>, SDL_GetError<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> <span class="nu0">1</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw4">void</span> init_GL<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">// Set the OpenGL state after creating the context with SDL_SetVideoMode</span></p>
<p>glClearColor<span class="br0">&#40;</span> <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span> <span class="br0">&#41;</span>;</p>
<p>glEnable<span class="br0">&#40;</span> GL_TEXTURE_2D <span class="br0">&#41;</span>;        <span class="co1">// Need this to display a texture</span><br />
glEnable<span class="br0">&#40;</span>GL_BLEND<span class="br0">&#41;</span>;                  <span class="co1">// Turn Blending On</span><br />
glDisable<span class="br0">&#40;</span>GL_DEPTH_TEST<span class="br0">&#41;</span>;         <span class="co1">//Turn Depth Testing Off&lt;/em&gt;</span></p>
<p>glViewport<span class="br0">&#40;</span> <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">640</span>, <span class="nu0">480</span> <span class="br0">&#41;</span>;</p>
<p>glMatrixMode<span class="br0">&#40;</span> GL_PROJECTION <span class="br0">&#41;</span>;<br />
glLoadIdentity<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>glOrtho<span class="br0">&#40;</span> <span class="nu0">0</span>, <span class="nu0">640</span>, <span class="nu0">480</span>, <span class="nu0">0</span>, -<span class="nu0">1</span>, <span class="nu0">1</span> <span class="br0">&#41;</span>;</p>
<p>glMatrixMode<span class="br0">&#40;</span> GL_MODELVIEW <span class="br0">&#41;</span>;<br />
glLoadIdentity<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw4">void</span> clean_up<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
glDeleteTextures<span class="br0">&#40;</span> <span class="nu0">1</span>, &amp;amp;texture <span class="br0">&#41;</span>;&lt;/em&gt;</p>
<p>SDL_Quit<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="kw4">int</span> argc, <span class="kw4">char</span> *argv<span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//Make sure the program waits for a quit</span><br />
bool quit = <span class="kw2">false</span>;</p>
<p>init<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
init_GL<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
loadImage<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
drawImage<span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="kw1">while</span><span class="br0">&#40;</span> quit == <span class="kw2">false</span> <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span> SDL_PollEvent<span class="br0">&#40;</span> &amp;amp;event <span class="br0">&#41;</span> <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//If a key was pressed</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span> event.<span class="me1">type</span> == SDL_KEYDOWN <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//Adjust the velocity</span><br />
<span class="kw1">switch</span><span class="br0">&#40;</span> event.<span class="me1">key</span>.<span class="me1">keysym</span>.<span class="me1">sym</span> <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">case</span> SDLK_UP:<br />
UP=<span class="kw2">true</span>;<br />
<span class="kw2">break</span>;<br />
<span class="kw1">case</span> SDLK_DOWN:<br />
DOWN=<span class="kw2">true</span>;<br />
<span class="kw2">break</span>;<br />
<span class="kw1">case</span> SDLK_ESCAPE:<br />
quit=<span class="kw2">true</span>;<br />
<span class="kw2">break</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="co1">//If a key was released</span><br />
<span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span> event.<span class="me1">type</span> == SDL_KEYUP <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="co1">//Adjust the velocity</span><br />
<span class="kw1">switch</span><span class="br0">&#40;</span> event.<span class="me1">key</span>.<span class="me1">keysym</span>.<span class="me1">sym</span> <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">case</span> SDLK_UP:<br />
UP=<span class="kw2">false</span>;<br />
<span class="kw2">break</span>;<br />
<span class="kw1">case</span> SDLK_DOWN:<br />
DOWN=<span class="kw2">false</span>;<br />
<span class="kw2">break</span>;<br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// If UP key is pressed</span></p>
<p>
<span class="kw1">if</span><span class="br0">&#40;</span>UP==<span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>alpha&amp;lt;<span class="nu0">1</span>.0f<span class="br0">&#41;</span>         <span class="co1">// make sure alpha value is not greater than maximum value 1.0</span><br />
alpha+=<span class="nu0">0</span>.01f;       <span class="co1">//increase the alpha value, fade out</span><br />
drawImage<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>DOWN==<span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#123;</span>    <span class="co1">//If DOWN key is pressed</span><br />
<span class="kw1">if</span><span class="br0">&#40;</span>alpha&amp;gt;<span class="nu0">0</span>.0f<span class="br0">&#41;</span>       <span class="co1">// make sure value of alpha is not less than 0.0f</span><br />
alpha-=<span class="nu0">0</span>.01f;      <span class="co1">// decrease the alpha value, fade in</span><br />
drawImage<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></p>
<p>clean_up<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">return</span> <span class="nu0">0</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>So thats it. Now you are off to fly.</p>
<p><strong>Gracias.</strong></p>
<p><a name="fb_share" type="box_count share_url="http://www.gaanza.com/blog/alpha-blending/"></a><br />
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
        type="text/javascript">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/alpha-blending/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up java classpath on ubuntu</title>
		<link>http://www.gaanza.com/blog/setting-up-classpath-for-java-on-ubuntu/</link>
		<comments>http://www.gaanza.com/blog/setting-up-classpath-for-java-on-ubuntu/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 01:31:23 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[java classpath ubuntu]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=81</guid>
		<description><![CDATA[

When u install sun&#8217;s jdk manually on ubuntu, java classpath doesn&#8217;t get set automatically unlike in windows. So when you enter command javac in terminal window, it says &#8220;javac  command not found&#8221;. So here is the very simple way to set up the classpath for java on ubuntu.
STEP 1 : Open the terminal window.
STEP 2: [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Fsetting-up-classpath-for-java-on-ubuntu%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><img class="aligncenter size-full wp-image-133" title="java_ubuntu" src="http://www.gaanza.com/wp-content/uploads/2009/06/java_ubuntu.png" alt="java_ubuntu" width="350" height="150" /></p>
<p>When u install sun&#8217;s jdk manually on ubuntu, java classpath doesn&#8217;t get set automatically unlike in windows. So when you enter command javac in terminal window, it says &#8220;javac  command not found&#8221;. So here is the very simple way to set up the classpath for java on ubuntu.</p>
<p><strong>STEP 1</strong> : Open the terminal window.</p>
<p><strong>STEP 2</strong>: Type sudo gedit /etc/bash.bash.rc. Press enter.</p>
<p><strong>STEP 3</strong>: Now gedit editor will open up. Now at the end of file just write:</p>
<p>PATH=$PATH:/usr/lib/java/jdk1.6.0_13/bin</p>
<p>export PATH</p>
<p>**You have to provide the path of bin folder in java installation deirectory.**</p>
<p><img class="alignnone size-full wp-image-82" title="screenshot-12" src="http://www.gaanza.com/wp-content/uploads/2009/06/screenshot-12.png" alt="screenshot-12" width="554" height="415" /></p>
<p><strong>STEP 4</strong>: Now save the file and close the editor and terminal. Open new terminal window and type javac and press enter, all the java options and flags will come up.</p>
<p>Thats it.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/setting-up-classpath-for-java-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make a exe file of Java Program ?</title>
		<link>http://www.gaanza.com/blog/how-to-make-a-exe-file-for-java-program/</link>
		<comments>http://www.gaanza.com/blog/how-to-make-a-exe-file-for-java-program/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 15:50:15 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.exe file of java]]></category>
		<category><![CDATA[exe4j]]></category>
		<category><![CDATA[java exe maker]]></category>
		<category><![CDATA[making an exe for java app]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=61</guid>
		<description><![CDATA[
If you are making a java program for windows operating system only then  wouldn&#8217;t it be easy to have a exe file for your java program and distribute it to the users and user would find easy to execute your program. Well i guess yes because exe would definetly make easy for users to execute [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Fhow-to-make-a-exe-file-for-java-program%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>If you are making a java program for windows operating system only then  wouldn&#8217;t it be easy to have a exe file for your java program and distribute it to the users and user would find easy to execute your program. Well i guess yes because exe would definetly make easy for users to execute your java programs. So:</p>
<p>Q. How to make an exe file for your java program ?</p>
<p>A. exe4J.</p>
<p>exe4j is a Java exe maker that helps you integrate your Java applications into             the Windows operating environment, whether they are service, GUI or command line             applications. If you want your own process name instead of             java.exe in the task manager and a user friendly task-bar grouping in Windows XP,             exe4j does the job. exe4j helps you with starting your Java applications in a             safe way, displaying native splash screens, detecting or distributing suitable             JREs and JDKs, startup error handling and much more.</p>
<p>Check out the <a href="http://www.ej-technologies.com/products/exe4j/features.html" target="_blank">features</a> of exe4J. <a href="http://www.ej-technologies.com/download/exe4j/files.html" target="_blank">Download</a>(i would suggest you to download zip archive) the exe4J from <a href="http://www.ej-technologies.com/download/exe4j/files.html" target="_blank">here</a>.</p>
<p>Ok now i&#8217;ll show you the steps to use exe4J for making exe. So download the exe4J zip archive and extract it to your preference location. Here i&#8217;ll be showing you how to create exe file for your java executable jar file. So lets first write a simple swing frame application which will just create a frame.</p>
<p><em>import javax.swing.*;</em></p>
<p><em>public class Test<br />
{<br />
public Test(){<br />
JFrame frame=new JFrame(&#8220;test&#8221;);<br />
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
frame.setSize(400,300);<br />
frame.setVisible(true);<br />
}<br />
public static void main(String[] args){<br />
new Test();<br />
}<br />
}</em></p>
<p>Ok save Test.java it in some folder ( I have saved it in E:/java_programs).</p>
<p>Now open your  command prompt, navigate to the folder where Test.java file is saved and compile the Test.java using command javac Test.java</p>
<p>Now we&#8217;ll create a manifest file which will be needed to make an executable jar file. So this is the way you write your manifest file:</p>
<p>Main-Class: Test</p>
<p>First line on your manifest file will be Main-Class:&lt;space&gt;main-class(class file with the main method). then new line&lt;enter&gt;. You have to provide one new line after first line. Then save it as manifest.txt to the same folder where your Test.class file is saved.</p>
<p>Now we&#8217;ll create the executable jar file. Syntax is:  jar -cvmf manifest.txt &lt;name of jar file that you will create&gt; class file/package if used</p>
<p>so open up your command prompt, navigate to the folder where Test.class file and manifest file is saved. Then enter command jar -cvmf manifest.txt test.jar Test.class and press enter. Yout executable jar file is created. You can check and test it(java -jar test.jar).</p>
<p>Now executable jar file is ready. So now i&#8217;ll show you the steps to make exe from your executable jar file.</p>
<p><strong>STEP 1:</strong> Open the folder that u had extracted. Go to bin folder. Double click exe4j launcher. Now exe4j window will open up. Click next.</p>
<p><img class="alignnone size-full wp-image-62" title="1" src="http://www.gaanza.com/wp-content/uploads/2009/06/1.png" alt="1" width="565" height="417" /></p>
<p><strong>STEP 2:</strong> Choose &#8220;JAR in EXE&#8221; mode. Click next.</p>
<p><img class="alignnone size-full wp-image-63" title="2" src="http://www.gaanza.com/wp-content/uploads/2009/06/2.png" alt="2" width="559" height="415" /></p>
<p><strong>STEP 3:</strong> Now give the name for your application. I have given &#8220;app&#8221;. Then give the path of the location where you want to save the exe file. I have given the path of location where my class, manifest and jar file are located i.e E:/java_programs. Click next.</p>
<p><img class="alignnone size-full wp-image-64" title="3" src="http://www.gaanza.com/wp-content/uploads/2009/06/3.png" alt="3" width="559" height="417" /></p>
<p><strong>STEP 4:</strong> Now choose your executable type from list of radio buttons. In our case we will choose GUI application. Then give the name of exe file that we are making.  I have provided test. Now check the boxes as shown in the screenshot. And Click next.</p>
<p><img class="alignnone size-full wp-image-65" title="4" src="http://www.gaanza.com/wp-content/uploads/2009/06/4.png" alt="4" width="558" height="414" /></p>
<p><strong>STEP 5:</strong> Now give the name of your main class. In our case its Test. Don&#8217;t put the .class extension, just give the name. Now don&#8217;t click next.</p>
<p><img class="alignnone size-full wp-image-66" title="5" src="http://www.gaanza.com/wp-content/uploads/2009/06/5.png" alt="5" width="559" height="413" /></p>
<p><strong>STEP 6:</strong> You can see the the gree plus button on above screenshot. Click that and a window will open up. Check the archive radio button above.Now we have to provide the executable jar file to the Archive, so browse the location where your executable jar file is saved. Add it. Click OK. Click next.</p>
<p><img class="alignnone size-full wp-image-67" title="6" src="http://www.gaanza.com/wp-content/uploads/2009/06/6.png" alt="6" width="558" height="432" /></p>
<p><strong>STEP 7:</strong> Now we have to configure the JRE. So provide the minimum jre version and maximum jre version to be used by the user. Then click next.</p>
<p><img class="alignnone size-full wp-image-68" title="7" src="http://www.gaanza.com/wp-content/uploads/2009/06/7.png" alt="7" width="558" height="412" /></p>
<p><strong>STEP 8:</strong> Now we have to configure splash screen (if you want to). I haven&#8217;t provided splash screen so i have chosed no splash screen. You can give your choice. Click next.</p>
<p><img class="alignnone size-full wp-image-69" title="8" src="http://www.gaanza.com/wp-content/uploads/2009/06/8.png" alt="8" width="555" height="411" /></p>
<p><strong>STEP 9:</strong> Now we have to configure messages like if you want to give error message when user does not have JRE installed in his/her machine. Click next.</p>
<p><img class="alignnone size-full wp-image-70" title="9" src="http://www.gaanza.com/wp-content/uploads/2009/06/9.png" alt="9" width="560" height="413" /></p>
<p><strong>STEP 10:</strong> Now the last step of the wizard. If you want to save the configuration then click save as. I haven&#8217;t saved the configuration so i clicked EXIT. Then it will ask me if i want to save the configuration. Click NO(if you want to save click yes). So Thats it. Done.</p>
<p><img class="alignnone size-full wp-image-71" title="10" src="http://www.gaanza.com/wp-content/uploads/2009/06/10.png" alt="10" width="556" height="413" /></p>
<p>Now navigate the output folder where u have saved the exe file. In our case we provided the same folder where our jar and class files are located. In below screenshot you can see that test.exe file has been created.</p>
<p><img class="alignnone size-full wp-image-73" title="111" src="http://www.gaanza.com/wp-content/uploads/2009/06/111.png" alt="111" width="506" height="357" /></p>
<p>Now double click test.exe and message box(&#8220;executable was created using evalustion version of exe4J&#8221;) will open. Just click ok. Then application will run. In our program we created a frame so frame will get displayed.</p>
<p><img class="alignnone size-full wp-image-74" title="13" src="http://www.gaanza.com/wp-content/uploads/2009/06/13.png" alt="13" width="508" height="377" /></p>
<p>So thats it. You are off. Your exe has been created. Now you can distribute this exe to windows user. But i f u want to make a cross-platform distributed file then this methos is not recommended. This is for only windows environment.</p>
<p><strong>Thanks.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/how-to-make-a-exe-file-for-java-program/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Setting up Slick 2D with netbeans 6.5.1</title>
		<link>http://www.gaanza.com/blog/slick2d-netbeans/</link>
		<comments>http://www.gaanza.com/blog/slick2d-netbeans/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 16:22:59 +0000</pubDate>
		<dc:creator>padam</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[2D engine]]></category>
		<category><![CDATA[lwjgl]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[Slick 2D]]></category>
		<category><![CDATA[slick 2d with netbeans]]></category>

		<guid isPermaLink="false">http://www.gaanza.com/blog/?p=36</guid>
		<description><![CDATA[

Slick2D engine is a high performance 2d game library based on a LWJGL(Lightweight Java Game Library). You can see the current features of Slick2D in their site. Download the library from here.
You can check the games made in Slick2D engine http://www.cokeandcode.com/ and http://slick.cokeandcode.com/gallery.php.
Tutorials : There are good and easy to go tutorials for beginners.
Now download [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.gaanza.com%2Fblog%2Fslick2d-netbeans%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p><a href="http://www.gaanza.com/wp-content/uploads/2009/06/slick2d_netbeans.png"><img class="alignnone size-medium wp-image-58" title="slick2d_netbeans" src="http://www.gaanza.com/wp-content/uploads/2009/06/slick2d_netbeans-300x150.png" alt="" width="300" height="150" /></a><br />
Slick2D engine is a high performance 2d game library based on a LWJGL(Lightweight Java Game Library). You can see the current <a href="http://slick.cokeandcode.com/static.php?page=features" target="_blank">features</a> of Slick2D in their <a href="http://slick.cokeandcode.com/index.php" target="_blank">site</a>. <a href="http://slick.cokeandcode.com/index.php" target="_blank">Download</a> the library from <a href="http://slick.cokeandcode.com/index.php" target="_blank">here</a>.<br />
You can check the games made in Slick2D engine <a href="http://www.cokeandcode.com/" target="_blank">http://www.cokeandcode.com/</a> and <a href="http://slick.cokeandcode.com/gallery.php" target="_blank">http://slick.cokeandcode.com/gallery.php</a>.</p>
<p><a href="http://slick.cokeandcode.com/wiki/doku.php?id=tutorials" target="_blank">Tutorials </a>: There are good and easy to go <a href="http://slick.cokeandcode.com/wiki/doku.php?id=tutorials" target="_blank">tutorials</a> for beginners.</p>
<p>Now download the library. So here i&#8217;ll be telling how to setup the library with netbeans 6.5.1 so that u can write compile and run slick games easily and fast. I am using Ubuntu 8.04(Hardy heron), steps are similar for setting up in windows.</p>
<p><span style="font-size: 180%;"><span style="font-weight: bold;">STEP 1:</span></span> Download the library and save it in some appropriate place.<br />
<span style="font-weight: bold; font-size: 180%;">STEP 2:</span> Open your Netbeans 6.5.1.<br />
<span style="font-weight: bold; font-size: 180%;">STEP 3:</span> Go to tool-&gt;libraries. Library Manager window will open. Click New Library. Give it a name Slick. Then click OK.</p>
<p><img class="alignnone size-full wp-image-38" title="screenshot-11" src="http://www.gaanza.com/wp-content/uploads/2009/06/screenshot-11.png" alt="screenshot-11" width="543" height="413" /></p>
<p><span style="font-weight: bold; font-size: 180%;">STEP 4:</span> Now click classpath tab. Click Add Jar/Folder. Browse the folder where u have saved Your slick library. Go to lib folder and add all the jar files except slick.jar. Click OK</p>
<p><img class="alignnone size-full wp-image-39" title="screenshot-2" src="http://www.gaanza.com/wp-content/uploads/2009/06/screenshot-2.png" alt="screenshot-2" width="536" height="414" /></p>
<p><span style="font-weight: bold; font-size: 180%;">STEP 5:</span> Click JavaDoc tab. Click add/zip floder. Browse ur slick folder and select javadoc folder and add it. So done. Click OK.</p>
<p><img class="alignnone size-full wp-image-40" title="screenshot-3" src="http://www.gaanza.com/wp-content/uploads/2009/06/screenshot-3.png" alt="screenshot-3" width="535" height="410" /></p>
<p><span style="font-weight: bold; font-size: 180%;">STEP 6:</span> Ok so your slick library has been created. Now few steps remaining to complete the full set up. Create a new java project called SlickTest. Now Right Click SlickTest project, then click properties. Project properties window will open up. At left side, under categories select Libraries. Now at right side click Compile tab. Now Click Add Jar/Folder. Browse ur slick folder, go to lib folder, select slick.jar and add it.</p>
<p><img class="alignnone size-full wp-image-41" title="screenshot-4" src="http://www.gaanza.com/wp-content/uploads/2009/06/screenshot-4.png" alt="screenshot-4" width="599" height="487" /></p>
<p><span style="font-weight: bold; font-size: 180%;">STEP 7:</span> Now click Run tab. Click Add Library. Add Library window will open up. From there select Slick library that we previously created. Then add it.</p>
<p><img class="alignnone size-full wp-image-42" title="screenshot-5" src="http://www.gaanza.com/wp-content/uploads/2009/06/screenshot-5.png" alt="screenshot-5" width="580" height="472" /></p>
<p><span style="font-weight: bold; font-size: 180%;">FINAL STEP 8 :</span> Now at left side select Run. At Right side, go to VM Options, there u have to provide the parameter/argument that will link lwjgl libraries to your application. So at VM Options textbox, For Ubuntu users write: -Djava.library.path=<span style="font-style: italic;">lwjgl library path</span> For Windows user write: -Djava.library.path=&#8221;<span style="font-style: italic;">lwjgl library path&#8221;. And Click Ok</span></p>
<p><span style="font-style: italic;"><span style="font-style: italic;">Thats it</span></span> Windows users have to put the path within double quotes. Here <span style="font-style: italic;">lwjgl library path</span> is the path to the location where .so files for ubuntu linux(liblwjgl.so, liblwjgl64.so, libodejava.so,libopenal.so etc) and .dll for windows(liblwjgl.dll, liblwjgl64.dll, libodejava.dll,libopenal.dll etc) are located<span style="font-style: italic;">.</span></p>
<p>For windows user .dll files comes with slick library but linux users have to <a href="http://www.lwjgl.org/download.php" target="_blank">download</a> the native .so lib files.</p>
<p>So now you are done and lets write a simple program for testing. This code will just create a window. Create a class called Test under the project that we had created.</p>
<p>package com.padam.testing;</p>
<p>import org.newdawn.slick.AppGameContainer;<br />
import org.newdawn.slick.BasicGame;<br />
import org.newdawn.slick.GameContainer;<br />
import org.newdawn.slick.Graphics;<br />
import org.newdawn.slick.SlickException;</p>
<p>/**<br />
*<br />
* @author padam<br />
*/<br />
public class Test extends BasicGame{</p>
<p>public Test(String name){<br />
super(name);<br />
}</p>
<p>public static void main(String[] args){<br />
try {<br />
AppGameContainer container = new AppGameContainer(new Test(&#8220;Game&#8221;));<br />
container.setDisplayMode(800,600,false);<br />
container.start();<br />
} catch (SlickException e) {<br />
e.printStackTrace();<br />
}<br />
}</p>
<p>@Override<br />
public void init(GameContainer gc) throws SlickException {</p>
<p>}</p>
<p>@Override<br />
public void update(GameContainer gc, int delta) throws SlickException {</p>
<p>}</p>
<p>public void render(GameContainer gc, Graphics g) throws SlickException {</p>
<p>}</p>
<p>}</p>
<p><span style="font-weight: bold; font-size: 180%;">NOTE:</span> <span style="font-style: italic; font-weight: bold;">Linux and Mac users must download the lwjgl library. Then browse the folder and go to native folder. There choose your native OS folder. That will be your lwjgl library path</span> <span style="font-style: italic; font-weight: bold;">thatt will go to VM Options parameter as specified on last step or you can copy the .so/native files to your convenient location and provide that path to VM Options parameter.</span><br />
<span style="font-style: italic; font-weight: bold;">Now after this just test the above code. You may get a runtime error saying:</span></p>
<p><span style="font-style: italic; color: #006600;">Exception in thread &#8220;main&#8221; java.lang.LinkageError: Version mismatch: jar version is &#8216;16&#8242;, native libary version is &#8216;17&#8242; </span><br />
<span style="font-style: italic; color: #006600;"> at org.lwjgl.Sys.(Sys.java:105) </span><br />
<span style="font-style: italic; color: #006600;"> at org.lwjgl.opengl.Display.(Display.java:128) </span><br />
<span style="font-style: italic; color: #006600;"> at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39) </span><br />
<span style="font-style: italic; color: #006600;"> at java.security.AccessController.doPrivileged(Native Method) </span><br />
<span style="font-style: italic; color: #006600;"> at org.newdawn.slick.AppGameContainer.(AppGameContainer.java:36) </span><br />
<span style="font-style: italic; color: #006600;"> at com.padam.testing.Test.main(Test.java:26) </span><br />
<span style="font-style: italic; color: #006600;"> Java Result: 1 </span><br />
<span style="font-style: italic; color: #006600;"> BUILD SUCCESSFUL (total time: 1 second) </span></p>
<p><span style="font-style: italic; font-weight: bold;">Linux/Mac/Solaris might face this problem because lwjgl jar files that comes with slick might be of older version which won&#8217;t match with the new lwjgl native .so/native files that u have downloaded. This means that the lwjgl jar files and lwjgl native/ .so files doesn&#8217;t match. So what u have to do is browse lwjgl folder that u have downloaded and go to jar folder and copy all the jar files and paste/replace the old jar files in the lib folder located in slick folder or location of slick library.</span></p>
<p><span style="font-style: italic; font-weight: bold;">So Thats it. If u face any problem, comment it.</span></p>
<p><span style="font-weight: bold; font-size: 180%;">Gracias.</span></p>
<p><a name="fb_share" type="box_count share_url="http://www.gaanza.com/blog/slick2d-netbeans/"></a><br />
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
        type="text/javascript">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gaanza.com/blog/slick2d-netbeans/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
