How to: Getting started with JOGL

First of all - GREAT tutorial/updates. I’ve just finished a course on OpenGL for ANSI-C and this changeover is brill…

kfaissal - I’m running a dual-core intel 32bit with Vista and JoGL works fine! Chews up a hellavalot of processing tho’ (just for a simple triangle) using jogl-1.1.1-rc1-windows-i586 bins (I’m assuming those are old - although I only downloaded them a few months ago). Make sure you use javax.media.opengl.* tho’. Having said that I’ve got all the dlls and jars installed in my jre, which I understand may cause clashed for you. Good luck figuring that out!

xxS

Looks like it is falling back to software rendering. There are some issues on Vista but imho all related to drivers.

I have written a more up to date tutorial. introducing basically the same concepts.

http://cgi.cse.unsw.edu.au/~ekjo014/index.php?n=Programming.JOGLTutorial

While your tutorial is good, both links you supply for installing JOGL suggest to copy the jogl.jar to the lib/ext directory, which is strongly discouraged, since it breaks webstart installation. This can lead to downloaded applications not working on the machine! Just copy the jogl jars somewhere on your system (e.g. C:\development\jogl) and set the CLASSPATH and PATH (LD_LIBRARY_PATH on Linux) variables accordingly.

yes that is true. my tute is meant mainnly for n00bs, and the installation section is included only as a courtesy

yes, I do understand that, but especially noobs would have problems debugging this situation, if they try to run a webstart app depending on a different jogl version.

yeah true. i’ll update when i get the chance.

I struggled to get JOGL running correctly as many above people describe. But Netbeans saved me. If you use
the NetBeans IDE version 6.0 or later, it comes with the openGL pack, and all that JOGL stuff is done for you.
You don’t even have to know what the word “classpath” means. In addition, NetBeans provides a dozen openGL
examples, and provides them in the best possible way, i.e., as a project in the IDE that you can select. It makes
it so easy to learn, because, for example, you can select the openGL gears demo, run it, modify it, run it again, etc.
Kudos to netbeans!

I’m struggling now with the same thing that Jason Boyd described, how to deploy a Java-openGL project on the
internet. I have deployed many applets, but cannot figure out how to write an applet that uses openGL. I have written
many openGL applications, but haven’t been able to deploy any of them successfully. Does anyone know of a
tutorial or examples that allows us to put an Java-openGL program (either applet or application) on the web so that
someone else can run it as they now can run a Java applet (without openGL)?

