mik01aj
mik01aj

Reputation: 12392

How to make JOGL 2.0 work with SWT?

I'm trying to get SWT working with the newest JOGL (2.0).

I tried SWT snippet 209, but it doesn't work. The problem is caused by the following line:

final GLContext context = GLDrawableFactory.getFactory().createExternalGLContext();

...but when I change getFactory() to getFactory(GLProfile.getDefault()) (to make it compatible with the new API), it crashes on createExternalGLContext() with javax.media.opengl.GLException: Error: current context null. I don't understand this message: I'm trying to create a new context, and it complains that the current is null. Why?

Maybe there is some other way to create a GLContext?

Or maybe it is possible to use GLEventListener with SWT GLCanvas?

PS. I placed my modified version of the snippet here.


Edit: now I understand the error message. Documentation says:

The underlying OpenGL context must be current on the current thread at the time this method is called.

How to create the first GLContext?

Upvotes: 1

Views: 2106

Answers (2)

Wade Walker
Wade Walker

Reputation: 534

The tutorial at http://wadeawalker.wordpress.com/2010/10/09/tutorial-a-cross-platform-workbench-program-using-java-opengl-and-eclipse/ shows how to do exactly this. I modified the SWT snippet 209 starting from the JOGL2 version at http://github.com/sgothel/jogl-demos/blob/master/src/demos/swt/Snippet209.java.

My tutorial shows how to do it as an Eclipse RCP app (using only SWT, no AWT bridge). To do it as a standalone SWT app, there's a tutorial at https://sites.google.com/site/justinscsstuff/jogl-tutorials.

Upvotes: 0

j flemm
j flemm

Reputation: 2039

Easy way: Have your rendering class implement GLEventListener and move your GLContext creation code into the .init(...) callback (seems like the right location for the example you posted). Then add that listener to whatever GLCanvas or the like you're using as your display widget.

They cleaned up JOGL a decent bit recently so most examples won't even compile without a decent bit of massaging. If you're new to it, you might want to roll back to an older version with higher code example compatibility while you get spun up.

Upvotes: 2

Related Questions