JavaGaming.org

March 10, 2010, 06:45:04 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
Advanced search  
Pages: 1 2 3 [4]   Go Down
Print
Author Topic: How to: Getting started with JOGL  (Read 89121 times)
0 Members and 1 Guest are viewing this topic.
cylab
JGO Kernel
*********
Offline Offline

Gender: Male
Posts: 1545


View Profile WWW
« Reply #90 on: March 23, 2008, 05:50:13 am »

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.
Logged

mr_incredible
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #91 on: April 03, 2008, 08:21:36 am »

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

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

call.
Logged
cylab
JGO Kernel
*********
Offline Offline

Gender: Male
Posts: 1545


View Profile WWW
« Reply #92 on: April 16, 2008, 01:10:02 pm »

Here is a working example:

Code:
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 <BR>
 * 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) {
    }
}
Logged

Trussell
Jr. Member
**
Offline Offline

Gender: Male
Posts: 56


Game Developer


View Profile
« Reply #93 on: April 26, 2008, 02:36:54 pm »

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.<clinit>(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.<init>(GLCanvas.java:131)
        at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:90)
        at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:83)
        at joglscape.SimpleJOGL.main(SimpleJOGL.java:25)
Logged

I am a noob attempting to make a video game.
cylab
JGO Kernel
*********
Offline Offline

Gender: Male
Posts: 1545


View Profile WWW
« Reply #94 on: April 26, 2008, 03:37:13 pm »

You have to start your program with configured native libraries. This means you have to add
Code:
-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.
Logged

gorgonzola
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #95 on: April 28, 2008, 01:30:49 am »

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 ^_^
Logged
gorgonzola
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #96 on: April 29, 2008, 03:11:01 am »

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

It's the best tutorial I have found by far after several hours of searching.
Logged
KeySabreur
JGO n00b
*
Offline Offline

Posts: 1


View Profile
« Reply #97 on: June 20, 2008, 05:37:47 pm »

Here is a working example:

Code:
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 <BR>
 * 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) {
    }
}

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.<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: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?
Logged
cylab
JGO Kernel
*********
Offline Offline

Gender: Male
Posts: 1545


View Profile WWW
« Reply #98 on: June 21, 2008, 04:25:37 pm »

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/<user>/development/jogl" or something like that) and either setup your environment variables accordingly or start your app with the right commanline options (see above)
Logged

ajith_kgs
JGO n00b
*
Offline Offline

Posts: 3


View Profile
« Reply #99 on: August 05, 2008, 07:46:29 am »

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. Cheesy Thanks in advance.

Code:
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);
}
});
}
}

« Last Edit: August 05, 2008, 07:50:11 am by ajith_kgs » Logged
GKW
Sr. Member
****
Offline Offline

Posts: 450


Revenge is mine!


View Profile
« Reply #100 on: August 05, 2008, 08:45:34 am »

You need to set up your projection matrix.
Logged
ajith_kgs
JGO n00b
*
Offline Offline

Posts: 3


View Profile
« Reply #101 on: August 05, 2008, 08:49:39 am »

ok.. how am I supposed to do that?
Logged
cylab
JGO Kernel
*********
Offline Offline

Gender: Male
Posts: 1545


View Profile WWW
« Reply #102 on: August 05, 2008, 09:27:56 am »

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.

Logged

ajith_kgs
JGO n00b
*
Offline Offline

Posts: 3


View Profile
« Reply #103 on: August 05, 2008, 10:33:24 am »

yea, i tried it. it works ..  Grin thank you..
Logged
nortino
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #104 on: August 25, 2008, 03:31:34 pm »

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.

« Last Edit: August 26, 2008, 04:07:33 pm by nortino » Logged
nortino
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #105 on: August 26, 2008, 04:06:06 pm »

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.



« Last Edit: September 07, 2008, 08:23:44 am by nortino » Logged
EpicNerd
JGO n00b
*
Offline Offline

Posts: 4


View Profile
« Reply #106 on: June 11, 2009, 09:02:33 am »

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:
Code:
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
Logged
bienator
JGO Ninja
*****
Offline Offline

Gender: Male
Posts: 582


OutOfCoffeeException


View Profile WWW
« Reply #107 on: June 11, 2009, 09:08:40 am »

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
Logged

EpicNerd
JGO n00b
*
Offline Offline

Posts: 4


View Profile
« Reply #108 on: June 11, 2009, 09:12:00 am »

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.
Logged
cylab
JGO Kernel
*********
Offline Offline

Gender: Male
Posts: 1545


View Profile WWW
« Reply #109 on: June 11, 2009, 02:03:45 pm »

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" ;-)
Logged

falcon
JGO n00b
*
Offline Offline

Posts: 4


View Profile
« Reply #110 on: August 15, 2009, 01:14:54 pm »

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

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 <BR>
 * 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) {
    }
}

Logged
bienator
JGO Ninja
*****
Offline Offline

Gender: Male
Posts: 582


OutOfCoffeeException


View Profile WWW
« Reply #111 on: August 15, 2009, 01:44:00 pm »

(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)
Logged

Justmaker
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #112 on: December 03, 2009, 08:41:30 am »

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?
Logged
Xerxes
JGO n00b
*
Offline Offline

Posts: 1


View Profile
« Reply #113 on: December 27, 2009, 11:43:48 am »

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.
« Last Edit: December 27, 2009, 11:46:37 am by Xerxes » Logged
gingerfish
JGO n00b
*
Offline Offline

Posts: 2


View Profile
« Reply #114 on: January 15, 2010, 12:17:41 am »

hey people,

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

where i can download the latest release??

thanks Smiley

Logged
rhdxmr
JGO n00b
*
Offline Offline

Posts: 12


View Profile
« Reply #115 on: January 19, 2010, 07:54:12 am »

you can download it from here.  Smiley
http://download.java.net/media/jogl/builds/archive/
Logged
Pages: 1 2 3 [4]   Go Up
Print
 
Jump to: