This getting started-tutorial is intended for JOGL users that are mere beginners. It helps to setup a recent JOGL installation in Eclipse on Windows. There is a video-walk-through further down the post, in case you dont feel like reading.
First you need to download JOGL. This is actually more difficult than it sounds because the precompiled binary packages are a bit hidden in the new project site. Fortunately, I figured out where you can download recent JOGL binaries.
For this tutorial, I am using
- jogl-b633-2012-01-23_20-37-13, and
- gluegen-b480-2012-01-23_16-49-04.
This is how your project setup should look like:
So one you got the binaries, unpack the ZIP file somewhere. You will notice the jar folder with a number of JAR files. All you need is in that jar folder, because the DLL binaries are included in the JARs.
Create a new eclipse project (name doesnt matter) and add the following JARs on the classpath:
- gluegen-rt-natives-windows-amd64.jar
- gluegen-rt.jar
- jogl-all-natives-windows-amd64.jar
- gluegen-rt.jar
These files are the native part of the OpenGL binding and are linked via Java Native Interface (JNI). Since the DLLs are precompiled as part of the JAR files, you are almost ready to go.
Once you got that set up, create a package de.schabby.jogl.helloworld and copypaste the following two classes in the newly created package.
package de.schabby.jogl.helloworld; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; public class HelloWorld { public static void main(String[] args) { // setup OpenGL Version 2 GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabilities capabilities = new GLCapabilities(profile); // The canvas is the widget that's drawn in the JFrame GLCanvas glcanvas = new GLCanvas(capabilities); glcanvas.addGLEventListener(new Renderer()); glcanvas.setSize( 300, 300 ); JFrame frame = new JFrame( "Hello World" ); frame.getContentPane().add( glcanvas); // shutdown the program on windows close event frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); frame.setSize( frame.getContentPane().getPreferredSize() ); frame.setVisible( true ); } } |
The
package de.schabby.jogl.helloworld; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.glu.GLU; class Renderer implements GLEventListener { private GLU glu = new GLU(); public void display(GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(-1.5f, 0.0f, -6.0f); gl.glBegin(GL2.GL_TRIANGLES); gl.glVertex3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glEnd(); gl.glTranslatef(3.0f, 0.0f, 0.0f); gl.glBegin(GL2.GL_QUADS); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glEnd(); gl.glFlush(); } public void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged, boolean deviceChanged) { System.out.println("displayChanged called"); } public void init(GLAutoDrawable gLDrawable) { System.out.println("init() called"); GL2 gl = gLDrawable.getGL().getGL2(); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL2.GL_FLAT); } public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) { System.out.println("reshape() called: x = "+x+", y = "+y+", width = "+width+", height = "+height); final GL2 gl = gLDrawable.getGL().getGL2(); if (height <= 0) // avoid a divide by zero error! { height = 1; } final float h = (float) width / (float) height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); } public void dispose(GLAutoDrawable arg0) { System.out.println("dispose() called"); } } |
By right-clicking on the main() method and chosing "run as application", Eclipse will execute the program. You should see something like this:
For the lazy, I provide a video-walkthough.
Common problems and solutions:
- If you get Can't load AMD 64-bit .dll on a IA 32-bit platform, then you are using an 64bit DLL (eg. gluegen-rt.dee) with an JRE that is 32bit. In most cases you can just switch to a 64bit JRE if you are running a 64bit system. Make sure that Eclipse is using the right JRE when you execute the code.
- If you get no gluegen-rt in java.library.path, then you may need to add gluegen-rt-natives-windows-amd64.jar to you classpath.
- If you get no nativewindow_awt in java.library.path, then you may need to add jogl-all-natives-windows-amd64.jar to you classpath.
That's it so far. Please let me know if you have questions or comments.


thanks a lot .非常谢谢
Hi are the import javax.media.opengl.awt.GLCanvas; standand jogl imports or are they showing its from the internet
There is a JSR on OpenGL/JoGL so I guess it made its way into the giant library by now, but I usually pick the most current binaries from the Jogle project site. You find the URL on my previous post: http://schabby.de/jogl-download/
I hope this answers your question?
I am having linker errors ( I have a 64bit windows 7 os, but both JVM and eclipse are 32bit so I am using JOGL 32 bit too) for some reason it says that it can't link the native windows 32 I placed all four dlls in the class path. here is a pic of the error http://img259.imageshack.us/img259/2051/97707781.png
Found how to run the program after days of surfing the net.
ok, I will explain how I managed to run it and set up JOGL at the same time. https://sites.google.com/site/justinscsstuff/jogl-tutorial-1. shows how to create your own user library; once this is done I had some trouble running the dlls which I fixed by placing them in the directory of the project I was working on.
Your example is wrong, you should never have "height" set to zero. If it happens, it means that the height of your canvas is 0. Moreover, your example won't work with the debug pipeline of JOGL 2.0, a GLException will be thrown very early.
Hi Julien, thanks for your post! I will correct my example as soon as i get the chance.
Best Regards!
Johannes
Thanks - I've tried setting up JOGL so many times, and this is the only way that has worked!
Hi Shura, cool, I am glad it helped
Johannes
Instead of adding a WindowListener for exiting the application, consider using
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
as a shortcut instead.
AWESOME tutorial, for me was really hard to find a decent one.
Thanks a lot
Hi,
By chance, do you also have an example how to run a jogl program as a java applet ?
Thanks
Hi!
I am afraid I dont
I never really put too much though in applets to be honest. WebGL is about to win the openGL-in-Browsers race from my point of view.
Hello.,
Thanks for the post., it helped me a lot., but i faced a problem while adding a jar file in eclipse. You have mentioned about adding the following jar files.,
1. jogl.all.jar
2. nativewindow.all.jar
3. gluegen-rt.jar
I could not find them on my computer, I downloaded the latest zip file from the link you have provided in your post.,
http://schabby.de/jogl-download/
I have downloaded the file named "jogl-2.0-b610-20111226-windows-i586.7z" under the link " jogl-b610-2011-12-26_00-30-55" dated 26-12-2011. unzipped the file., but i could not find all the jar files mentioned above. I could just find "jogl.all.jar". Hope you'll help me with this.
Thanks,
Yogesh.
If you get the error
"Can't load IA 32-bit .dll on a AMD 64-bit platform"
you downladed the 32-bit binaries, not the 64bit binaries.
I tried the hello world tutorial and it will work when I run it from eclipse, however when i close the window (click the x) it still leaves and instance of javaw.exe running in the task manager. I have to manually end the process all the time. Any ideas whats causing this?
Hi, the window is independent from the OS process. So closing the window does not terminate the VM. I will enhance the example to shut down the VM once the user closes the window.
Thanks for pointing me at this!!
Johannes
Hi, thank you very much for the video. Was working on similar project and couldn't execute it for a long time, found your blog on the right time. Truly life saving, keep up the good work.
Verdammt gute Arbeit!
Ich danke vielmals!
Hi, thank you for this post. it helped me. But i tried to change frame's background color as frame.setBackground(Color.blue).it doesn't work.
thank you..
Hi Ezra, you are trying to set the background of the Swing Component, which is not part of OpenGL. The command you are looking for is gl.glClearColor(...). I hope this helps, Johannes
ok, thank you ..
Hi,
I have download and do all the stuff that you have said in the video of JOGL in Eclipse ,And after that when i run your first program 'HelloWorld' following error is coming.
Can you please help me out? THX
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The type javax.media.nativewindow.Capabilities cannot be resolved. It is indirectly referenced from required .class files
at JOGLHW.HelloWorld.main(HelloWorld.java:21)
Hi Hardik, this is an interesting problem. Does your code completely compile? Are you sure, that you got all necessary libraries added to your classpath? If yes, do you have additional depenencies on the system, such as additional libraries that are part of your project? What JDK are you using? I myself used JDK 6 64bit.
The problem appears to me, as if your current classpath does not contain the necessary javax.media.* stuff. What OS are you using?
Cheers,
Johannes
Hi schabby, i use 64-bit wnidows 7 OS. and also my code is not compile. There is error coming in line 'GLCanvas glcanvas = new GLCanvas(capabilities);' saying that 'the type javax.media.nativwindow.Capabilites cannot be resolved . it is indirectly refrenced from required .class files'
Thanks! Afer a dozen non-working tutorials (even the examples on the JOGL and Eclipse pages aren't working properly...) finally one that works
Hi i copied and pasted your code exactly as you said but im being thrown an error
Exception in thread "main" java.lang.IllegalArgumentException: Shared Drawable is null
Exception in thread "main" java.lang.IllegalArgumentException: Shared Drawable is null
at jogamp.opengl.windows.wgl.WindowsWGLGraphicsConfigurationFactory.preselectGraphicsConfiguration(WindowsWGLGraphicsConfigurationFactory.java:239)
at jogamp.opengl.windows.wgl.WindowsWGLGraphicsConfiguration.preselectGraphicsConfiguration(WindowsWGLGraphicsConfiguration.java:151)
at jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(WindowsAWTWGLGraphicsConfigurationFactory.java:128)
at javax.media.nativewindow.GraphicsConfigurationFactory.chooseGraphicsConfiguration(GraphicsConfigurationFactory.java:278)
at javax.media.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:955)
at javax.media.opengl.awt.GLCanvas.addNotify(GLCanvas.java:509)
at java.awt.Container.addNotify(Unknown Source)
at java.awt.Window.addNotify(Unknown Source)
at java.awt.Frame.addNotify(Unknown Source)
at java.awt.Window.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
thanx dude.. it was a gr8 help..keep on awesome work!!
I think it should actually be Renderer.java not Render.java for the second file. Anyways, thanks for all the help.
Thanks! I could not figure out how to install this library correctly (tried it two days ago and gave up after two hours), but thanks to your tutorial I did it in a few minutes!
Hello
I have a problem.
Although I did exactly same as the tutorial, even i watched the video. Even i tried other tutorial.But all of my try, i got that error everytime.
When i click to run, a error box display and "A Java Exception has occurred."
And i see that errors in consol
Exception in thread "main" java.lang.NoClassDefFoundError: com/jogamp/common/type/WriteCloneable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
...
Even i uninstalled jdk&jre and i download last version and install. I am using eclipse, Windows 7 home premium 64 bit.
stackover link: http://stackoverflow.com/questions/11710076/jogl-opengl-writecloneable-in-eclipse
Hi!
hmm, my first bet is that there are the jogamp libraries missing. Could you tell me your _exact_ setup? What OS are you running? 32bit 64bit? What Java version are you using? Which download URL (ie. which version) did you pick? What native binaries are in your classpath?
I am pretty sure we will get it to work.
Cheers,
Johannes
I did something but i didn't understand exactly.
Now, i got this:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jogamp/common/jvm/JVMUtil
at javax.media.opengl.GLProfile.(GLProfile.java:1145)
at HelloWorld.main(HelloWorld.java:14)
Caused by: java.lang.ClassNotFoundException: com.jogamp.common.jvm.JVMUtil
...
I am using windows 7 64 bit.
I have jre 7.I download it few days ago.
jogl-b633-2012-01-23_20-37-13, gluegen-b480-2012-01-23_16-49-04
I download them(windows amd64)
Also i added only "gluegen-rt.dll"
Same as you did.
Hi Nafiz,
I just checked in my setup in which JAR you find the class com/jogamp/common/type/WriteCloneable. It is definitely in gluegen-rt.jar. So adding this JAR will solve that problem. And this is probably what you did until you got stuck with the second problem
So, as for the second problem (java.lang.NoClassDefFoundError: com/jogamp/common/jvm/JVMUtil), I can find this class in the package jogamp.common.jvm also in gluegen-rt.jat, however it is strange that this class is actually requested. I suspect, that your classpath contains other JARs that request this library. Therefore, I send you my eclipse project as a ZIP file via mail hoping that it will work for you.
Cheers,
Johannes
It's work finally.
Thank you Johannes.
Your solution is work!
If you get JVMUtil or WriteCloneable error with NoClassDefFoundError, you must copy that 4 library to java/jre/lib/ext folder.
감사합니다. Thank you.
I am starting with JOGL and was struggling to find where to get those jars... You saved my day! Thank you for your great post. I could easily setup and run your example. You really made it simple. Can't thank you enough for sharing this!
Simple and effective, as I like
Thanks a lot
Hi
Your video is overcomplicated. Please can you update it?
As a first step, you should use the proper JVM (according to your architecture, you should use a 64 bits one). Then, you won't need to extract the DLL, just do the same thing than in your video but you will see that it will simply work the very first time.
Your video gives the impression that JOGL 2.0 is not straightforward to install whereas we made some efforts to ease that. The latest release candidate can be downloaded on the main page, there is a link that points to this:
http://jogamp.org/deployment/jogamp-current/archive/jogamp-all-platforms.7z
Best regards.
@Nafiz Never copy JARs into java/jre/lib/ext, it can cause some version conflicts (further versions won't be detected if you put an obsolete JAR here). Rather find the obsolete JAR(s) on your system and remove them.
The gluegen-rt.jar is mentioned twice in the include list!
Thanks for taking the trouble to make this tutorial.
Great post and video, you save my life mate! hahaha
Thx soooo much!!! Gr8 Tutorial; saved me after hours of abysmal installation disasters
U DA MAN
PS I started out with the jar files containing windows-i586 in their name, since I have an Intel laptop, but the only jar files that worked were the ones with amd64
Thanks for the tutorial, works great. didn't even have to do the extra steps in the vid, for some reason.