Getting up and running with JOGL JOGL is Sun’s open sourced OpenGL binding for Java. It is actively supported by many developers with Sun’s newly established Java Gaming Group. With JOGL it is possible to finally be able to create (API supported) OpenGL games in Java. The only credible competing API is the LWJGL (Lightweight Java Game Library) which strives to be the Java gaming equivalent of DirectX.
Both libraries utilize a hefty amount of native code, but where LWJGL seeks to be a complete gaming solution - the Sun APIs (JOGL, JOAL, and JInput) allow you to mix and match what you need to create your solution. In addition, JOGL integrates cleanly with AWT and Swing components whereas LWJGL creates its own native window - defying any attempts to integrate it with a Java application.
This article deals specifically with getting JOGL installed on your machine and getting it to render a single cheesy triangle. As you will shortly discover, this takes little effort (unless you are unfamiliar with the OpenGL APIs). The first step required is to obtain the binaries that you will need in order to compile and run your applications. These pre-compiled binaries can be obtained from the project website file sharing area Project Files. Download the binaries for your platform (currently there are binaries available for OSX (Panther DP or greater), Linux, Solaris, and Windows. This pretty much covers all of the major platforms so I doubt you’ll find yourself trying to compile the library yourself.
Now that you have the binaries you will note that you hava a .jar file and a JNI library (.dll, .so, .jnilib). You will need to install the jogl.jar file in the classpath of your build environment in order to be able to compile an application with JOGL. Since many people these days are using IDEs like Eclipse, JBuilder, and IntelliJ - it is fairly straightforward to add the .jar file to your build. Follow the instructions for your specific build environment.
Next comes the slightly trickier part, the installation of the native library. You won’t need this in order to compile your application, but you will need it in order to run your application. Java developers usually don’t find themselves installing native libraries (for obvious reasons) so it usually escapes us as to how its done. Java loads native libraries from the directories listed in the java.library.path environment variable. Best to just print this out and put the native library into one of these directories. One of these directories is likely to be the extension (ext) directory of the JRE for your IDE. Unless you only want to run the application from inside the IDE, don’t install it here.
You can confirm this by creating a test program that does System.loadLibrary(“jogl”);. If the application throws an UnsatisfiedLinkException, the JRE running your application cannot find the native library. This isn’t too likely if you’ve installed it in one of the directories listed in java.library.path, but just in case - try again
Now that you have JOGL installed, you want to feed cool L33t geometry to your video card and have it do cool stuff. Well at the moment I want to feed myself so I tell you about that. Coming up next - actually understanding the API enough to be able to get something on the screen!