JOGL: helping me to make sense of spatial data
2009-Aug-24, Monday 11:27 amJOGL. Java binding for OpenGL. The question I get asked is, why JOGL? I haven't looked into Java3D in years, but back when I was making this fairly unimportant decision two factors weighed heavily. Firstly, I already knew a bit of OpenGL from my C-based graphics course. Secondly, the OpenGL standard is used in a variety of different languages, once you know the basics in one you can quickly pick up another, which makes the skillset much more portable. And, as we're already seeing, Java is falling out of favour. So the next question becomes, why not just use C? The answer is also two-fold. Firstly, I know Java much better than C, I'm not planning a major project here, just a utility. Secondly, and this one is very close to my heart, it's more portable. When optimisation starts meaning more to me than portability I'll return to my beloved C, but that's not today. No, this project is very simple, and differences of microseconds aren't going to have a large impact. What is the project?
Data-logging and visualisation. Now, before your eyes glaze over hear me out. While working on my Arduino Lilypad gloves project I hit a bit of a block. I need to use the data I'm getting from the 3-axes accelerometer and translate that into RGB colours. Only I can't make sense of the data coming from the accelerometer, so my attempts to map the data to colours left all the colours looking the same. I reckon the problem is one of two-halfs. Understanding the accelerometer data, and truly understanding the RGB colour-mix. So first off, I need a way to plot the 3-axes of accelerometer data, and literally see what's going on. That's where JOGL comes in. I'm going to write a small utility to grab the data from the serial monitor, and draw it in a 3-D graph. It will also need helpful things like an arcball environment to enable me to grab the graph and rotate it easily. But otherwise quite simple.
(Sidenote: Actually, my final year project in college was something similar, only vastly more complicated and involved graphing evolving data-sets and helping people see the changes no matter how minute. I took a 2.5D approach, where I had time slices or snapshots of time arranged in a 3D space. And since leaving college I haven't coded anything for myself (bar one failed attempt at a C-based 2D visualisation which I wanted to do completely from scratch, foolish idea that), so I hope this will get me back coding for fun.)
Today I wish to tell you how to set up JOGL on your machine (if your machine is running Fedora Linux or Windows XP that is), as the instructions I found when looking into this are a few years out of date. I hope it's not because no-one is using JOGL anymore, but rather that it is so simple to set-up that few people feel there is a need for a tutorial.
Step one: Get Java.
Make sure you have the Sun Java Development Kit on your machine. Personally I'm fine with using Java SE (Standard Edition), but get whatever you'll need. Things are simple for Windows users, just run the installer. But, if you're running Linux and used to the repository way of things you might want to read these two links. It's not difficult, when you know what you're doing.
- How to download and install. Including configuring your browser to use Java.
- How to configure your system. Including symbolic links, alternatives and setting which Java you want to use. It's a bit out of date as we're using Java 6 and Fedora 11 now, so if there are duplicate steps refer to the ones in the first link.
Step two: Get JOGL.
This is chiefly where the instructions I found were out of date. Once upon a time you needed to get two packages, the universal jars, and the platform dependant natives. This lead me to some time searching for the non-existent second package. The packages have been rearranged and now the one package on the download site has everything you need. (To navigate, go to https://jogl.dev.java.net/, click on the 'Documents and files' link on the left-hand side, and click on 'Release Builds' for your year. Click on the sub folder, then select the right binary for your platform. Demo and documentation is also available here, so make sure you pick the right one.)
Step three: Install JOGL.
Save the binary zip to wherever you like, and extract the contents. You should see two jars, and four natives in a lib folder.
For Windows: Right-click the 'My Computer' icon on the desktop or start menu. Select 'Properties', then the 'Advanced' tab. Press the 'Environment Variables' button. In the lower list of the window that pops up, the 'System variables', find the PATH variable, and Edit it. At the end of the list (don't delete anything, add a semi-colon (;) to separate from the previous item in the list if it's not there already) add the path to your JOGL lib folder. Click OK. And then add the path to the CLASSPATH variable as well. (If you don't have this variable already create a New one. Call it CLASSPATH, and give it an initial value of .; and the path to your JOGL lib folder. The . implies that anything in the current working directory is to be used.) Click OK, and keeping pressing until the frames are closed.
For Linux: You'll have to edit your .bashrc file and add some variables, unless you want to set it each time you compile and run your program that is. I like VIM*, but use whatever you want. You may have trouble seeing the file graphically, as any file starting with a . is hidden. To see hidden files in the terminal type: ls -a
Go to you home directory (cd /home/username), and open the file to edit (vim .bashrc). Add lines similar to the following, changed to reflect the location you choose:
export CLASSPATH=${CLASSPATH}:/usr/lib/jogl-1.1.1-linux-i586/lib/jogl.jar
export CLASSPATH=${CLASSPATH}:/usr/lib/jogl-1.1.1-linux-i586/lib/gluegen-rt.jar
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/jogl-1.1.1-linux-i586/lib
Save and quit.
*VIM basics:
Press i to start editing the file. When done press Esc to leave editing mode. :w will save the file. :q will quit back to the terminal. :q! will quit without saving your changes, and :wq will quit saving them.
Step four: Get an IDE.
I'm really only familiar with Eclipse and NetBeans, and both are fine. There is a JOGL plugin for NetBeans, but so far I've yet to see it actually do anything. I'll leave you to getting/using your own IDEs, just make sure it handles Java.
Step five: Create a JOGL project.
This is just like creating any Java project. Once created, right-click the project and select 'Properties'.
In NetBeans: Click on the 'Libraries' branch, and then the 'Add JAR/Folder' button.
In Eclipse: Click on the 'Java Build Path' branch, and then the 'Libraries' tab. Now use the 'Add External JARs...' button.
Add the two jars in the JOGL lib folder. Now you're ready to throw in some code and see if it all works. There's a few 'Hello World' style tutorials for JOGL going around, but I think one of the simplest is from OpenGL.J3D.org. Grab the zip, and throw the source code in. (Watch out for package names.) Then run. Hopefully everything will work and you'll see a multi-coloured triangle in a black frame. (Note: there was no code added to handle your pressing the red x, so to stop it use the IDEs stop button.)
And that's it, you're ready to use JOGL for fancy 3D graphics. And I'm ready to make a start on my utility project. Have fun!
Data-logging and visualisation. Now, before your eyes glaze over hear me out. While working on my Arduino Lilypad gloves project I hit a bit of a block. I need to use the data I'm getting from the 3-axes accelerometer and translate that into RGB colours. Only I can't make sense of the data coming from the accelerometer, so my attempts to map the data to colours left all the colours looking the same. I reckon the problem is one of two-halfs. Understanding the accelerometer data, and truly understanding the RGB colour-mix. So first off, I need a way to plot the 3-axes of accelerometer data, and literally see what's going on. That's where JOGL comes in. I'm going to write a small utility to grab the data from the serial monitor, and draw it in a 3-D graph. It will also need helpful things like an arcball environment to enable me to grab the graph and rotate it easily. But otherwise quite simple.
(Sidenote: Actually, my final year project in college was something similar, only vastly more complicated and involved graphing evolving data-sets and helping people see the changes no matter how minute. I took a 2.5D approach, where I had time slices or snapshots of time arranged in a 3D space. And since leaving college I haven't coded anything for myself (bar one failed attempt at a C-based 2D visualisation which I wanted to do completely from scratch, foolish idea that), so I hope this will get me back coding for fun.)
Today I wish to tell you how to set up JOGL on your machine (if your machine is running Fedora Linux or Windows XP that is), as the instructions I found when looking into this are a few years out of date. I hope it's not because no-one is using JOGL anymore, but rather that it is so simple to set-up that few people feel there is a need for a tutorial.
Step one: Get Java.
Make sure you have the Sun Java Development Kit on your machine. Personally I'm fine with using Java SE (Standard Edition), but get whatever you'll need. Things are simple for Windows users, just run the installer. But, if you're running Linux and used to the repository way of things you might want to read these two links. It's not difficult, when you know what you're doing.
- How to download and install. Including configuring your browser to use Java.
- How to configure your system. Including symbolic links, alternatives and setting which Java you want to use. It's a bit out of date as we're using Java 6 and Fedora 11 now, so if there are duplicate steps refer to the ones in the first link.
Step two: Get JOGL.
This is chiefly where the instructions I found were out of date. Once upon a time you needed to get two packages, the universal jars, and the platform dependant natives. This lead me to some time searching for the non-existent second package. The packages have been rearranged and now the one package on the download site has everything you need. (To navigate, go to https://jogl.dev.java.net/, click on the 'Documents and files' link on the left-hand side, and click on 'Release Builds' for your year. Click on the sub folder, then select the right binary for your platform. Demo and documentation is also available here, so make sure you pick the right one.)
Step three: Install JOGL.
Save the binary zip to wherever you like, and extract the contents. You should see two jars, and four natives in a lib folder.
For Windows: Right-click the 'My Computer' icon on the desktop or start menu. Select 'Properties', then the 'Advanced' tab. Press the 'Environment Variables' button. In the lower list of the window that pops up, the 'System variables', find the PATH variable, and Edit it. At the end of the list (don't delete anything, add a semi-colon (;) to separate from the previous item in the list if it's not there already) add the path to your JOGL lib folder. Click OK. And then add the path to the CLASSPATH variable as well. (If you don't have this variable already create a New one. Call it CLASSPATH, and give it an initial value of .; and the path to your JOGL lib folder. The . implies that anything in the current working directory is to be used.) Click OK, and keeping pressing until the frames are closed.
For Linux: You'll have to edit your .bashrc file and add some variables, unless you want to set it each time you compile and run your program that is. I like VIM*, but use whatever you want. You may have trouble seeing the file graphically, as any file starting with a . is hidden. To see hidden files in the terminal type: ls -a
Go to you home directory (cd /home/username), and open the file to edit (vim .bashrc). Add lines similar to the following, changed to reflect the location you choose:
export CLASSPATH=${CLASSPATH}:/usr/lib/jogl-1.1.1-linux-i586/lib/jogl.jar
export CLASSPATH=${CLASSPATH}:/usr/lib/jogl-1.1.1-linux-i586/lib/gluegen-rt.jar
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/jogl-1.1.1-linux-i586/lib
Save and quit.
*VIM basics:
Press i to start editing the file. When done press Esc to leave editing mode. :w will save the file. :q will quit back to the terminal. :q! will quit without saving your changes, and :wq will quit saving them.
Step four: Get an IDE.
I'm really only familiar with Eclipse and NetBeans, and both are fine. There is a JOGL plugin for NetBeans, but so far I've yet to see it actually do anything. I'll leave you to getting/using your own IDEs, just make sure it handles Java.
Step five: Create a JOGL project.
This is just like creating any Java project. Once created, right-click the project and select 'Properties'.
In NetBeans: Click on the 'Libraries' branch, and then the 'Add JAR/Folder' button.
In Eclipse: Click on the 'Java Build Path' branch, and then the 'Libraries' tab. Now use the 'Add External JARs...' button.
Add the two jars in the JOGL lib folder. Now you're ready to throw in some code and see if it all works. There's a few 'Hello World' style tutorials for JOGL going around, but I think one of the simplest is from OpenGL.J3D.org. Grab the zip, and throw the source code in. (Watch out for package names.) Then run. Hopefully everything will work and you'll see a multi-coloured triangle in a black frame. (Note: there was no code added to handle your pressing the red x, so to stop it use the IDEs stop button.)
And that's it, you're ready to use JOGL for fancy 3D graphics. And I'm ready to make a start on my utility project. Have fun!