summaryrefslogtreecommitdiffstats
path: root/src/demos/hwShadowmapsSimple
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2003-11-04 02:29:09 +0000
committerKenneth Russel <[email protected]>2003-11-04 02:29:09 +0000
commit917325a616f2bd89589bc3b6a4bdce0679bb99cf (patch)
tree0105b9f1710a0be9304a980fa722617a688b3a0f /src/demos/hwShadowmapsSimple
parent645dc4e330e1685b280b8a406bd6a400fffa06b8 (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/hwShadowmapsSimple')
-rw-r--r--src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java82
1 files changed, 40 insertions, 42 deletions
diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
index 74ecbdd..e600dbd 100644
--- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
+++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
@@ -62,6 +62,7 @@ public class HWShadowmapsSimple {
private GLCanvas canvas;
private GLPbuffer pbuffer;
+ private Animator animator;
private GLUT glut;
@@ -145,6 +146,8 @@ public class HWShadowmapsSimple {
canvas.addGLEventListener(new Listener());
canvas.setNoAutoRedrawMode(true);
+ animator = new Animator(canvas);
+
Frame frame = new Frame("ARB_shadow Shadows");
frame.setLayout(new BorderLayout());
canvas.setSize(512, 512);
@@ -155,40 +158,11 @@ public class HWShadowmapsSimple {
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
- quit = true;
+ runExit();
}
});
- try {
- while (!quit) {
- if (viewer != null) {
- viewer.update();
-
- // Grab these values once per render to avoid multithreading
- // issues with their values being changed by manipulation from
- // the AWT thread during the render
- CameraParameters params = viewer.getCameraParameters();
-
- cameraPerspective.set(params.getProjectionMatrix());
- cameraInverseTransform.set(params.getModelviewMatrix());
- cameraTransform.set(cameraInverseTransform);
- cameraTransform.invertRigid();
- spotlightTransform.set(spotlight.getTransform());
- spotlightInverseTransform.set(spotlightTransform);
- spotlightInverseTransform.invertRigid();
- objectTransform.set(object.getTransform());
- }
-
- if (displayMode == RENDER_SCENE_FROM_CAMERA_VIEW_SHADOWED || !fullyInitialized) {
- if (pbuffer != null) {
- pbuffer.display();
- }
- }
- canvas.display();
- }
- } finally {
- System.exit(0);
- }
+ animator.start();
}
//----------------------------------------------------------------------
@@ -212,7 +186,6 @@ public class HWShadowmapsSimple {
checkExtension(gl, "GL_ARB_pixel_format");
} catch (GLException e) {
e.printStackTrace();
- quit = true;
throw(e);
}
@@ -319,8 +292,26 @@ public class HWShadowmapsSimple {
}
public void display(GLDrawable drawable) {
- if (quit) {
- return;
+ viewer.update();
+
+ // Grab these values once per render to avoid multithreading
+ // issues with their values being changed by manipulation from
+ // the AWT thread during the render
+ CameraParameters params = viewer.getCameraParameters();
+
+ cameraPerspective.set(params.getProjectionMatrix());
+ cameraInverseTransform.set(params.getModelviewMatrix());
+ cameraTransform.set(cameraInverseTransform);
+ cameraTransform.invertRigid();
+ spotlightTransform.set(spotlight.getTransform());
+ spotlightInverseTransform.set(spotlightTransform);
+ spotlightInverseTransform.invertRigid();
+ objectTransform.set(object.getTransform());
+
+ if (displayMode == RENDER_SCENE_FROM_CAMERA_VIEW_SHADOWED || !fullyInitialized) {
+ if (pbuffer != null) {
+ pbuffer.display();
+ }
}
if (!fullyInitialized) {
@@ -355,8 +346,6 @@ public class HWShadowmapsSimple {
gl.glLoadIdentity();
}
- CameraParameters params = viewer.getCameraParameters();
-
switch (displayMode) {
case RENDER_SCENE_FROM_CAMERA_VIEW: render_scene_from_camera_view(gl, glu, drawable, params); break;
case RENDER_SCENE_FROM_CAMERA_VIEW_SHADOWED: render_scene_from_camera_view_shadowed(gl, glu, drawable, params); break;
@@ -382,15 +371,10 @@ public class HWShadowmapsSimple {
}
private void dispatchKey(char k) {
- if ((k == (char) 27) || (k == 'q')) {
- quit = true;
- return;
- }
-
switch (k) {
case 27:
case 'q':
- quit = true;
+ runExit();
break;
case 'v':
@@ -847,4 +831,18 @@ public class HWShadowmapsSimple {
return m;
}
+
+ 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();
+ }
}