summaryrefslogtreecommitdiffstats
path: root/src/demos/fullscreen
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2009-06-15 23:12:27 +0000
committerKenneth Russel <[email protected]>2009-06-15 23:12:27 +0000
commit41cd6c47b23975098cd155517790e018670785e7 (patch)
tree247333528ad674d427ba96b1e05810f7961d609e /src/demos/fullscreen
parent935d2596c13371bb745d921dbcb9f05b0c11a010 (diff)
Copied JOGL_2_SANDBOX r350 on to trunk; JOGL_2_SANDBOX branch is now closed
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@352 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/fullscreen')
-rwxr-xr-xsrc/demos/fullscreen/FullscreenWorkaround.java96
-rwxr-xr-xsrc/demos/fullscreen/GearsFullscreen.java128
-rwxr-xr-xsrc/demos/fullscreen/GearsFullscreen2.java156
-rwxr-xr-xsrc/demos/fullscreen/JGearsFullscreen.java153
4 files changed, 533 insertions, 0 deletions
diff --git a/src/demos/fullscreen/FullscreenWorkaround.java b/src/demos/fullscreen/FullscreenWorkaround.java
new file mode 100755
index 0000000..b337db7
--- /dev/null
+++ b/src/demos/fullscreen/FullscreenWorkaround.java
@@ -0,0 +1,96 @@
+/*
+ * 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.fullscreen;
+
+import java.awt.*;
+import javax.swing.*;
+
+import javax.media.opengl.*;
+
+/** Class which implements workaround for full-screen bugs on Windows
+ when <code>-Dsun.java2d.noddraw=true</code> is specified as well
+ as a similar bug on Mac OS X. This code currently expects that the
+ GLAutoDrawable will be placed in a containing Frame. */
+
+public class FullscreenWorkaround implements GLEventListener {
+ private int width;
+ private int height;
+
+ /** Creates a full-screen workaround with the specified width and
+ height to set the full-screen window to later. */
+ public FullscreenWorkaround(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ // Find parent frame if any
+ final Frame frame = getParentFrame((Component) drawable);
+ if (frame != null) {
+ EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ frame.setBounds(0, 0, width, height);
+ frame.setVisible(true);
+ frame.toFront();
+ }
+ });
+ }
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ public void display(GLAutoDrawable drawable) {}
+ public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {}
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ private static Frame getParentFrame(Component c) {
+ while (c != null &&
+ (!(c instanceof Frame))) {
+ c = c.getParent();
+ }
+ return (Frame) c;
+ }
+}
diff --git a/src/demos/fullscreen/GearsFullscreen.java b/src/demos/fullscreen/GearsFullscreen.java
new file mode 100755
index 0000000..2bbf158
--- /dev/null
+++ b/src/demos/fullscreen/GearsFullscreen.java
@@ -0,0 +1,128 @@
+package demos.fullscreen;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import demos.gears.Gears;
+import demos.util.*;
+import javax.media.opengl.awt.GLCanvas;
+import com.sun.opengl.util.Animator;
+
+/**
+ * GearsFullscreen.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21 <P>
+ *
+ * Illustrates simple usage of GLCanvas in full-screen mode. On
+ * Windows this demo should be run with the system property
+ * -Dsun.java2d.noddraw=true specified to prevent Java2D from using
+ * DirectDraw, which is incompatible with OpenGL at the driver level.
+ */
+
+public class GearsFullscreen {
+ private GraphicsDevice dev;
+ private DisplayMode origMode;
+ private boolean fullScreen;
+ private Frame frame;
+ private Animator animator;
+ private int initWidth = 300;
+ private int initHeight = 300;
+
+ public static void main(String[] args) {
+ new GearsFullscreen().run(args);
+ }
+
+ public void run(String[] args) {
+ dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ origMode = dev.getDisplayMode();
+ DisplayMode newMode = null;
+
+ if (dev.isFullScreenSupported()) {
+ newMode = ScreenResSelector.showSelectionDialog();
+ if (newMode != null) {
+ initWidth = newMode.getWidth();
+ initHeight = newMode.getHeight();
+ }
+ } else {
+ System.err.println("NOTE: full-screen mode not supported; running in window instead");
+ }
+
+ frame = new Frame("Gear Demo");
+ if (newMode != null) {
+ frame.setUndecorated(true);
+ }
+ final GLCanvas canvas = new GLCanvas();
+
+ canvas.addGLEventListener(new Gears());
+ canvas.addGLEventListener(new FullscreenWorkaround(initWidth, initHeight));
+
+ frame.add(canvas);
+ frame.setSize(initWidth, initHeight);
+ animator = new Animator(canvas);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ runExit();
+ }
+ });
+ frame.setVisible(true);
+
+ if (dev.isFullScreenSupported() && (newMode != null)) {
+ dev.setFullScreenWindow(frame);
+ if (dev.isDisplayChangeSupported()) {
+ dev.setDisplayMode(newMode);
+ fullScreen = true;
+ } else {
+ // Not much point in having a full-screen window in this case
+ dev.setFullScreenWindow(null);
+ final Frame f2 = frame;
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ f2.setVisible(false);
+ f2.setUndecorated(false);
+ f2.setVisible(true);
+ f2.setSize(initWidth, initHeight);
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.err.println("NOTE: was not able to change display mode; full-screen disabled");
+ }
+ }
+
+ animator.start();
+ }
+
+ public void runExit() {
+ // Run this on another thread than the AWT event queue to
+ // make sure the call to Animator.stop() completes before
+ // exiting
+ new Thread(new Runnable() {
+ public void run() {
+ animator.stop();
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ if (fullScreen) {
+ try {
+ dev.setDisplayMode(origMode);
+ } catch (Exception e1) {
+ }
+ try {
+ dev.setFullScreenWindow(null);
+ } catch (Exception e2) {
+ }
+ fullScreen = false;
+ }
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.exit(0);
+ }
+ }).start();
+ }
+}
diff --git a/src/demos/fullscreen/GearsFullscreen2.java b/src/demos/fullscreen/GearsFullscreen2.java
new file mode 100755
index 0000000..8b050df
--- /dev/null
+++ b/src/demos/fullscreen/GearsFullscreen2.java
@@ -0,0 +1,156 @@
+package demos.fullscreen;
+
+import demos.gears.Gears;
+import demos.util.ScreenResSelector;
+import java.awt.BorderLayout;
+import java.awt.DisplayMode;
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.media.opengl.awt.GLCanvas;
+import com.sun.opengl.util.Animator;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.ToolTipManager;
+
+
+/**
+ * GearsFullscreen2.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21 <P>
+ *
+ * Illustrates more complex usage of GLCanvas in full-screen mode. On
+ * Windows this demo should be run with the system property
+ * -Dsun.java2d.noddraw=true specified to prevent Java2D from using
+ * DirectDraw, which is incompatible with OpenGL at the driver level.
+ */
+
+public class GearsFullscreen2 {
+ private GraphicsDevice dev;
+ private DisplayMode origMode;
+ private boolean fullScreen;
+ private JFrame frame;
+ private Animator animator;
+ private int initWidth = 300;
+ private int initHeight = 300;
+
+ public static void main(String[] args) {
+ new GearsFullscreen2().run(args);
+ }
+
+ public void run(String[] args) {
+ dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ origMode = dev.getDisplayMode();
+ DisplayMode newMode = null;
+
+ if (dev.isFullScreenSupported()) {
+ newMode = ScreenResSelector.showSelectionDialog();
+ if (newMode != null) {
+ initWidth = newMode.getWidth();
+ initHeight = newMode.getHeight();
+ }
+ } else {
+ System.err.println("NOTE: full-screen mode not supported; running in window instead");
+ }
+
+ frame = new JFrame("Gear Demo");
+ if (newMode != null) {
+ frame.setUndecorated(true);
+ }
+ GLCanvas canvas = new GLCanvas();
+
+ canvas.addGLEventListener(new Gears());
+ canvas.addGLEventListener(new FullscreenWorkaround(initWidth, initHeight));
+ frame.getContentPane().setLayout(new BorderLayout());
+
+ ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
+
+ JButton button = new JButton("West");
+ button.setToolTipText("West ToolTip");
+ frame.getContentPane().add(button, BorderLayout.WEST);
+
+ button = new JButton("East");
+ button.setToolTipText("East ToolTip");
+ frame.getContentPane().add(button, BorderLayout.EAST);
+
+ button = new JButton("North");
+ button.setToolTipText("North ToolTip");
+ frame.getContentPane().add(button, BorderLayout.NORTH);
+
+ button = new JButton("South");
+ button.setToolTipText("South ToolTip");
+ frame.getContentPane().add(button, BorderLayout.SOUTH);
+
+ frame.getContentPane().add(canvas, BorderLayout.CENTER);
+ frame.setSize(initWidth, initHeight);
+ animator = new Animator(canvas);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ runExit();
+ }
+ });
+ frame.setVisible(true);
+
+ if (dev.isFullScreenSupported() && (newMode != null)) {
+ dev.setFullScreenWindow(frame);
+ if (dev.isDisplayChangeSupported()) {
+ dev.setDisplayMode(newMode);
+ fullScreen = true;
+ } else {
+ // Not much point in having a full-screen window in this case
+ dev.setFullScreenWindow(null);
+ final Frame f2 = frame;
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ f2.setVisible(false);
+ f2.setUndecorated(false);
+ f2.setVisible(true);
+ f2.setSize(initWidth, initHeight);
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.err.println("NOTE: was not able to change display mode; full-screen disabled");
+ }
+ }
+
+ animator.start();
+ }
+
+ public void runExit() {
+ // Run this on another thread than the AWT event queue to
+ // make sure the call to Animator.stop() completes before
+ // exiting
+ new Thread(new Runnable() {
+ public void run() {
+ animator.stop();
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ if (fullScreen) {
+ try {
+ dev.setDisplayMode(origMode);
+ } catch (Exception e1) {
+ }
+ try {
+ dev.setFullScreenWindow(null);
+ } catch (Exception e2) {
+ }
+ fullScreen = false;
+ }
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.exit(0);
+ }
+ }).start();
+ }
+}
diff --git a/src/demos/fullscreen/JGearsFullscreen.java b/src/demos/fullscreen/JGearsFullscreen.java
new file mode 100755
index 0000000..92e0769
--- /dev/null
+++ b/src/demos/fullscreen/JGearsFullscreen.java
@@ -0,0 +1,153 @@
+package demos.fullscreen;
+
+import demos.jgears.JGears;
+import demos.util.ScreenResSelector;
+import java.awt.BorderLayout;
+import java.awt.DisplayMode;
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.media.opengl.awt.GLJPanel;
+import com.sun.opengl.util.Animator;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+
+
+
+/**
+ * JGearsFullscreen.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21 <P>
+ *
+ * Illustrates usage of GLJPanel in full-screen mode. On Windows this
+ * demo should be run with the system property
+ * -Dsun.java2d.noddraw=true specified to prevent Java2D from using
+ * DirectDraw, which is incompatible with OpenGL at the driver level.
+ */
+
+public class JGearsFullscreen {
+ private GraphicsDevice dev;
+ private DisplayMode origMode;
+ private boolean fullScreen;
+ private JFrame frame;
+ private Animator animator;
+ private int initWidth = 300;
+ private int initHeight = 300;
+
+ public static void main(String[] args) {
+ new JGearsFullscreen().run(args);
+ }
+
+ public void run(String[] args) {
+ dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ origMode = dev.getDisplayMode();
+ DisplayMode newMode = null;
+
+ if (dev.isFullScreenSupported()) {
+ newMode = ScreenResSelector.showSelectionDialog();
+ if (newMode != null) {
+ initWidth = newMode.getWidth();
+ initHeight = newMode.getHeight();
+ }
+ } else {
+ System.err.println("NOTE: full-screen mode not supported; running in window instead");
+ }
+
+ frame = new JFrame("Gear Demo");
+ if (newMode != null) {
+ frame.setUndecorated(true);
+ }
+ JGears drawable = new JGears();
+ drawable.addGLEventListener(new FullscreenWorkaround(initWidth, initHeight));
+
+ frame.getContentPane().setLayout(new BorderLayout());
+
+ JButton button = new JButton("West");
+ button.setToolTipText("West ToolTip");
+ frame.getContentPane().add(button, BorderLayout.WEST);
+
+ button = new JButton("East");
+ button.setToolTipText("East ToolTip");
+ frame.getContentPane().add(button, BorderLayout.EAST);
+
+ button = new JButton("North");
+ button.setToolTipText("North ToolTip");
+ frame.getContentPane().add(button, BorderLayout.NORTH);
+
+ button = new JButton("South");
+ button.setToolTipText("South ToolTip");
+ frame.getContentPane().add(button, BorderLayout.SOUTH);
+
+ frame.getContentPane().add(drawable, BorderLayout.CENTER);
+ frame.setSize(initWidth, initHeight);
+ animator = new Animator(drawable);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ runExit();
+ }
+ });
+ frame.setVisible(true);
+
+ if (dev.isFullScreenSupported() && (newMode != null)) {
+ dev.setFullScreenWindow(frame);
+ if (dev.isDisplayChangeSupported()) {
+ dev.setDisplayMode(newMode);
+ fullScreen = true;
+ } else {
+ // Not much point in having a full-screen window in this case
+ dev.setFullScreenWindow(null);
+ final Frame f2 = frame;
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ f2.setVisible(false);
+ f2.setUndecorated(false);
+ f2.setVisible(true);
+ f2.setSize(initWidth, initHeight);
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.err.println("NOTE: was not able to change display mode; full-screen disabled");
+ }
+ }
+
+ animator.start();
+ }
+
+ public void runExit() {
+ // Run this on another thread than the AWT event queue to
+ // make sure the call to Animator.stop() completes before
+ // exiting
+ new Thread(new Runnable() {
+ public void run() {
+ animator.stop();
+ try {
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ if (fullScreen) {
+ try {
+ dev.setDisplayMode(origMode);
+ } catch (Exception e1) {
+ }
+ try {
+ dev.setFullScreenWindow(null);
+ } catch (Exception e2) {
+ }
+ fullScreen = false;
+ }
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.exit(0);
+ }
+ }).start();
+ }
+}