Hey people. I just downloaded the JOGL files to my HD. So, all I have to do is include the .jar in my app? I don’t have admin access on my computer so I can’t install applications… :’(

For compiling JOGL based apps, you need to specify the needed jars on
the classpath:

javac -classpath path/to/jogl.jar:path/to/gluegen-rt.jar
-sourcepath app/sources -d app/classes

and run it via

java -Djava.library.path=path/to/jogl/natives:path/to/gluegen/natives
-classpath path/to/jogl.jar:path/to/gluegen-rt.jar:app/classes
org.yourorg.YourApp

Replace : with ; when using windows.

You can put the above in a .sh(unix) or .bat(windows) file.

This example is terribly out of date. There is no longer a

        GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( new GLCapabilities() );

call.

Here is a working example:


package org.yourorghere;

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



/**
 * SimpleJOGL.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()));

        GL gl = drawable.getGL();
        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(GL.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) {
        GL gl = drawable.getGL();
        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(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(45.0f, h, 1.0, 20.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();

        // Clear the drawing area
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.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(GL.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(GL.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 displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }
}

When I try the code above, I get the following error:

Exception in thread “main” java.lang.UnsatisfiedLinkError: no jogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at com.sun.opengl.impl.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:189)
at com.sun.opengl.impl.NativeLibLoader.access$000(NativeLibLoader.java:49)
at com.sun.opengl.impl.NativeLibLoader$DefaultAction.loadLibrary(NativeLibLoader.java:80)
at com.sun.opengl.impl.NativeLibLoader.loadLibrary(NativeLibLoader.java:103)
at com.sun.opengl.impl.NativeLibLoader.access$200(NativeLibLoader.java:49)
at com.sun.opengl.impl.NativeLibLoader$1.run(NativeLibLoader.java:111)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.loadCore(NativeLibLoader.java:109)
at com.sun.opengl.impl.windows.WindowsGLDrawableFactory.(WindowsGLDrawableFactory.java:60)
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.(GLCanvas.java:131)
at javax.media.opengl.GLCanvas.(GLCanvas.java:90)
at javax.media.opengl.GLCanvas.(GLCanvas.java:83)
at joglscape.SimpleJOGL.main(SimpleJOGL.java:25)

You have to start your program with configured native libraries. This means you have to add


-Djava.library.path=<path/to/jogl/natives/folder>:<path/to/gluegen-rt/natives/folder>

to the command line starting your app. If you use an IDE add this to the JVM-ARGS parameter in your IDEs run configuration.

If you use NetBeans, you can try our OpenGL Pack.

If you haven’t already, read the JOGL User’s Guide. It also describes an alternative configuration option that involves modifying your systems CLASSPATH and PATH/LD_LIBRARY_PATH environment variables, which might be less cumbersome if you use the commandline instead of an IDE.

I finally got it working, turned out while trying to install about 5000 times over and over I had left some old jogl.jar files in another of my classpath so I still got the unlinked-blabla-error. When I removed them everything worked :slight_smile:

Btw I think this should be included somewhere in this topic, maybe in the first post :stuck_out_tongue:
http://fivedots.coe.psu.ac.th/~ad/jg2/

It’s the best tutorial I have found by far after several hours of searching.

Exception in thread “main” java.lang.NoClassDefFoundError: com/sun/gluegen/runtime/DynamicLookupHelper
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$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
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$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java:106)
at javax.media.opengl.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:520)
at javax.media.opengl.GLCanvas.(GLCanvas.java:131)
at javax.media.opengl.GLCanvas.(GLCanvas.java:90)
at javax.media.opengl.GLCanvas.(GLCanvas.java:83)
at SimpleJOGL.main(SimpleJOGL.java:25)
Caused by: java.lang.ClassNotFoundException: com.sun.gluegen.runtime.DynamicLookupHelper
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
… 32 more

What happened? What should I do?

This usually happens if you either don’t have the gluegen-rt.jar on your classpath or you have a conflicting jogl/gluegen installation somewhere in your system directories like jre/ext, C:\windows\system32 etc. Make sure you only have one installation of jogl/gluegen on your system in a dedicated (non-system) directory (e.g. “C:\development\jogl”, “/home//development/jogl” or something like that) and either setup your environment variables accordingly or start your app with the right commanline options (see above)

Hi. I am a beginner in JOGL and I was trying out some tutorials I got from nehe.gamedev.net (for c / c++)…

I hit a snag when I was doing the 3d shapes tutorial, the tutorial says, that we need to move the drawing point to the loc (-1.5, 0, -6.0), using glTranslatef() func. I tried the same but I am getting just a black screen. I tried the code without changing the drawing point, i.e leaving it at its original place (0, 0, 0), then I could see a very big pyramid rotating. Here is the code. I am using eclipse, with the latest JRE and JOGL library. Can somebody please tell me, what I am doing wrong. :smiley: Thanks in advance.

import javax.media.opengl.*;
import com.sun.opengl.util.Animator;
import javax.media.opengl.GLEventListener;
import java.awt.*;
import java.awt.event.*;

class SimpleEventListener implements GLEventListener{
	
	float rt;
	Animator anim;
	
	public void init(GLAutoDrawable drawable){
		
		GL gl = drawable.getGL();
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
				
		rt=0.0f;
		anim= new Animator(drawable);
		anim.start();
		
	}
	public void display(GLAutoDrawable drawable){
		
		GL gl = drawable.getGL();
		
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
        gl.glLoadIdentity();
        
        gl.glTranslatef(-1.5f, 0.0f, -6.0f);
        gl.glRotatef(rt, 0.0f, 1.0f, 0.0f);
		
		gl.glBegin(GL.GL_TRIANGLES);
		
		gl.glColor3f(1.0f,0.0f,0.0f);			
		gl.glVertex3f( 0.0f, 1.0f, 0.0f);
		gl.glColor3f(0.0f,1.0f,0.0f);			
		gl.glVertex3f(-1.0f,-1.0f, 1.0f);		
		gl.glColor3f(0.0f,0.0f,1.0f);			
		gl.glVertex3f( 1.0f,-1.0f, 1.0f);		
		gl.glColor3f(1.0f,0.0f,0.0f);			
		gl.glVertex3f( 0.0f, 1.0f, 0.0f);			
		gl.glColor3f(0.0f,0.0f,1.0f);			
		gl.glVertex3f( 1.0f,-1.0f, 1.0f);		
		gl.glColor3f(0.0f,1.0f,0.0f);			
		gl.glVertex3f( 1.0f,-1.0f, -1.0f);		
		gl.glColor3f(1.0f,0.0f,0.0f);			
		gl.glVertex3f( 0.0f, 1.0f, 0.0f);			
		gl.glColor3f(0.0f,1.0f,0.0f);			
		gl.glVertex3f( 1.0f,-1.0f, -1.0f);			
		gl.glColor3f(0.0f,0.0f,1.0f);			
		gl.glVertex3f(-1.0f,-1.0f, -1.0f);			
		gl.glColor3f(1.0f,0.0f,0.0f);			
		gl.glVertex3f( 0.0f, 1.0f, 0.0f);			
		gl.glColor3f(0.0f,0.0f,1.0f);			
		gl.glVertex3f(-1.0f,-1.0f,-1.0f);			
		gl.glColor3f(0.0f,1.0f,0.0f);			
		gl.glVertex3f(-1.0f,-1.0f, 1.0f);	
		
	    gl.glEnd();
               
        rt+=0.2f;
        
	}
	public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h){}
	public void displayChanged(GLAutoDrawable drawable, boolean b1, boolean b2){}
	
}
public class SimpleTest {

	public static void main(String[] args)
	{
		Frame frame= new Frame("SimpleTest");
	
		GLCanvas canvas= new GLCanvas();
		SimpleEventListener listener= new SimpleEventListener();
	
		frame.setSize(640, 480);
		frame.add(canvas);
		frame.setVisible(true);
		
		canvas.addGLEventListener(listener);
	
		frame.addWindowListener(new WindowAdapter() {
		
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
	}
}


You need to set up your projection matrix.