Hello,
I've been working on a JOGL application using active rendering. I've based a lot of it off of Andrew Davison's chapter on JOGL (
http://www.java-gaming.org/forums/index.php?topic=12512.0). He extends an AWT Canvas to create the class that has the thread that does all the GL rendering, but wraps it in a JPanel. I tried to create one class, extending JPanel, to handle the GL rendering thread. I created a Canvas as an instance variable in that classand added it to the panel. Then I add my custom, threaded panel to a JFrame. But whenever I try to make the context current to make GL calls, a GLExeption is thrown:
1 2 3 4 5 6 7
| Exception in thread "Thread-2" javax.media.opengl.GLException: Unable to lock surface at com.sun.opengl.impl.windows.WindowsOnscreenGLDrawable.lockSurface(WindowsOnscreenGLDrawable.java:169) at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:57) at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:118) at quantum.graphics.RenderJPanel.makeContextCurrent(RenderJPanel.java:108) at quantum.graphics.RenderJPanel.run(RenderJPanel.java:123) at java.lang.Thread.run(Thread.java:595) |
(I called my JPanel RenderJPanel).
Some of my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| private void makeContextCurrent() { try { while(context.makeCurrent()==GLContext.CONTEXT_NOT_CURRENT) Thread.sleep(50); } catch(InterruptedException e){e.printStackTrace();} }
public void run() { try { while((!ready)||(!isVisible())) Thread.sleep(50); } catch(InterruptedException e){e.printStackTrace();}
makeContextCurrent(); gl=context.getGL(); glu=new GLU();
if(renderer!=null) { init(); context.release();
while(running) { makeContextCurrent();
render(); drawable.swapBuffers();
context.release(); }
shutdown(); }
context.destroy(); System.exit(0); } |
I'm not creating any other threads in the program, o I don't see how the context could already be current on a different thread. The javadoc says the exception can also be thrown due to "non-recoverable, window system-specific errors." That doesn't help me much though.
Is there a problem with combining the JPanel and the Canvas in the same class? Anything else I'm doing wrong? If more code would be helpful, I can post it too.
Thanks for the help in advance.