Setting up the Java stencil buffer

In OpenGL, the stencil buffer is used to mask pixels on the screen. However, if you notice that your stencil test is always passing (i.e. your stencil bits are always returns as zero), then you probably haven’t initialized the stencil bits.

This isn’t very well documented. It took a few days of searching to find it. In C, one would be using GLUT, so calling glutInitDisplayMode() would be he function to call that requests stencil bits. In Java, this is in the GLCapabilities object.

So, to request stencil bits, in your init() function put


GLCapabilities cap = new GLCapabilities();
cap.setStencilBits(8);
GLCanvas canvas = new GLCanvas(cap);


Basically, this initializes a new GLCapabilities object, and assigns it an 8-bit stencil buffer. Pass it into the GLCanvas as a parameter and you’re gold. 

One use for this buffer is to render shadow volumes:

 

Java’s forever loop

If you want to loop forever in Java, just type


for(;;) { }


Coincidentally, “for(;;)” and “forever” have the same number of characters…

Enabling Apache and PHP on a Mac 10.6 (Snow Leopard)

The Apache web server and PHP come preinstalled on Macs. All you have to do is enable it. Unfortunately, there is no “Enable Apache and PHP” switch, but the process is relatively simple.

To first enable PHP5, using a Terminal navigate to “/etc/apache2/”


cd /etc/apache2


and sudo open up the httpd.conf file using your editor of choice.

Next, find this line:


#LoadModule php5_module        libexec/apache2/libphp5.so


and uncomment it by removing the ‘#’. Save and close. Now PHP5 is enabled.

Next, we need to turn on the Apache web server (or reboot it if it’s already running). Open up System Preferences from the Apple menu. Click on Sharing. Under the list of options in the toolbar on the left, check (or uncheck-then check) the “Web Sharing” option. This will effectively activate the apache web server.

That’s it! Now open up a web browser and type http://localserver/ and it should give you a happy “It Works!” confirmation that Apache is up. Your home directory is located at http://localserver/~username and you can navigate to your websites and run PHP scripts.

Using scp on a directory/file with spaces

The protocol when copying/moving a file that has spaces in the filename in a terminal window is to use “\ “, or


cp ~/some\ directory/some\ thing.zip ~/destination/


Oddly enough, scp doesn’t employ the same protocol.  Instead, I’ve found that this works:


scp 'myname@location:"~/some directory/some thing.zip" ' ~/destination/


That is, wrap the entire call after scp in single quotes, and the path in double quotes

Or an easy solution: don’t put spaces in filenames or directories