Explicitly creating context for GLJPanel

Hello,

I am writing a swing applet which needs multiple GLJPanel instances sharing a single context. But after creating GLJPanel I can not use getContext method to access the GLContext instance being used due to null pointer exception. It seems like the context creating is being done after component gets visible. Even my attempts to use invokeLater to get context after component creation events are processed failed also. Even it is possible, it does not seem like an elegant way to get context after creating the first GLJPanel instance and create other panels later.

I tried GLDrawableFactory.getFactory().createExternalGLContext() to create a context but it fails with:
javax.media.opengl.GLException: Error: attempted to make an external GLContext without a drawable/context current.

Is there a way to explicitly create GL context that can be used by GLJPanel instances ?

regards

Yes thats true, GLJPanel and GLCanvas delay context creation until they are visible (on windows).

To get a shared context for all of your components you could use a GLPBuffer and pass it as shared context to your components:

GLPBuffer sharedPBuffer = GLDrawableFactory.createGLPbuffer(...,1,1, null);

new GLJPanel(...,sharedPBuffer.getContext());
new GLCanvas(...,sharedPBuffer.getContext());

Thanks a lot, it worked. I have passed a new GLCapabilities instance, Should I assume this uses the same fallback mechanism normally GLJPanel uses, line non-hardware support etc. to be chosen if needed ?

GLJPanel uses pbuffers internally too. This means you should check if your hardware has pbuffer support anyway.

I am not aware of a GLJPanel software fallback mode. The last time i used GLJPanels they where just created with the capabilities i passed in but this may have changed. I usually use the GLCanvas so i haven’t much experience with GLJPanels.

(btw i guess you need the shared context to share things like display lists, textures or vbos, if yes it probably doesn’t matter what capabilities you pass to the shared buffer context since you don’t use it for rendering)