diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/demos/common/Demo.java | 61 | ||||
-rwxr-xr-x | src/demos/common/DemoListener.java (renamed from src/demos/util/DemoListener.java) | 2 | ||||
-rwxr-xr-x | src/demos/hdr/HDR.java | 20 | ||||
-rw-r--r-- | src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java | 17 | ||||
-rw-r--r-- | src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java | 16 | ||||
-rwxr-xr-x | src/demos/jrefract/JRefract.java | 71 | ||||
-rw-r--r-- | src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java | 19 | ||||
-rw-r--r-- | src/demos/vertexArrayRange/VertexArrayRange.java | 14 | ||||
-rw-r--r-- | src/demos/vertexBufferObject/VertexBufferObject.java | 12 | ||||
-rw-r--r-- | src/demos/vertexProgRefract/VertexProgRefract.java | 25 | ||||
-rw-r--r-- | src/demos/vertexProgWarp/VertexProgWarp.java | 23 | ||||
-rw-r--r-- | src/gleem/ManipManager.java | 13 |
12 files changed, 186 insertions, 107 deletions
diff --git a/src/demos/common/Demo.java b/src/demos/common/Demo.java new file mode 100755 index 0000000..00f5956 --- /dev/null +++ b/src/demos/common/Demo.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package demos.common; + +import javax.media.opengl.*; + +public abstract class Demo implements GLEventListener { + protected DemoListener demoListener; + private boolean doShutdown = true; + + public void setDemoListener(DemoListener listener) { + this.demoListener = listener; + } + + // Override this with any other cleanup actions + public void shutdownDemo() { + // Execute only once + boolean shouldDoShutdown = doShutdown; + doShutdown = false; + if (shouldDoShutdown) { + demoListener.shutdownDemo(); + } + } +} diff --git a/src/demos/util/DemoListener.java b/src/demos/common/DemoListener.java index ee343e7..95b5e9c 100755 --- a/src/demos/util/DemoListener.java +++ b/src/demos/common/DemoListener.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package demos.util; +package demos.common; /** Defines certain events demos can send. Different harnesses may respond differently to these events. */ diff --git a/src/demos/hdr/HDR.java b/src/demos/hdr/HDR.java index b7467da..20122f4 100755 --- a/src/demos/hdr/HDR.java +++ b/src/demos/hdr/HDR.java @@ -11,6 +11,7 @@ import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.cg.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -20,7 +21,7 @@ import gleem.linalg.*; Ported to Java by Kenneth Russell */ -public class HDR implements GLEventListener { +public class HDR extends Demo { private static String[] defaultArgs = { "demos/data/images/stpeters_cross.hdr", "512", @@ -30,6 +31,7 @@ public class HDR implements GLEventListener { "3", "demos/data/models/teapot.obj" }; + private GLAutoDrawable drawable; private boolean useCg; private boolean initComplete; private HDRTexture hdr; @@ -217,15 +219,14 @@ public class HDR implements GLEventListener { return win_h; } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } //---------------------------------------------------------------------- // Listener for main window @@ -334,6 +335,7 @@ public class HDR implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; viewer = new ExaminerViewer(MouseButtonHelper.numMouseButtons()); viewer.setAutoRedrawMode(false); @@ -436,7 +438,7 @@ public class HDR implements GLEventListener { private void unavailableExtension(String message) { JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); throw new GLException(message); } @@ -447,7 +449,7 @@ public class HDR implements GLEventListener { switch (keyCode) { case KeyEvent.VK_ESCAPE: case KeyEvent.VK_Q: - demoListener.shutdownDemo(); + shutdownDemo(); break; case KeyEvent.VK_EQUALS: @@ -1219,7 +1221,7 @@ public class HDR implements GLEventListener { private void usage() { System.err.println("usage: java demos.hdr.HDR [-cg] image.hdr pbuffer_w pbuffer_h window_scale blur_width blur_decimate [obj file]"); - demoListener.shutdownDemo(); + shutdownDemo(); } private void printThreadName(String where) { diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java index dcffc3a..ca2a8aa 100644 --- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java +++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java @@ -45,6 +45,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -58,7 +59,7 @@ import gleem.linalg.*; Ported to Java by Kenneth Russell */ -public class HWShadowmapsSimple implements GLEventListener { +public class HWShadowmapsSimple extends Demo { public static void main(String[] args) { final GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); HWShadowmapsSimple demo = new HWShadowmapsSimple(); @@ -88,15 +89,15 @@ public class HWShadowmapsSimple implements GLEventListener { }); } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } + private GLPbuffer pbuffer; private GLUT glut; @@ -152,6 +153,7 @@ public class HWShadowmapsSimple implements GLEventListener { private float lightshaper_zFar = 5.0f; // Manipulators + private GLAutoDrawable drawable; private ExaminerViewer viewer; private boolean doViewAll = true; // private float zNear = 0.5f; @@ -257,6 +259,7 @@ public class HWShadowmapsSimple implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; object = new HandleBoxManip(); object.setTranslation(new Vec3f(0, 0.7f, 1.8f)); @@ -370,7 +373,7 @@ public class HWShadowmapsSimple implements GLEventListener { switch (k) { case 27: case 'q': - demoListener.shutdownDemo(); + shutdownDemo(); break; case 'v': diff --git a/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java b/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java index eb90430..05594be 100644 --- a/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java +++ b/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java @@ -45,6 +45,7 @@ import javax.imageio.stream.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -66,7 +67,7 @@ import gleem.linalg.*; Ported to Java by Kenneth Russell */ -public class InfiniteShadowVolumes implements GLEventListener { +public class InfiniteShadowVolumes extends Demo { public static void main(String[] args) { GLCapabilities caps = new GLCapabilities(); caps.setStencilBits(16); @@ -98,15 +99,14 @@ public class InfiniteShadowVolumes implements GLEventListener { }); } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } static class Model { Model() { @@ -148,6 +148,7 @@ public class InfiniteShadowVolumes implements GLEventListener { private GLUT glut = new GLUT(); + private GLAutoDrawable drawable; private ExaminerViewer viewer; private HandleBoxManip objectManip; private HandleBoxManip lightManip; @@ -228,6 +229,7 @@ public class InfiniteShadowVolumes implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; objectManip = new HandleBoxManip(); manager.showManipInWindow(objectManip, drawable); @@ -564,7 +566,7 @@ public class InfiniteShadowVolumes implements GLEventListener { private void dispatchKey(char k) { b[k] = ! b[k]; if (k==27 || k=='q') { - demoListener.shutdownDemo(); + shutdownDemo(); return; } diff --git a/src/demos/jrefract/JRefract.java b/src/demos/jrefract/JRefract.java index d6c3e04..b3953b4 100755 --- a/src/demos/jrefract/JRefract.java +++ b/src/demos/jrefract/JRefract.java @@ -42,6 +42,7 @@ import javax.swing.event.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.hdr.HDR; import demos.hwShadowmapsSimple.HWShadowmapsSimple; import demos.infiniteShadowVolumes.InfiniteShadowVolumes; @@ -84,6 +85,17 @@ public class JRefract { private static final int WATER = 8; private JInternalFrame addWindow(int which) { + // FIXME: workaround for problem in 1.6 where ALL Components, + // including Swing components, are Finalizable, requiring two full + // GC cycles (and running of finalizers) to reclaim + System.gc(); + // Try to get finalizers run + try { + Thread.sleep(1); + } catch (InterruptedException e) { + } + System.gc(); + String str = ""; switch (which) { case GEARS: str = "Gears Demo"; break; @@ -122,6 +134,7 @@ public class JRefract { } }; + Demo demo = null; switch (which) { case GEARS: { // GLEventListener already added @@ -129,46 +142,35 @@ public class JRefract { } case HDR: { - HDR demo = new HDR(); - demo.setDemoListener(demoListener); - demo.setup(null); - inner.setSize(demo.getPreferredWidth(), demo.getPreferredHeight()); - canvas.addGLEventListener(demo); + demo = new HDR(); + ((HDR) demo).setup(null); + inner.setSize(((HDR) demo).getPreferredWidth(), ((HDR) demo).getPreferredHeight()); break; } case HWSHADOWS: { - HWShadowmapsSimple demo = new HWShadowmapsSimple(); - demo.setDemoListener(demoListener); - canvas.addGLEventListener(demo); + demo = new HWShadowmapsSimple(); break; } case INFINITE: { - InfiniteShadowVolumes demo = new InfiniteShadowVolumes(); - demo.setDemoListener(demoListener); - canvas.addGLEventListener(demo); + demo = new InfiniteShadowVolumes(); break; } case REFRACT: { - VertexProgRefract demo = new VertexProgRefract(); - demo.setDemoListener(demoListener); - canvas.addGLEventListener(demo); + demo = new VertexProgRefract(); break; } case VBO: { - VertexBufferObject demo = new VertexBufferObject(); - demo.setDemoListener(demoListener); - canvas.addGLEventListener(demo); + demo = new VertexBufferObject(); break; } case WARP: { - VertexProgWarp demo = new VertexProgWarp(); - demo.setDemoListener(demoListener); - demo.setTitleSetter(new VertexProgWarp.TitleSetter() { + demo = new VertexProgWarp(); + ((VertexProgWarp) demo).setTitleSetter(new VertexProgWarp.TitleSetter() { public void setTitle(final String title) { SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -177,17 +179,18 @@ public class JRefract { }); } }); - canvas.addGLEventListener(demo); break; } case WATER: { - ProceduralTexturePhysics demo = new ProceduralTexturePhysics(); - demo.setDemoListener(demoListener); - canvas.addGLEventListener(demo); + demo = new ProceduralTexturePhysics(); break; } } + if (which != GEARS) { + demo.setDemoListener(demoListener); + canvas.addGLEventListener(demo); + } canvas.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { canvas.requestFocus(); @@ -196,20 +199,23 @@ public class JRefract { addJPanel(canvas); + final Demo fDemo = demo; + inner.addInternalFrameListener(new InternalFrameAdapter() { public void internalFrameClosed(InternalFrameEvent e) { - removeJPanel(canvas); - System.gc(); + if (fDemo != null) { + fDemo.shutdownDemo(); + } } }); inner.getContentPane().setLayout(new BorderLayout()); if (which == REFRACT) { - inner.getContentPane().add(canvas, BorderLayout.CENTER); - inner.getContentPane().add(new JButton("West"), BorderLayout.WEST); - inner.getContentPane().add(new JButton("East"), BorderLayout.EAST); - inner.getContentPane().add(new JButton("North"), BorderLayout.NORTH); - inner.getContentPane().add(new JButton("South"), BorderLayout.SOUTH); + // Testing scrolling + canvas.setSize(512, 512); + canvas.setPreferredSize(new Dimension(512, 512)); + JScrollPane scroller = new JScrollPane(canvas); + inner.getContentPane().add(scroller); } else if (which == GEARS) { // Provide control over transparency of gears background canvas.setOpaque(false); @@ -237,7 +243,6 @@ public class JRefract { } public void run(String[] args) { - JFrame frame = new JFrame("JOGL and Swing Interoperability"); desktop = new JDesktopPane(); desktop.setSize(1024, 768); @@ -350,7 +355,7 @@ public class JRefract { frame.setSize(desktop.getSize()); frame.setVisible(true); - animator = new Animator(); + animator = new FPSAnimator(60); animator.start(); } diff --git a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java index b1d52c5..6fbab29 100644 --- a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java +++ b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java @@ -39,6 +39,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -57,7 +58,7 @@ import gleem.linalg.*; * */ -public class ProceduralTexturePhysics implements GLEventListener { +public class ProceduralTexturePhysics extends Demo { public static void main(String[] args) { GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); ProceduralTexturePhysics demo = new ProceduralTexturePhysics(); @@ -88,19 +89,20 @@ public class ProceduralTexturePhysics implements GLEventListener { animator.start(); } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } + private volatile boolean drawing; private volatile int mousePosX; private volatile int mousePosY; + private GLAutoDrawable drawable; private Water water = new Water(); private volatile ExaminerViewer viewer; private boolean[] b = new boolean[256]; @@ -151,6 +153,7 @@ public class ProceduralTexturePhysics implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; viewer = new ExaminerViewer(MouseButtonHelper.numMouseButtons()); viewer.setAutoRedrawMode(false); @@ -248,7 +251,7 @@ public class ProceduralTexturePhysics implements GLEventListener { if (!gl.isExtensionAvailable(extensionName)) { String message = "Unable to initialize " + extensionName + " OpenGL extension"; JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } } @@ -258,7 +261,7 @@ public class ProceduralTexturePhysics implements GLEventListener { switch (k) { case 27: case 'q': - demoListener.shutdownDemo(); + shutdownDemo(); break; case 'w': water.enableWireframe(getFlag('w')); diff --git a/src/demos/vertexArrayRange/VertexArrayRange.java b/src/demos/vertexArrayRange/VertexArrayRange.java index 26d5512..7c4d1a5 100644 --- a/src/demos/vertexArrayRange/VertexArrayRange.java +++ b/src/demos/vertexArrayRange/VertexArrayRange.java @@ -42,6 +42,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; /** <P> A port of NVidia's [tm] Vertex Array Range demonstration to @@ -75,7 +76,7 @@ import demos.util.*; C++ speed with the HotSpot Client and Server compilers, respectively. </P> */ -public class VertexArrayRange implements GLEventListener { +public class VertexArrayRange extends Demo { public static void main(String[] args) { boolean startSlow = false; @@ -135,15 +136,10 @@ public class VertexArrayRange implements GLEventListener { setFlag('v', true); // VAR on } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; private boolean[] b = new boolean[256]; private static final int SIZEOF_FLOAT = 4; private static final int STRIP_SIZE = 48; @@ -264,7 +260,7 @@ public class VertexArrayRange implements GLEventListener { new Thread(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } }).start(); throw new RuntimeException(message); @@ -289,7 +285,7 @@ public class VertexArrayRange implements GLEventListener { ensurePresent(gl, "glFinishFenceNV"); ensurePresent(gl, "glAllocateMemoryNV"); } catch (RuntimeException e) { - demoListener.shutdownDemo(); + shutdownDemo(); throw (e); } @@ -371,7 +367,7 @@ public class VertexArrayRange implements GLEventListener { setFlag(k, !getFlag(k)); // Quit on escape or 'q' if ((k == (char) 27) || (k == 'q')) { - demoListener.shutdownDemo(); + shutdownDemo(); return; } diff --git a/src/demos/vertexBufferObject/VertexBufferObject.java b/src/demos/vertexBufferObject/VertexBufferObject.java index ee78499..97a5483 100644 --- a/src/demos/vertexBufferObject/VertexBufferObject.java +++ b/src/demos/vertexBufferObject/VertexBufferObject.java @@ -42,6 +42,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; /** <P> A port of NVidia's [tm] Vertex Array Range demonstration to @@ -67,7 +68,7 @@ import demos.util.*; same data in system memory allows. </P> */ -public class VertexBufferObject implements GLEventListener { +public class VertexBufferObject extends Demo { public static void main(String[] args) { boolean vboEnabled = true; @@ -124,15 +125,10 @@ public class VertexBufferObject implements GLEventListener { setFlag('i', true); // infinite viewer and light } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; private boolean initComplete; private boolean[] b = new boolean[256]; private static final int SIZEOF_FLOAT = 4; @@ -266,7 +262,7 @@ public class VertexBufferObject implements GLEventListener { new Thread(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } }).start(); throw new RuntimeException(message); @@ -366,7 +362,7 @@ public class VertexBufferObject implements GLEventListener { setFlag(k, !getFlag(k)); // Quit on escape or 'q' if ((k == (char) 27) || (k == 'q')) { - demoListener.shutdownDemo(); + shutdownDemo(); return; } diff --git a/src/demos/vertexProgRefract/VertexProgRefract.java b/src/demos/vertexProgRefract/VertexProgRefract.java index 18dca1c..8c1e867 100644 --- a/src/demos/vertexProgRefract/VertexProgRefract.java +++ b/src/demos/vertexProgRefract/VertexProgRefract.java @@ -46,6 +46,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -62,7 +63,7 @@ import gleem.linalg.*; Ported to Java and ARB_fragment_program by Kenneth Russell */ -public class VertexProgRefract implements GLEventListener { +public class VertexProgRefract extends Demo { public static void main(String[] args) { GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); VertexProgRefract demo = new VertexProgRefract(); @@ -93,11 +94,6 @@ public class VertexProgRefract implements GLEventListener { animator.start(); } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - - private DemoListener demoListener; private boolean useRegisterCombiners; private boolean initComplete; private boolean firstRender = true; @@ -109,6 +105,7 @@ public class VertexProgRefract implements GLEventListener { private GLUT glut = new GLUT(); + private GLAutoDrawable drawable; private ExaminerViewer viewer; private boolean doViewAll = true; @@ -245,14 +242,14 @@ public class VertexProgRefract implements GLEventListener { new Thread(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } }).start(); throw new RuntimeException(message); } } } catch (RuntimeException e) { - demoListener.shutdownDemo(); + shutdownDemo(); throw(e); } @@ -282,7 +279,7 @@ public class VertexProgRefract implements GLEventListener { try { loadPNGCubemap(gl, glu, "demos/data/cubemaps/uffizi", true); } catch (IOException e) { - demoListener.shutdownDemo(); + shutdownDemo(); throw new RuntimeException(e); } @@ -318,6 +315,7 @@ public class VertexProgRefract implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; viewer = new ExaminerViewer(MouseButtonHelper.numMouseButtons()); viewer.setNoAltKeyMode(true); @@ -454,13 +452,18 @@ public class VertexProgRefract implements GLEventListener { //---------------------------------------------------------------------- // Internals only below this point // + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } + private boolean[] b = new boolean[256]; private void dispatchKey(char k) { setFlag(k, !getFlag(k)); // Quit on escape or 'q' if ((k == (char) 27) || (k == 'q')) { - demoListener.shutdownDemo(); + shutdownDemo(); return; } @@ -562,7 +565,7 @@ public class VertexProgRefract implements GLEventListener { new Thread(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } }).start(); throw new RuntimeException(message); diff --git a/src/demos/vertexProgWarp/VertexProgWarp.java b/src/demos/vertexProgWarp/VertexProgWarp.java index c6e177a..e740a64 100644 --- a/src/demos/vertexProgWarp/VertexProgWarp.java +++ b/src/demos/vertexProgWarp/VertexProgWarp.java @@ -42,6 +42,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -55,11 +56,12 @@ import gleem.linalg.*; Ported to Java by Kenneth Russell */ -public class VertexProgWarp implements GLEventListener { +public class VertexProgWarp extends Demo { private Frame frame; private Animator animator; private volatile boolean quit; + private GLAutoDrawable drawable; private DurationTimer timer = new DurationTimer(); private boolean firstRender = true; private int frameCount; @@ -111,11 +113,6 @@ public class VertexProgWarp implements GLEventListener { titleSetter = setter; } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - - private DemoListener demoListener; private TitleSetter titleSetter; private boolean initComplete; @@ -158,7 +155,7 @@ public class VertexProgWarp implements GLEventListener { try { initExtension(gl, "GL_ARB_vertex_program"); } catch (RuntimeException e) { - demoListener.shutdownDemo(); + shutdownDemo(); throw(e); } @@ -211,6 +208,7 @@ public class VertexProgWarp implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; viewer = new ExaminerViewer(MouseButtonHelper.numMouseButtons()); viewer.setNoAltKeyMode(true); @@ -301,13 +299,18 @@ public class VertexProgWarp implements GLEventListener { //---------------------------------------------------------------------- // Internals only below this point // + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } + private void initExtension(GL gl, String glExtensionName) { if (!gl.isExtensionAvailable(glExtensionName)) { final String message = "OpenGL extension \"" + glExtensionName + "\" not available"; new Thread(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } }).start(); throw new RuntimeException(message); @@ -363,7 +366,7 @@ public class VertexProgWarp implements GLEventListener { case KeyEvent.VK_ESCAPE: case KeyEvent.VK_Q: - demoListener.shutdownDemo(); + shutdownDemo(); return; case KeyEvent.VK_W: @@ -440,7 +443,7 @@ public class VertexProgWarp implements GLEventListener { try { Triceratops.drawObject(gl); } catch (IOException e) { - demoListener.shutdownDemo(); + shutdownDemo(); throw new RuntimeException(e); } break; diff --git a/src/gleem/ManipManager.java b/src/gleem/ManipManager.java index 767c8cd..85a3d80 100644 --- a/src/gleem/ManipManager.java +++ b/src/gleem/ManipManager.java @@ -117,12 +117,17 @@ public class ManipManager { /** Remove all references to a given window, including removing all manipulators from it. */ public synchronized void unregisterWindow(GLAutoDrawable window) { + if (window == null) { + return; + } WindowInfo info = (WindowInfo) windowToInfoMap.get(window); - for (Iterator iter = info.manips.iterator(); iter.hasNext(); ) { - removeManipFromWindow((Manip) iter.next(), window); + if (info != null) { + for (Iterator iter = info.manips.iterator(); iter.hasNext(); ) { + removeManipFromWindow((Manip) iter.next(), window); + } + windowToInfoMap.remove(window); + removeMouseListeners(window); } - windowToInfoMap.remove(window); - removeMouseListeners(window); } /** Make a given manipulator visible and active in a given |