Archive for JOGL
Installing JOGL and configuring for Windows and Eclipse
After a headache trying to find the right files and the standard ‘playing about’, I’ve finally got my OpenGl ‘Hello World’ example up and running. Before I forget, I thought I’d post my installation list as others seem to be getting dated.
I’ve modified the instructions from Matt Kindy http://kindy.net/jogl_setup.txt
DOWNLOAD ECLIPSE
1. Download Eclipse from the
http://www.eclipse.org/downloads/
I’m currently using ‘Eclipse for RCP and RAP Developers, 189 MB windows 32 Bit‘
2. There is no installer (executable program) used to install Eclipse. Just unzipping to a directory in an appropriate location on your hard disk (e.g. ‘C:\eclipse\‘). It is very strongly recommended that you locate the eclipse directory at the root of your computer hard drive or on a directory path with no spaces in its name (e.g. ‘C:\software\eclipse\‘). Eclipse does not write entries to the Windows registry so you can simply delete (or move) the directory, installed files, shortcuts, and/or the workspace: there is no executable uninstaller either so shift+Delete anytime.
3. Run Eclipse by running ‘C:\software\eclipse.exe‘ executable
DOWNLOAD JOGL
1. Download JOGL from the JogAmp.org site:
http://jogamp.org/deployment/webstart/archive/
At the bottom you’ll find jogl-v2.0-rc2.zip 03-Mar-2011 03:23 18M
Download and extract the ZIP file into a folder.
COPYING FILES
2. Create a folder in a convenient place to contain the necessary JOGL .jar files
e.g ‘C:\software\java\jogl\2.0\‘
3. Copy the .jar files from the folder in step 1 to the folder created in step 2.
============================
OPTIONS
Now this is where the given example and my way differs.
I will add my way at the end, so feel free to follow this way or jump to my way at the end ![]()
============================
4. Copy these DLL files to the Java Runtime Environment bin folder (e.g. ‘C:\Program Files\Java\jre6\bin‘):
gluegen-rt.dll
jogl.dll
jogl_awt.dll
jogl_cg.dll
SETTING ENVIRONMENT VARIABLES
5. Open the Windows environment variable window:
- Right-click My computer, choose Properties
- In Vista, choose “Advanced System Settings”;
In XP, choose the Advanced tab
- Click the “Environment Variables” button
- Under “System Variables” you will edit the following variables:
6. CLASSPATH
Add to the end of CLASSPATH the path to the JOGL .jar files folder (created in step 2)
- be sure the added path string is separated from the original string by a semicolon (;)
7. java.library.path
Create this environment variable with the path to the JRE bin folder (see step 4)
USING IN ECLIPSE
8. When you make a project in Eclipse, you will need to add the JOGL .jar files
to the project. To do so:
- right-click the project name and choose properties
- Choose “Java Build Path” in the left pane
- Choose the “Libraries” tab
- Click “Add External JARs”
- Browse to the folder from step 2. Add each of the JOGL .jar files to the project
IMPORTING THE JOGL LIBRARIES IN JAVA
9. To use in your Java program, add these lines to the appropriate class files:
import javax.media.opengl.*;
import com.sun.opengl.util.*;
import javax.media.opengl.glu.*;
Specifically, you’ll need these classes:
javax.media.opengl.GL
com.sun.opengl.util.GLUT
com.sun.opengl.util.Animator\
among others.
============================
My Way from Step 4.
============================
Eclipse
4. Start Eclipse and create a new java project File > New > java project
You can call the project ‘HelloWorld’
Make sure the execution environment is ‘JavaSE-1.6′
Click NEXT
5. Select the Libraries tab and click ‘Add Library’
Select ‘User Library’ as we’re going to create our own Jogl library
Select ‘User Libraries’ as the list should be empty
Now click ‘New’ and call the library ‘Jogl2.0′ and click ‘ok’
Click on the new ‘Jogl2.0′ library
Select ‘Add JARs’ and move to your jogl directory (type C:\software\java\jogl\2.0\lib into the filename and click open)
Add files to library
nativewindow.all.jar
newt.all.jar
gluegen-rt.jar
jogl.all.jar
Optional
You might want to expand (click on the plus sign) the library and attached files
then click on ‘Native library location’ and click ‘Edit’
then enter the path to your jogl lib directory (‘C:\software\java\jogl\2.0\lib‘)
repeat for all attached files
6. Now you should have a user library to add called ‘jogl2.0′ (or whatever you called yours)
Whenever you start a new project you’ll be able to right click on the project icon
Select Properties
select Java build path
select Add library > User library > Jogl2.0
JoGL ‘Hello World’ Example
Now you’ve got Eclipse and Jogl installed, you’ll probably want a great JoGL ‘Hello World’ example to try >>
JOGL Hello World Example
After looking around for a great first OpenGL example in java using JoGL I came across a great post on Schabby’s Blog which I have blatantly copied from http://schabby.de/jogl-example-hello-world/
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.
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.
So one you got the binaries, unpack the ZIP file somewhere. You will notice the lib folder with a number of DLL and JAR files. All you need is in that lib folder.
Create a new eclipse project (name doesnt matter) and add the following JARs on the classpath:
- jogl.all.jar
- nativewindow.all.jar
- gluegen-rt.jar
Then, copy the following DLL files to the projects root directory (this is where your src folder lies in).
- gluegen-rt.dll
- jogl_desktop.dll
- nativewindow_awt.dll
These files are the native part of the OpenGL binding and are linked via Java Native Interface (JNI). Since Eclipse starts all Programs with the working directory set to the project folder, the VM will find the DLLs when needed.
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 Render.java class looks like follows. It implements GLEventListener which is the call-back implementaiton by JOGL to do all OpenGL rendering.
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.
That’s it so far. Please let me know if you have questions or comments.
