<?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>Richard Carter &#187; Code Snippets/Tricks</title>
	<atom:link href="http://blog.rickyc.org/category/tech/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rickyc.org</link>
	<description>Computer Science &#38; Game Development Student at North Carolina State University</description>
	<lastBuildDate>Thu, 22 Sep 2011 06:58:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>JOGL Hello World</title>
		<link>http://blog.rickyc.org/2009/07/16/jogl-hello-world/</link>
		<comments>http://blog.rickyc.org/2009/07/16/jogl-hello-world/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 13:19:40 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Code Snippets/Tricks]]></category>

		<guid isPermaLink="false">http://blog.rickyc.org/?p=39</guid>
		<description><![CDATA[Here is a basic JOGL application: import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.awt.GLCanvas; import com.sun.opengl.util.Animator; public class JOGLAPP implements GLEventListener { &#160;&#160;public static void main(String[] args) { &#160;&#160;&#160;&#160;new JOGLAPP(); &#160;&#160;} &#160;&#160; &#160;&#160;Frame fr; &#160;&#160;GLCanvas canvas; &#160;&#160; &#160;&#160;public JOGLAPP() { &#160;&#160;&#160;&#160;fr = new Frame(&#34;JOGLAPP&#34;); &#160;&#160;&#160;&#160;canvas = new GLCanvas(); &#160;&#160;&#160;&#160;canvas.addGLEventListener(this); [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a basic JOGL application:<br />
<span id="more-39"></span></p>
<p><pre><code>import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;

import com.sun.opengl.util.Animator;

public class JOGLAPP implements GLEventListener {
&nbsp;&nbsp;public static void main(String[] args) {
&nbsp;&nbsp;&nbsp;&nbsp;new JOGLAPP();
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;Frame fr;
&nbsp;&nbsp;GLCanvas canvas;
&nbsp;&nbsp;
&nbsp;&nbsp;public JOGLAPP() {
&nbsp;&nbsp;&nbsp;&nbsp;fr = new Frame(&quot;JOGLAPP&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;canvas = new GLCanvas();
&nbsp;&nbsp;&nbsp;&nbsp;canvas.addGLEventListener(this);
&nbsp;&nbsp;&nbsp;&nbsp;fr.add(canvas);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Animator anim = new Animator(canvas);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;fr.setSize(300,300);
&nbsp;&nbsp;&nbsp;&nbsp;fr.setVisible(true);
&nbsp;&nbsp;&nbsp;&nbsp;anim.start();
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;fr.addWindowListener(new WindowAdapter() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void windowClosing(WindowEvent e) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.windowClosing(e);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(0);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;@Override
&nbsp;&nbsp;public void init(GLAutoDrawable drawable) {
&nbsp;&nbsp;&nbsp;&nbsp;GL2 gl = drawable.getGL().getGL2();
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// init opengl here
&nbsp;&nbsp;}

&nbsp;&nbsp;@Override
&nbsp;&nbsp;public void display(GLAutoDrawable drawable) {
&nbsp;&nbsp;&nbsp;&nbsp;GL2 gl = drawable.getGL().getGL2();
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// draw things here
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;gl.glFinish();
&nbsp;&nbsp;}

&nbsp;&nbsp;@Override
&nbsp;&nbsp;public void dispose(GLAutoDrawable drawable) {
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;}

&nbsp;&nbsp;@Override
&nbsp;&nbsp;public void reshape(GLAutoDrawable drawable, int x, int y, int width,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int height) {
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;
}
</code></pre></p>



Share this article:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F&amp;partner=sociable" title="Print"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://blog.rickyc.org/feed/" title="RSS"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=JOGL%20Hello%20World&amp;body=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F" title="email"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F&amp;title=JOGL%20Hello%20World&amp;bodytext=Here%20is%20a%20basic%20JOGL%20application%3A%0D%0A%0D%0A%0D%0Aimport%20java.awt.Frame%3B%0D%0Aimport%20java.awt.event.WindowAdapter%3B%0D%0Aimport%20java.awt.event.WindowEvent%3B%0D%0A%0D%0Aimport%20javax.media.opengl.GL2%3B%0D%0Aimport%20javax.media.opengl.GLAutoDrawable%3B%0D%0Aimport%20javax.media.opengl.GLEventLis" title="Digg"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F&amp;title=JOGL%20Hello%20World&amp;notes=Here%20is%20a%20basic%20JOGL%20application%3A%0D%0A%0D%0A%0D%0Aimport%20java.awt.Frame%3B%0D%0Aimport%20java.awt.event.WindowAdapter%3B%0D%0Aimport%20java.awt.event.WindowEvent%3B%0D%0A%0D%0Aimport%20javax.media.opengl.GL2%3B%0D%0Aimport%20javax.media.opengl.GLAutoDrawable%3B%0D%0Aimport%20javax.media.opengl.GLEventLis" title="del.icio.us"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F&amp;t=JOGL%20Hello%20World" title="Facebook"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=JOGL%20Hello%20World%20-%20http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F" title="Twitter"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F&amp;title=JOGL%20Hello%20World" title="Live"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F07%2F16%2Fjogl-hello-world%2F&amp;title=JOGL%20Hello%20World" title="StumbleUpon"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.rickyc.org/2009/07/16/jogl-hello-world/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>C++ &#8211; Sleeping</title>
		<link>http://blog.rickyc.org/2009/01/29/c-sleeping/</link>
		<comments>http://blog.rickyc.org/2009/01/29/c-sleeping/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 05:26:13 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Code Snippets/Tricks]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[sleep]]></category>

		<guid isPermaLink="false">http://blog.rickyc.org/?p=17</guid>
		<description><![CDATA[I am currently using SDL_Delay function in my program, which sleeps for the specified number of milliseconds. But seeing as I&#8217;m trying to get rid of SDL, I have to find another cross-platform solution for implementing sleep. So I have to write a replacement function. I&#8217;m still figuring out what to call it, but here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently using SDL_Delay function in my program, which sleeps for the specified number of milliseconds. But seeing as I&#8217;m trying to get rid of SDL, I have to find another cross-platform solution for implementing sleep. So I have to write a replacement function. I&#8217;m still figuring out what to call it, but here&#8217;s the essentials of a cross-platform sleep.<span id="more-17"></span></p>
<p>First of all, do NOT just do a tight while loop. It may appear to pause for that much time, but if you watch the CPU usage for your program, a while-loop like that will use 100% CPU. That is quite unfriendly to people like me with laptops. Not to mention, a 100% utilized CPU can heat up pretty quickly; especially when on a processor like the Pentium 4 (yuck).</p>
<p>So Windows has this handy function inside the all-mighty &lt;Windows.h&gt; file, Sleep(). It takes one argument of how many milliseconds to sleep. This argument can be 0, in which case it yields to another thread for some small amount of time. Or, according to the MSDN documentation, &#8220;A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution.&#8221;</p>
<p>http://msdn.microsoft.com/en-us/library/ms686298(VS.85).aspx</p>
<p>Linux does something pretty different. Their sleep function is inside the include file &lt;unistd.h&gt;, which apparently is a file that contains &#8220;standard symbolic constants and types.&#8221; The function is usleep, and it takes the parameter of how many microseconds to sleep. That&#8217;s right, microseconds. As in, thousandths of milliseconds. So, take the number of milliseconds you want, multiply it by 1000, and give it to this function and your Linux processor will sleep that many milliseconds.</p>
<p>http://opengroup.org/onlinepubs/007908799/xsh/usleep.html</p>
<p>Macs, well, I don&#8217;t really know. Nor care. I don&#8217;t feel confident enough that I can contort to their differences enough to get my program running on their machines. Meh.</p>
<p>-Ricky</p>



Share this article:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F&amp;partner=sociable" title="Print"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://blog.rickyc.org/feed/" title="RSS"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=C%2B%2B%20-%20Sleeping&amp;body=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F" title="email"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F&amp;title=C%2B%2B%20-%20Sleeping&amp;bodytext=I%20am%20currently%20using%20SDL_Delay%20function%20in%20my%20program%2C%20which%20sleeps%20for%20the%20specified%20number%20of%20milliseconds.%20But%20seeing%20as%20I%27m%20trying%20to%20get%20rid%20of%20SDL%2C%20I%20have%20to%20find%20another%20cross-platform%20solution%20for%20implementing%20sleep.%20So%20I%20have%20to%20write%20a%20repl" title="Digg"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F&amp;title=C%2B%2B%20-%20Sleeping&amp;notes=I%20am%20currently%20using%20SDL_Delay%20function%20in%20my%20program%2C%20which%20sleeps%20for%20the%20specified%20number%20of%20milliseconds.%20But%20seeing%20as%20I%27m%20trying%20to%20get%20rid%20of%20SDL%2C%20I%20have%20to%20find%20another%20cross-platform%20solution%20for%20implementing%20sleep.%20So%20I%20have%20to%20write%20a%20repl" title="del.icio.us"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F&amp;t=C%2B%2B%20-%20Sleeping" title="Facebook"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=C%2B%2B%20-%20Sleeping%20-%20http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F" title="Twitter"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F&amp;title=C%2B%2B%20-%20Sleeping" title="Live"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.rickyc.org%2F2009%2F01%2F29%2Fc-sleeping%2F&amp;title=C%2B%2B%20-%20Sleeping" title="StumbleUpon"><img src="http://rickyc.org/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://blog.rickyc.org/2009/01/29/c-sleeping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

