Completely lost- getting started with JOGL

Wow its amazing how much of a headache this thing really is, it makes no sense to me how anyone can even get started with it with 2 thousand different versions with 2000 different imports, yet all the tutorials are the same and none work! /rant.

Ok so I installed all the JOGL dll’s and Jars and I can access the new JSR imports (javax.media.opengl) but I have no idea how to get started programming with java. I have tried the converted NeHe tutorials for JOGL but those dont work (most arent updated to JSR, and i have tried fixing it myself but no luck there)

Anyone know where i can get some up to date tutorials for getting started with JOGL?

Or can someone post a SINGLE file template that I can use and get started with…Just something I can build upon and learn JOGL with…

Thanks, I really appreciate the help to those who help.

I hope “installed” does not mean you have copied the files to your jre/ext folder. This is a common hint in JOGL tutorials, but is wrong, since it might break webstart of JOGL applications using other versions than your “installed” one.

You can use our support pack for Netbeans 6, if you are using this IDE or would like to try it. It contains all neccessary jars and natives and includes most of the official JOGL demos as template projects.

If you prefer another IDE, you can use the following code as a starter:


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

Thanks man, I did use your installer before and it worked great! But now Its having problems


To run this application from the command line without Ant, try:
java -cp "C:\Documents and Settings\Christopher\.netbeans\6.0\jogl-runtime\gluegen-rt.jar-natives-windows-i586;C:\Documents and Settings\Christopher\.netbeans\6.0\jogl-runtime\jogl.jar-natives-windows-i586;C:\Documents and Settings\Christopher\My Documents\NetBeansProjects\SimpleJOGL\dist\SimpleJOGL.jar" org.yourorghere.SimpleJOGL
Creating native distibutions
C:\Documents and Settings\Christopher\My Documents\NetBeansProjects\SimpleJOGL\nbproject\build-jogl-template-impl.xml:12: The following error occurred while executing this line:
C:\Documents and Settings\Christopher\My Documents\NetBeansProjects\SimpleJOGL\nbproject\build-jogl-template-impl.xml:86: C:\Documents and Settings\Christopher\.netbeans\6.0\jogl-runtime\jogl.jar-natives-windows-i586-natives-windows-i586 not found.
BUILD FAILED (total time: 1 second)


I have no idea why…I downloaded your OpenGL plugin. Installed it, tried to run this SimpleJOGL app and it does not work :frowning: Although it did work before :(, maybe i should reinstall everything, including netbeans?

hi Swattkidd7,

does the
C:\Documents and Settings\Christopher.netbeans\6.0\jogl-runtime
folder exist?

Yes that does exist

and also I redid EVERYTHING and now the SimpleJOGL does compile but I am getting the error when running the program that I got in the beginning that made me do all that crap :frowning:


Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.nio.DirectByteBuffer cannot be cast to com.sun.opengl.impl.windows.JAWT_Win32DrawingSurfaceInfo
        at com.sun.opengl.impl.windows.WindowsOnscreenGLDrawable.lockSurface(WindowsOnscreenGLDrawable.java:189)
        at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:57)
        at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
        at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:182)
        at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:301)
        at javax.media.opengl.GLCanvas.display(GLCanvas.java:133)
        at javax.media.opengl.GLCanvas.paint(GLCanvas.java:166)
        at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
        at sun.awt.RepaintArea.paint(RepaintArea.java:224)
        at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
        at java.awt.Component.dispatchEventImpl(Component.java:4486)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

hmm, just noticed this in the your ant output:
C:\Documents and Settings\Christopher.netbeans\6.0\jogl-runtime\jogl.jar-natives-windows-i586-natives-windows-i586
thats one -natives-windows-i586 to much…

I can’t explain why that happens have you edited the build.xml or something like that?

I downloaded the OpenGL pack from plugin protal and all build targets worked for me.

could you please uninstall the pack (all modules of category “OpenGL” and the JOGL module in category “Libraries”)
and remove:
C:\Documents and Settings\Christopher.netbeans\6.0\config\Preferences\javax\media\opengl.properties
C:\Documents and Settings\Christopher.netbeans\6.0\jogl-runtime

and reinstall again (please use the plugin portal version)?

Yea i will remove everything and reinstall and by portal version, what do you mean? Like download the OpenGL pack?

yes
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260

Ok I did that all, and right after I installed the plugin, I created a new SimpleJOGL project and right away I had some reference problems for some reason, but fixed them by creating the libraries JOGL and GLUEGEN-RT and adding the appropriate folders to them…but then I got the same error.

C:\Documents and Settings\Christopher\My Documents\NetBeansProjects\SimpleJOGL\nbproject\build-jogl-template-impl.xml:12: The following error occurred while executing this line:
C:\Documents and Settings\Christopher\My Documents\NetBeansProjects\SimpleJOGL\nbproject\build-jogl-template-impl.xml:86: C:\Documents and Settings\Christopher.netbeans\6.0\jogl-runtime\jogl.jar-natives-windows-i586-natives-windows-i586 not found.

I also have no idea why i am getting the double “natives-windows-i586” i had noticed that also, maybe i should try editing the xml file?
or better yet, could you post yours so i could just copy and paste it and save mine because i have no idea how to edit it:P

also i have been trying to get this to work since 10 in the morning, I have a pretty bad headache, I appreciate your help and I will come back later…im gonna go do something else now…

for me its 1 in the morning and i have to get up early _today… so you will have to wait some hours :wink:

your reference problem is an other strange thing. The pack registers the JOGL and GLUEGEN-RT libraries via a xml file this is almost impossible that they are missing in Tools|Libraries if you have installed the jogl-project.nbm module (and restarted netbeans like the installer recomented).

Yea I did all that, i have no idea why these problems arised…:frowning:

You have the locations of your libraries wrong. Go to the Library Manager and edit the JOGL and GLUEGEN-RT entries. Remove the folders you have added there and just add jogl.jar in the JOGL library and the gluegen-rt.jar in the GLUEGEN-RT library.

This is caused by mismatching jogl.jar and jogl.dll. Please make sure you don’t have a jogl.jar/jogl.dll somewhere global in your system like in the JRE/JDK’s ext folder or under windows/system32 or somewhere else on your PATH.

Trying

Thank you very much to both of you for the help everything seems to be working now. Thank you once again! I really appreciate it!!!