GLContext outside GLEventListener

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

GLContext outside GLEventListener

PepperAnn
Hello,

I would like to know whether a GLContext is specific to its drawing surface and how to access it outside of the
GLEventListener. Like for example, I have a class for 3d objects that contain its own vertex and color data, aswell
as its own render() method (which is called by the GLEventListener). In the class constructor I would like to call glGenBuffers, glBindBuffers and glBufferData in order to initialize the VBO/s of the 3d object. As far as I understood I can only access these functions through the GLContext which is only available to the GLEventListener. I am sure there has to be some way to access the GLContext outside of the GLEventListener or create another (as long as it is not drawing surface specific), right? What is the answer to my question, and more importantly, how would I have figured it out on my own? Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: GLContext outside GLEventListener

gouessej
Administrator
Hi

Please look at the Java documentation, there are several methods to retrieve GL and GLContext:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLContext.html#getCurrent()
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLContext.html#getCurrentGL()

You should rather initialize your OpenGL resources in the init() method of your GLEventListener or add a GLRunnable into a queue. If you don't want to do that, get a GLContext, make it current, perform your OpenGL calls and release it. I advise you to look at the unit tests demonstrating the use of shared contexts.

Edit.: setSharedContext() can be used in your case.
Julien Gouesse | Personal blog | Website