From d347e888b8bbc189e8844a2ae3c819c39f520c9b Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Fri, 27 Jun 2008 00:04:31 +0000 Subject: Periodically release the OpenGL context to allow the AWT to dispatch native messages on some platforms git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@252 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4 --- src/demos/es1/RedSquare.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/demos') diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 97b6730..fe69983 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -112,6 +112,7 @@ public class RedSquare implements MouseListener { long startTime = System.currentTimeMillis(); long curTime; + int frameCount = 0; while (!ml.quit && ((curTime = System.currentTimeMillis()) - startTime) < 20000) { gl.glClear(GL2ES1.GL_COLOR_BUFFER_BIT | GL2ES1.GL_DEPTH_BUFFER_BIT); @@ -140,6 +141,20 @@ public class RedSquare implements MouseListener { } window.pumpMessages(); + + // Periodically release the OpenGL context to allow + // messages to be pumped in some configurations (in + // particular, if using the AWT) + if (++frameCount > 10) { + frameCount = 0; + context.release(); + if ((res = context.makeCurrent()) == GLContext.CONTEXT_NOT_CURRENT) { + System.out.println("Unexpected error making context current again"); + System.exit(0); + } else if (res == GLContext.CONTEXT_CURRENT_NEW) { + gl = context.getGL().getGL2ES1(); + } + } } // Shut things down cooperatively -- cgit v1.2.3