How to initialize jogl?

The following code fails abysmally.

`
import net.java.games.jogl.*;

public class Query {
public static void main(String[] args) {
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
GL gl=canvas.getGL();
String result=gl.glGetString(GL.GL_VERSION);
System.out.println(result);
}
}
`

It compiles fine, of course… but prints “(null)”, which isn’t what I’d hope to see.

In C, I’d use the glutInit functions to ensure that OpenGL was set up correctly before calling any glGet functions, but how do I do that with jogl? Evidently what I tried above does not seem to work.

Is there any way that I can possibly do stuff like this without the burden of a GUI application?

Thanks

Hi,

With JOGL you should only make “gl” call in a thread where the openGL context is valid, that is to say in one of the method provided by GLEventListener, or making yourself the thread the want as the openGl drawing thread…

It explains your null result.

Moreover, if i remember well, the lazy init used by JOGL must make you display a canvas before allowing you any gl calls (to be validated by JOGL gurus :wink: )

As a workaround You can put the canvas to a window outside the screen bounds to trigger the lazy initialization.