execution problem - beginning jogl

Hi, I have a problem here, I set everything up, followed instructions but whatever I do I can’t get my basic jogl code to execute…

import java.awt.;
import java.awt.event.
;
import javax.swing.;
import net.java.games.jogl.
;

/**
*

  • @author El Technico
    */
    public class probeersel extends JFrame {

    /** Creates a new instance of probeersel */
    public probeersel() {

     super("JOGL-probeersel");
     
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
     GLCapabilities caps = new GLCapabilities();
     caps.setDoubleBuffered(true);
     caps.setHardwareAccelerated(true);
     
     GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(caps);
     canvas.addGLEventListener(new tekening3D());
     canvas.setSize(800, 600);
      
     getContentPane().add(canvas, BorderLayout.CENTER);
     
     setSize(800, 600);
     centerWindow(this);
    

    }

    public void centerWindow(Component frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();

    if (frameSize.width > screenSize.width ) frameSize.width = screenSize.width;
    if (frameSize.height > screenSize.height) frameSize.height = screenSize.height;

    frame.setLocation (
    (screenSize.width - frameSize.width ) >> 1,
    (screenSize.height - frameSize.height) >> 1
    );
    }

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {

      final probeersel app = new probeersel();

      //show what we’ve done
      SwingUtilities.invokeLater (
      new Runnable() {
      public void run() {
      app.setVisible(true);
      }
      }
      );

    }

}

class tekening3D implements GLEventListener {

public void init(GLDrawable drawable) {

    GL gl = drawable.getGL();
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glColor3i(0, 0, 0);
    gl.glPointSize(4.0f);
    
}

public void display(GLDrawable drawable) {
    
    GL gl = drawable.getGL();
    gl.glBegin( GL.GL_POINTS );
    gl.glVertex2i(100, 50);
    gl.glVertex2i(100, 130);
    gl.glVertex2i(150, 130);
    gl.glEnd();
    
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
    
    
    
}

public void displayChanged(GLDrawable drawable,
                       boolean modeChanged,
                       boolean deviceChanged) {}

}

When I execute this, I get this error message:

net.java.games.jogl.GLException: Unable to lock surface
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.lockSurface(WindowsOnscreenGLContext.java:155)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:107)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:203)
at net.java.games.jogl.GLCanvas.reshape(GLCanvas.java:97)
at java.awt.Component.setBounds(Component.java:1664)
at java.awt.Component.resize(Component.java:1601)
at java.awt.Component.setSize(Component.java:1593)
at net.java.games.jogl.impl.windows.WindowsGLContextFactory.getDummyGLContext(WindowsGLContextFactory.java:139)
at net.java.games.jogl.impl.windows.WindowsGLContext.choosePixelFormatAndCreateContext(WindowsGLContext.java:264)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.create(WindowsOnscreenGLContext.java:204)
at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(WindowsGLContext.java:133)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:110)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:203)
at net.java.games.jogl.GLCanvas.reshape(GLCanvas.java:97)
at java.awt.Component.setBounds(Component.java:1664)
at java.awt.BorderLayout.layoutContainer(BorderLayout.java:691)
at java.awt.Container.layout(Container.java:1020)
at java.awt.Container.doLayout(Container.java:1010)
at java.awt.Container.validateTree(Container.java:1092)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validate(Container.java:1067)
at java.awt.Window.show(Window.java:461)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at JAVA3D.probeersel$1.run(probeersel.java:67)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

One of the undocumented aspects of JOGL is that you can’t mess with the canvas before it is attached to a screen resource. That means no calls to setSize or anything like that until you add it to a Frame. So just move your canvas.setSize call to the line after adding it to the context pane and it should work just fine.

I’ve put the canvas.setSize(800, 600); command after adding it to the contentPane, but still it gives away the same error… :frowning:

I’m not sure but why don’t you try to remove the invokeLater stuff…
If I remember well, you must display the Frame before playing with some JOGL aspect (but it may be only for pBuffers…)

I have seen this error before, it is a bug in jogl. It seems to occur on all Windows machines, but not elsewhere.

Every time, you try to make a window containing a GLCanvas visible from the event dispatching thread, you will get an “Unable to lock surface” exception.

You can simply remove the invokeLater. Although this is an improper use of the Swing API, it will make the program work.

ps:
Your previous code is also theoretically incorrect. As you may not make any calls to a realized awt component outside the event dispatching thread, and you cannot guarantee, that your frame is not realized in its constructor (for example by the setSize call) you should move the entire main method into the invokeLater block. Well, you should do this theoretically… but actually your program still wouldn’t work, so just remove the invokeLater.

Hi,

Just a thought: Surely you don’t need to set the canvas size as well as that of it’s container? And wouldn’t your final canvas size end up slightly less than 800x600 with the window borders and title bar?

Also, it may be better to set the frame’s size before adding the canvas to the layout, but that might just be personal preference.

Try this:


/** 
 * 
 * @author  El Technico 
 */ 
public class probeersel extends JFrame { 
     
    /** Creates a new instance of probeersel */ 
    public probeersel() { 
    
   super("JOGL-probeersel"); 

   // Move to here:
   setSize(800, 600); 
   centerWindow(this); 
    
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    
   GLCapabilities caps = new GLCapabilities(); 
   caps.setDoubleBuffered(true); 
   caps.setHardwareAccelerated(true); 
    
   GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(caps); 
   canvas.addGLEventListener(new tekening3D()); 

   // Not needed:
   // canvas.setSize(800, 600); 
     
   getContentPane().add(canvas, BorderLayout.CENTER); 
        
    }     

this is quite frustrating, I got rid of the invokeLater thing, but now I get this error (with exactly the same code, just removed invokeLater):

java.lang.UnsatisfiedLinkError: dispatch_wglGetExtensionsStringARB
at net.java.games.jogl.impl.windows.WindowsGLImpl.dispatch_wglGetExtensionsStringARB(Native Method)
at net.java.games.jogl.impl.windows.WindowsGLImpl.wglGetExtensionsStringARB(WindowsGLImpl.java:33366)
at net.java.games.jogl.impl.windows.WindowsGLContextFactory$1.init(WindowsGLContextFactory.java:116)
at net.java.games.jogl.impl.GLDrawableHelper.init(GLDrawableHelper.java:68)
at net.java.games.jogl.GLCanvas$InitAction.run(GLCanvas.java:191)
at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(WindowsGLContext.java:160)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:110)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:203)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:186)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:74)
at net.java.games.jogl.impl.windows.WindowsGLContextFactory.getDummyGLContext(WindowsGLContextFactory.java:145)
at net.java.games.jogl.impl.windows.WindowsGLContext.choosePixelFormatAndCreateContext(WindowsGLContext.java:264)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.create(WindowsOnscreenGLContext.java:204)
at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(WindowsGLContext.java:133)
at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:110)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:203)
at net.java.games.jogl.GLCanvas.reshape(GLCanvas.java:97)
at java.awt.Component.setBounds(Component.java:1664)
at java.awt.BorderLayout.layoutContainer(BorderLayout.java:691)
at java.awt.Container.layout(Container.java:1020)
at java.awt.Container.doLayout(Container.java:1010)
at java.awt.Container.validateTree(Container.java:1092)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validate(Container.java:1067)
at java.awt.Window.show(Window.java:461)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at JAVA3D.probeersel.main(probeersel.java:57)

Thanks for all your help guys! There is still hope

this is quite frustrating

Don’t give up!
:wink:

It seems like you are using two incompatible versions of jogl.jar and jogl.dll. This may happen, if you have an old jogl.dll from a previous installation lingering around in some system directory or the bin directory of your JRE. The new jogl.jar requires an implementation for a new native method that was not present in the old version, but the old dll has no implementation for it: “Unsatisfied Link Error”.

Try do get rid of all "jogl.dll"s and “jogl.jars” on your system and make a fresh install with a matching pair of files from a prebuilt binary.

Hi,

I’m a JOGL newb too, and I have the exact same problem as geert … in fact, I have almost the exact same code as him… I think we have the same book! :stuck_out_tongue:

Anyway…I got rid of the invokeLater call, and I tried was Shadowcaster2 said about making sure I have the same version of the JOGL jar and dll, and eclipse flashes an error quickly, but then displays a frame that’s just gray… which I’m assuming is the JFrame but without any of the JOGL being put into it.

Any other ideas how I can get this to work?

Also… I’m a bit concerned about the comment regarding this not being correct Swing… how should I be launching this frame?

Thanks alot.
David