How to: Getting started with JOGL

ok… how am I supposed to do that?

Take a look at the SimpleJOGL example some post above, and copy the reshape()-method to your SimpleEventListener class. Also the Animator should not be instantiated and started inside the init() callback. Chances are, that init() is called multiple times on e.g. window resize and you would instantiate and start multiple animators this way, which could lead to an application freeze. Again, take a look at the SimpleJOGL example.

yea, i tried it. it works … ;D thank you…

Hi, I’ve read this thread and googled around, but I’m having a problem getting JOGl to run in an Eclipse project. I’ve followed the instructions here:

http://www.geofx.com/html/OpenGL_Eclipse/OpenGL_Eclipse.html

to make a simple Eclipse RCP application with a single View that implements GLEventListener, and basically the project builds OK, but when I run it I get the following exception:

java.lang.NoClassDefFoundError: javax/media/opengl/GLEventListener

Now, I have a directory called “C:\jogl-1.1.1-windows-i586” which is an unzip of the jogl-1.1.1-windows-i586.zip, and so contains the JOGl dlls and jars, and I have included the gluegen-rt.jar and jogl.jar from here in my Eclipse project. As I say, Eclipse is happy with this and the project builds fine, and it can ‘see’ javax/media/opengl/GLEventListener, but it fails at runtime. I have tried adding “C:\jogl-1.1.1-windows-i586” and the “C:\jogl-1.1.1-windows-i586\lib” subdirectory to my Path environment variable, but I get the same error. Any help would be appreciated.

Right, I’ve solved this now. For anyone with a similar issue, here is my understanding of the situation:

To recap, I’m trying to get a minimal JOGL example working in an Eclipse RCP application. The application compiles fine, but craps out at runtime with “java.lang.NoClassDefFoundError: javax/media/opengl/GLEventListener”. This seems like typical classpath fun and games, so I fart around and set my CLASSPATH environment variable (I’m on Win XP) to include the world and his wife, but of course it still doesn’t work. I try putting all the JOGL crap in the “\jdk1.6.0_01\jre\lib\ext” directory. This not only doesn’t solve the problem, but now it won’t even build (Eclipse complains about Access Restriction on the JOGL stuff; great) - I know putting the JOGL stuff in here is naughty but I’m just trying to get it to work, so w/e.
What I didn’t realise is that Eclipse ignores the CLASSPATH variable, so messing around with that is a waste of time. My understanding was that if you included a JAR in the Project > Properties > Libraries > Add External Jars bit, then Eclipse would sort out the CLASSPATH stuff for you, and certainly it adds some stuff to its little .classpath file, but it doesn’t work at runtime, so there you go.
Anyway, I think this is some special wierdness of making an RCP application. I think you have to do Other Things to get the CLASSPATH sorted for external JARs in an Eclipse RCP application. Here’s what I did:

Start a clean RCP Plug-In project in Eclipse. Add a lib directory to it. Put the gluegen-rt.jar and jogl.jar in there. Right-click on them in Eclipse and do ‘Add to Build Path’. Right-click your MANIFEST.MF file and do ‘Open With’ > ‘Plug-in Manifest Editor’. In the Manifest Editor select the Runtime tab. On there, under the Classpath bit click ‘Add…’, and select your lib/gluegen-rt.jar and lib/jogl.jar. That’s it really. This is basically following the steps here:

http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg06980.html

To see some JOGL stuff, add a View and if you use the code from here it should work:

http://www.geofx.com/html/OpenGL_Eclipse/OpenGL_Eclipse.html

Hope this is helpful to someone.

I’m getting an error similar to the one listed a couple of posts above. I’ve double-checked and there is only one instance of the gluegen-rt.jar file on my system and it is in the same directory as my jogl.jar file (which Java is finding correctly).

Here is the command I’m running and here is the error:


c:\JOGL\Examples>java -Djava.library.path=c:\jogl\native -classpath c:\jogl\jogl.jar;. SimpleJOGL

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/gluegen/runtime/DynamicLookupHelper
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java:106)
        at javax.media.opengl.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:520)
        at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:131)
        at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:90)
        at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:83)
        at SimpleJOGL.main(SimpleJogl.java:23)
Caused by: java.lang.ClassNotFoundException: com.sun.gluegen.runtime.DynamicLookupHelper
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 32 more

you forgot to add gluegen-rt.jar to the classpath.
c:\JOGL\Examples>java -Djava.library.path=c:\jogl\native -classpath c:\jogl\jogl.jar;c:\jogl\gluegen-rt.jar;. SimpleJOGL

That would be it. Thanks! Isn’t there a better way to set that somehow? At least now I can play around with stuff. Thanks again.

You could add the jars to the CLASSPATH environment variable and the directories with the native libraries to the PATH. Oh and also read the “Jogl Users Guide” :wink:

