Friday, March 30, 2007

Arrggg Linux + JOGL

Today, I was doing some work for my other subject "Enterprise Programming" which requires you to do everything on Linux. So while I was on Linux I thought I would attempt to get JOGL working with Netbeans, so I could do some development on it. I prefer to develop on Linux because I get to learn new skills and work with a new operating system, and also the look and feel of the OS is much more appealing to me than Windows. So I hunted down a heap of websites looking for a tutorial on how to install JOGL on a linux system, but I kept getting other people having the same problem and no one providing a solid solution. Every time I tried to compile some JOGL code it would tell me that it couldn't find the library files and cause an exception.

Some links I bookmarked:
Environment Variables
Hello World tutorial
JOGL forums
JOGL install tutorial


Arrggg!!! after about 2 hours of trying to get it to work with Netbeans, I installed Eclipse and tried to get it to work with that. NO SUCCESS BAH! I just cant figure out how this thing needs to be setup on Linx. I gave up and switched over to Windows.

I had installed Netbeans on Windows not long ago, just to get my PC ready for some coding when the time comes. I used the above hello world tutorial to test if JOGL was working on Windows and encountered the exact same problem that was happening on Linux, SIGH! I had looked at the JOGL install tutorial several times at this point, but I guess I just wasn't reading it properly because of my frustration, after reading it VERY carefully I discovered this section:

The .jar file jogl.jar needs to be in your CLASSPATH for compiling and running your code, while the native library file or files also need to be along the java.library.path at run time. You have two options of where to place these files.

Put the .jar in the lib/ext directory inside of the Java home directory, and the native libraries in an equivalent always-checked directory (such as jre/bin on Windows, or /Library/Java/Extensions on Mac OS X [note: this path has been changed since this article was first posted, on advice from Apple engineers. - ed). This approach gets you up and running quickly.


I soon discovered if I followed that to the letter it FINALLY worked! YAY. Ok, now that I have JOGL working on something I can finally start doing some test coding and try to get back into the swing of OpenGL.

I looked over the tutorials I did last semester in my OpenGL class and picked out one of the first ones we did, A spinning cube, and started coding it up in Java from C++. All of the OpenGL syntax is the same, and the translation between C++ and Java is very similar, so initially I thought this would be a fairly simple task to complete. I was wrong. I made use some of the demo code that is available from the JOGL website just so I could understand the layout and use of each section, to my surprise it was very similar to GLUT which is "Graphics Library Utility Toolkit" that simplifies the use of OpenGL, and also is supported on multiple platforms, so its commonly used on Linux for C++ OpenGL development. I reached the point were I was building the polygon method which would output all the vertex, normal and colour information to the screen for each side of the cube, because this function only made use of only OGL methods I just copied and pasted it in. It told me that all the functions inside the glBegin tags were causing an error, but to me they looked perfectly fine.


Example:

gl.glColor3fv(color[a]);

This means glColor3fv means its looking for 3 floats inside an array that specify the RGB values.

I was looking at the way I had defined the color array and the values inside it, to make sure everything was right according to Java's method of defining arrays and everything looked right, but it was still giving an error. After about an hour of doing everything I could think of, I finally discovered that the command was asking for two parameters, not just one. It was looking for an offset variable, which I have no idea what its use would be but if I was to take a guess it would have to be something like an offset value for the start off the array, or something similar to that. Frustrated at how long it took me to get this far I had to step away and thought I'll leave it till tomorrow and start fresh in the morning.

No comments: