|
From: <eli...@us...> - 2008-12-28 19:30:50
|
Revision: 3172
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3172&view=rev
Author: elias_naur
Date: 2008-12-28 19:30:43 +0000 (Sun, 28 Dec 2008)
Log Message:
-----------
Added Display.setDisplayModeAndFullscreen(mode) to switch mode and set fullscreen in one call (idea stolen from MatthiasM). Tweaked FullScreenWindowedTest to use the new method.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-12-28 17:50:08 UTC (rev 3171)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-12-28 19:30:43 UTC (rev 3172)
@@ -496,10 +496,33 @@
* from getAvailableDisplayModes() or if the mode switch fails.
*/
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
+ setDisplayModeAndFullscreenInternal(fullscreen, current_mode);
+ }
+
+ /**
+ * Set the mode of the context. If no context has been created through create(),
+ * the mode will apply when create() is called. If mode.isFullscreenCapable() is true, the context will become
+ * a fullscreen context and the display mode is switched to the mode given by getDisplayMode(). If
+ * mode.isFullscreenCapable() is false, the context will become a windowed context with the dimensions given in the
+ * mode returned by getDisplayMode(). The native cursor position is also reset.
+ *
+ * @param mode The new display mode to set. Must be non-null.
+ *
+ * @throws LWJGLException If the mode switch fails.
+ */
+ public static void setDisplayModeAndFullscreen(DisplayMode mode) throws LWJGLException {
+ setDisplayModeAndFullscreenInternal(mode.isFullscreenCapable(), mode);
+ }
+
+ private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
+ if (mode == null)
+ throw new NullPointerException("mode must be non-null");
+ DisplayMode old_mode = current_mode;
+ current_mode = mode;
boolean was_fullscreen = isFullscreen();
Display.fullscreen = fullscreen;
- if (was_fullscreen != isFullscreen()) {
+ if (was_fullscreen != isFullscreen() || !mode.equals(old_mode)) {
if (!isCreated())
return;
destroyWindow();
Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java 2008-12-28 17:50:08 UTC (rev 3171)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java 2008-12-28 19:30:43 UTC (rev 3172)
@@ -74,13 +74,19 @@
mainLoop();
cleanup();
}
+
+ private void switchMode() throws LWJGLException {
+ mode = findDisplayMode(800, 600, Display.getDisplayMode().getBitsPerPixel());
+ Display.setDisplayModeAndFullscreen(mode);
+ }
+
/**
* Initializes the test
*/
private void initialize() {
try {
//find displaymode
- mode = findDisplayMode(800, 600, Display.getDisplayMode().getBitsPerPixel());
+ switchMode();
// start of in windowed mode
Display.create();
glInit();
@@ -163,7 +169,7 @@
//check for fullscreen key
if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
try {
- Display.setFullscreen(true);
+ switchMode();
} catch (Exception e) {
e.printStackTrace();
}
@@ -171,7 +177,9 @@
//check for window key
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
try {
- Display.setFullscreen(false);
+ mode = new DisplayMode(640, 480);
+ Display.setDisplayModeAndFullscreen(mode);
+ glInit();
} catch (Exception e) {
e.printStackTrace();
}
@@ -237,15 +245,10 @@
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
if (modes[i].getWidth() == width && modes[i].getHeight() == height && modes[i].getBitsPerPixel() >= bpp && modes[i].getFrequency() <= 60) {
- try {
- Display.setDisplayMode(modes[i]);
- } catch (LWJGLException e) {
- e.printStackTrace();
- }
return modes[i];
}
}
- return Display.getDisplayMode();
+ return Display.getDesktopDisplayMode();
}
/**
* Initializes OGL
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|