It seems there are some changes in the API. I updated the code.



import com.sun.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.awt.GLCanvas;


/**
 * SimpleJOGL2.java 

 * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */
public class SimpleJOGL implements GLEventListener {

    public static void main(String[] args) {
        Frame frame = new Frame("Simple JOGL Application");
        GLCanvas canvas = new GLCanvas();

        canvas.addGLEventListener(new SimpleJOGL());
        frame.add(canvas);
        frame.setSize(640, 480);
        final Animator animator = new Animator(canvas);
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
                // make sure the call to Animator.stop() completes before
                // exiting
                new Thread(new Runnable() {

                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        // Center frame
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();
    }

    public void init(GLAutoDrawable drawable) {
        // Use debug pipeline
        // drawable.setGL(new DebugGL(drawable.getGL()));

       GL2 gl = drawable.getGL().getGL2(); 
        System.err.println("INIT GL IS: " + gl.getClass().getName());

        // Enable VSync
        gl.setSwapInterval(1);

        // Setup the drawing area and shading mode
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glShadeModel(GL2.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL2 gl = drawable.getGL().getGL2(); 
        GLU glu = new GLU();

        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 display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2(); 

        // Clear the drawing area
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        // Reset the current matrix to the "identity"
        gl.glLoadIdentity();

        // Move the "drawing cursor" around
        gl.glTranslatef(-1.5f, 0.0f, -6.0f);

        // Drawing Using Triangles
        gl.glBegin(GL2.GL_TRIANGLES);
            gl.glColor3f(1.0f, 0.0f, 0.0f);    // Set the current drawing color to red
            gl.glVertex3f(0.0f, 1.0f, 0.0f);   // Top
            gl.glColor3f(0.0f, 1.0f, 0.0f);    // Set the current drawing color to green
            gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
            gl.glColor3f(0.0f, 0.0f, 1.0f);    // Set the current drawing color to blue
            gl.glVertex3f(1.0f, -1.0f, 0.0f);  // Bottom Right
        // Finished Drawing The Triangle
        gl.glEnd();

        // Move the "drawing cursor" to another position
        gl.glTranslatef(3.0f, 0.0f, 0.0f);
        // Draw A Quad
        gl.glBegin(GL2.GL_QUADS);
            gl.glColor3f(0.5f, 0.5f, 1.0f);    // Set the current drawing color to light blue
            gl.glVertex3f(-1.0f, 1.0f, 0.0f);  // Top Left
            gl.glVertex3f(1.0f, 1.0f, 0.0f);   // Top Right
            gl.glVertex3f(1.0f, -1.0f, 0.0f);  // Bottom Right
            gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
        // Done Drawing The Quad
        gl.glEnd();

        // Flush all drawing operations to the graphics card
        gl.glFlush();
    }

     public void dispose(GLAutoDrawable drawable){}
    
    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }
}


(the whole thread is deprecated regarding JOGL2, its an introduction to JOGL1. Maybe a moderator should detach the thread from being the first in this forum)

I have a problem: I can’t find the jogl.jar file! I (finally) suceeded in building Jogl, and in the jogl\build folder i have 3 other folders:
jogl, nativewindow, newt.
In the jogl folder, I have a whole list of jogl.XXX.jar files but never the simple jogl.jar file…
Because of this, I cannot run the simple System.loadLibrary(“jogl”); command…

Any advice?

Im sorry but i am horribly confused about creating and binding a context to GL! What exactly is the recommended Window ToolKit? In the FAQ you can read, awt and swing are bad but i cant get the native Window toolkit running. http://kenai.com/projects/jogl/forums/forum/topics/1691-How-to-create-a-native-window- <- i found this here where you can see how to create a native window. But i have no idea how to get a GLDrawable out of the window in order to add it to an Animator. If this question doesnt belong here please forgive me! Since this is my problem with the “getting started” part.

hey people,

i wanna use new jogl package (i mean javax.media.opengl.…), but i get errors :’(

where i can download the latest release??

thanks :slight_smile:

you can download it from here. :slight_smile:
http://download.java.net/media/jogl/builds/archive/

Hello :),
I’m developing the applet http://analisegrafica.net/applet.html.
Some people report Java can’t find the Main class, but it works on my Windows and Linux environments.
I checked browser/Java/SO versions and all was equal to mine. What’s wrong?
Should I use JOGL 2? Is there a specific Topic about?
Is there a Netbeans plugin for JOGL 2?

Thanks :persecutioncomplex:

No, you should download it from here:
http://jogamp.org/deployment/archive/rc/

In the future instead of resurrecting an old thread, just make a new topic with your question. :slight_smile:

LOL

What happened to going green? We need to recycle, man!