Re: moving GLPanel from one to other AWT container
Posted by Ondrej on Mar 24, 2011; 12:03pm
URL: https://forum.jogamp.org/moving-GLPanel-from-one-to-other-AWT-container-tp2722179p2724831.html
Sven thanks for you hints. I still wonder how to create parent shared context. I tried to get it from "parent" GLCanvas:
GLProfile.initSingleton(false);
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
parentCanvas = new GLCanvas(caps);
frame.add(parentCanvas);
frame.setVisible(true);
then created movable "child" GLCanvas:
canvas = new GLCanvas(parentCanvas.getChosenGLCapabilities(), parentCanvas.getContext());
canvas.addGLEventListener(glEventListener);
jPanel1.add(canvas);
frame.validate();
FPSAnimator animator = new FPSAnimator(canvas, 60);
animator.add(canvas);
animator.start();
after some user moves the canvas to second panel:
jPanel2.add(canvas);
also changed glEventListener to check if parent context is used:
@Override
public void init(GLAutoDrawable drawable) {
System.out.println("init: context #" + System.identityHashCode(drawable.getContext()) + " parent context #" + System.identityHashCode(parentCanvas.getContext()));
if(drawable.getContext() != parentCanvas.getContext()) {
drawable.setContext(parentCanvas.getContext());
}
}
When init() is called for the first time context and parentContext are not the same. Is it correct to call drawable.setContext() from init()? I am getting this exception:
init: context #17303670 parent context #6533862
Exception in thread "Timer-0" javax.media.opengl.GLException: java.lang.NullPointerException
at com.jogamp.opengl.impl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:98)
at com.jogamp.opengl.impl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:197)
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:164)
at javax.media.opengl.awt.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:709)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:361)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:74)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:140)
at com.jogamp.opengl.util.FPSAnimator$1.run(FPSAnimator.java:125)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.NullPointerException
at com.jogamp.opengl.impl.GLDrawableHelper.reshape(GLDrawableHelper.java:193)
at com.jogamp.opengl.impl.GLDrawableHelper.reshape(GLDrawableHelper.java:202)
at javax.media.opengl.awt.GLCanvas$DisplayAction.run(GLCanvas.java:789)
at com.jogamp.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:355)
at javax.media.opengl.awt.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:810)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
This is just the first init, still didn't get to the second init, when moving canvas to other panel.
Maybe it would be better to use GLPBuffer for parent context instead of GLCanvas.
I will also try with NewtCanvasAWT. Can you please recommend which unit test to look at. I expect it will be some of these jogl/src/test/com/jogamp/opengl/test/junit/newt
Ondrej