CS 428 - JOGL information

Online resources


Why are we using JOGL?

OpenGL is perhaps most directly used with C/C++. JOGL serves two purposes. First, it provides "wrapper functions" via JNI so you can call OpenGL functions from Java. Second, it extends classes in Java.awt to allow for the creation of OpenGL windows. (From C/C++, this is typically done with a GUI library such as GLUT, Tck/Tk, Motif, or the MFC in Visual C++ in Windows).


Using OpenGL with JOGL

The use of OpenGL via JOGL is quite simple, and can be briefly summarized as:

For example, the following fragment of C code:
      glBegin(GL_POLYGON);
      glVertex3f(0.25, 0.25, 0.0);
      glVertex3f(0.75, 0.25, 0.0);
      glVertex3f(0.75, 0.75, 0.0);
      glVertex3f(0.25, 0.75, 0.0);
      glEnd();
would be written in Java as:
      gl.glBegin(GL.GL_POLYGON);
      gl.glVertex3f(0.25f, 0.25f, 0.0f);
      gl.glVertex3f(0.75f, 0.25f, 0.0f);
      gl.glVertex3f(0.75f, 0.75f, 0.0f);
      gl.glVertex3f(0.25f, 0.75f, 0.0f);
      gl.glEnd();
Notice the explicit type specifications (the f's) in the arguments to gl.glVertex3f(). As a result, it's probably easier to use double for everything:
      gl.glBegin(GL.GL_POLYGON);
      gl.glVertex3d(0.25, 0.25, 0.0);
      gl.glVertex3d(0.75, 0.25, 0.0);
      gl.glVertex3d(0.75, 0.75, 0.0);
      gl.glVertex3d(0.25, 0.75, 0.0);
      gl.glEnd();
There are also some differences in argument structure, in particular when passing arrays to OpenGL functions. For instance, when using the vector versions of vertex functions, like gl.glVertex3dv(), or gl.glColor3dv(), you need to add a second argument with the value zero:
      double[] p = { 1.0, 1.0, 2.0 };

      gl.glVertex3dv(p, 0);
or when specifying a clipping plane, a third argument of zero:
      double[] eqn = { 0.0, 1.0, 0.0, 1.5 };

      gl.glClipPlane(GL.GL_CLIP_PLANE0, eqn, 0);

The skeleton code you'll be using defines gl and (when needed) glu.


428 Home