diff options
author | Kenneth Russel <[email protected]> | 2003-11-04 02:29:09 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2003-11-04 02:29:09 +0000 |
commit | 917325a616f2bd89589bc3b6a4bdce0679bb99cf (patch) | |
tree | 0105b9f1710a0be9304a980fa722617a688b3a0f /src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java | |
parent | 645dc4e330e1685b280b8a406bd6a400fffa06b8 (diff) |
Implemented a per-thread GLContext stack, which gives a thread
knowledge of the OpenGL contexts it has made current and allows a
GLDrawable to make its context current recursively as well as allowing
a GLEventListener to call another GLDrawable's display() method from
within its display(). This mechanism can be used fairly easily to
expose swapBuffers in the public API, as has been requested. Updated
the demos which had to explicitly call display() on more than one
drawable to use the Animator class and to call GLDrawable.display()
from within their GLEventListeners' display() methods. Updated
documentation. Fixed bugs in gleem's CameraParameters class.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@27 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java')
-rw-r--r-- | src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java | 91 |
1 files changed, 35 insertions, 56 deletions
diff --git a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java index f34940c..03ef552 100644 --- a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java +++ b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java @@ -57,8 +57,6 @@ import gleem.linalg.*; */ public class ProceduralTexturePhysics { - private static volatile boolean quit; - private volatile boolean drawing; private volatile int mousePosX; private volatile int mousePosY; @@ -66,6 +64,7 @@ public class ProceduralTexturePhysics { private Dimension dim = new Dimension(); private GLCanvas canvas; private Water water; + private Animator animator; private volatile ExaminerViewer viewer; private boolean[] b = new boolean[256]; private boolean doViewAll = true; @@ -85,6 +84,8 @@ public class ProceduralTexturePhysics { canvas.addGLEventListener(new Listener()); canvas.setNoAutoRedrawMode(true); + animator = new Animator(canvas); + Frame frame = new Frame("Procedural Texture Waves"); frame.setLayout(new BorderLayout()); canvas.setSize(512, 512); @@ -95,47 +96,17 @@ public class ProceduralTexturePhysics { frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { - quit = true; + runExit(); } }); - try { - water = new Water(); - water.initialize("demos/data/images/nvfixed.tga", - "demos/data/images/nvspin.tga", - "demos/data/images/droplet.tga", - "demos/data/cubemaps/CloudyHills_{0}.tga", - canvas); - } catch (GLException e) { - JOptionPane.showMessageDialog(null, e.toString(), "Unavailable extension", JOptionPane.ERROR_MESSAGE); - } - - try { - while (!quit) { - if (viewer != null) { - try { - if (drawing) { - canvas.getSize(dim); - water.addDroplet(new Water.Droplet( 2 * (mousePosX / (float) dim.width - 0.5f), - -2 * (mousePosY / (float) dim.height - 0.5f), - 0.08f)); - } - water.tick(); - canvas.display(); - } catch (GLException e) { - // Have seen spurious exceptions getting thrown during SwapBuffers. - // Not sure why at this time; disabling of repaint() should prevent - // AWT thread from getting involved. Continue animating anyway. - e.printStackTrace(); - } - } else { - // Make the pbuffer get created - canvas.display(); - } - } - } finally { - System.exit(0); - } + water = new Water(); + water.initialize("demos/data/images/nvfixed.tga", + "demos/data/images/nvspin.tga", + "demos/data/images/droplet.tga", + "demos/data/cubemaps/CloudyHills_{0}.tga", + canvas); + animator.start(); } //---------------------------------------------------------------------- @@ -167,7 +138,6 @@ public class ProceduralTexturePhysics { checkExtension(gl, "GL_ARB_pixel_format"); } catch (GLException e) { e.printStackTrace(); - quit = true; throw(e); } @@ -220,14 +190,6 @@ public class ProceduralTexturePhysics { } public void display(GLDrawable drawable) { - if (water == null) { - return; - } - - if (quit) { - return; - } - if (!firstRender) { if (++frameCount == 30) { timer.stop(); @@ -255,6 +217,14 @@ public class ProceduralTexturePhysics { ManipManager.getManipManager().updateCameraParameters(drawable, viewer.getCameraParameters()); ManipManager.getManipManager().render(drawable, gl); + if (drawing) { + canvas.getSize(dim); + water.addDroplet(new Water.Droplet( 2 * (mousePosX / (float) dim.width - 0.5f), + -2 * (mousePosY / (float) dim.height - 0.5f), + 0.08f)); + } + water.tick(); + CameraParameters params = viewer.getCameraParameters(); water.draw(gl, params.getOrientation().inverse()); } @@ -272,22 +242,17 @@ public class ProceduralTexturePhysics { if (!gl.isExtensionAvailable(extensionName)) { String message = "Unable to initialize " + extensionName + " OpenGL extension"; JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - throw new GLException(message); + runExit(); } } private void dispatchKey(char k) { setFlag(k, !getFlag(k)); - if ((k == (char) 27) || (k == 'q')) { - quit = true; - return; - } - switch (k) { case 27: case 'q': - quit = true; + runExit(); break; case 'w': water.enableWireframe(getFlag('w')); @@ -389,4 +354,18 @@ public class ProceduralTexturePhysics { } } } + + private void runExit() { + // Note: calling System.exit() synchronously inside the draw, + // reshape or init callbacks can lead to deadlocks on certain + // platforms (in particular, X11) because the JAWT's locking + // routines cause a global AWT lock to be grabbed. Run the + // exit routine in another thread. + new Thread(new Runnable() { + public void run() { + animator.stop(); + System.exit(0); + } + }).start(); + } } |