From 94a3846d87e55e09a32c489fc6b8231accb70349 Mon Sep 17 00:00:00 2001 From: Carsten Weisse Date: Mon, 11 Dec 2006 21:32:17 +0000 Subject: hope this helps on win32 screen mode switching --- src/jake2/render/opengl/Jsr231Driver.java | 76 ++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/src/jake2/render/opengl/Jsr231Driver.java b/src/jake2/render/opengl/Jsr231Driver.java index ffb7d29..4b42f3a 100644 --- a/src/jake2/render/opengl/Jsr231Driver.java +++ b/src/jake2/render/opengl/Jsr231Driver.java @@ -1,8 +1,7 @@ /* - * JoglCommon.java + * Jsr231Driver.java * Copyright (C) 2004 * - * $Id: Jsr231Driver.java,v 1.17 2006-12-11 16:38:09 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -130,7 +129,7 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { */ public int setMode(Dimension dim, int mode, boolean fullscreen) { - Dimension newDim = new Dimension(); + final Dimension newDim = new Dimension(); VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); @@ -182,30 +181,43 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { canvas.addMouseWheelListener(JOGLKBD.listener); if (fullscreen) { - - DisplayMode displayMode = findDisplayMode(newDim); - - newDim.width = displayMode.getWidth(); - newDim.height = displayMode.getHeight(); - window.setUndecorated(true); - window.setResizable(false); - - device.setFullScreenWindow(window); - - if (device.isFullScreenSupported()) - device.setDisplayMode(displayMode); - - window.setLocation(0, 0); - window.setSize(displayMode.getWidth(), displayMode.getHeight()); - canvas.setSize(displayMode.getWidth(), displayMode.getHeight()); - VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); + DisplayMode displayMode = findDisplayMode(newDim); + + newDim.width = displayMode.getWidth(); + newDim.height = displayMode.getHeight(); + window.setUndecorated(true); + window.setResizable(false); + + device.setFullScreenWindow(window); + + if (device.isFullScreenSupported()) + device.setDisplayMode(displayMode); + + window.setLocation(0, 0); + window.setSize(displayMode.getWidth(), displayMode.getHeight()); + canvas.setSize(displayMode.getWidth(), displayMode.getHeight()); + + VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); } else { - window.setLocation(window_xpos, window_ypos); - window.pack(); - window.setResizable(false); - window.setVisible(true); + // Not much point in having a full-screen window in this + // case + device.setFullScreenWindow(null); + final Frame f2 = window; + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + f2.setVisible(false); + f2.setLocation(window_xpos, window_ypos); + f2.pack(); + f2.setResizable(false); + f2.setVisible(true); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } } while (!canvas.isDisplayable()) { @@ -247,6 +259,7 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { e.printStackTrace(); } if (window != null) { + display.destroy(); window.dispose(); } } @@ -348,9 +361,10 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { } public void removeNotify() { - release(); - context.destroy(); - drawable.setRealized(false); + if (drawable != null) { + drawable.setRealized(false); + drawable = null; + } super.removeNotify(); } @@ -368,6 +382,14 @@ public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { release(); drawable.swapBuffers(); } + + void destroy() { + if (context != null) { + release(); + context.destroy(); + context = null; + } + } private static GraphicsConfiguration unwrap(AWTGraphicsConfiguration config) { if (config == null) { -- cgit v1.2.3