2004-11-25 17:31:38 -05:00
|
|
|
/*
|
2004-06-12 16:28:34 -04:00
|
|
|
* Copyright (c) 2002-2004 LWJGL Project
|
2004-02-04 17:06:18 -05:00
|
|
|
* All rights reserved.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2004-02-04 17:06:18 -05:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2004-11-25 17:31:38 -05:00
|
|
|
* modification, are permitted provided that the following conditions are
|
2004-02-04 17:06:18 -05:00
|
|
|
* met:
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
2004-02-04 17:06:18 -05:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions 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.
|
2003-03-27 17:32:48 -05:00
|
|
|
*
|
2004-11-25 17:31:38 -05:00
|
|
|
* * Neither the name of 'LWJGL' nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
2004-02-04 17:06:18 -05:00
|
|
|
* from this software without specific prior written permission.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2004-02-04 17:06:18 -05:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
2004-11-25 17:31:38 -05:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
2004-02-04 17:06:18 -05:00
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
2004-11-25 17:31:38 -05:00
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
2004-02-04 17:06:18 -05:00
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2003-08-04 06:09:40 -04:00
|
|
|
package org.lwjgl.opengl;
|
2003-03-27 17:32:48 -05:00
|
|
|
|
|
|
|
/**
|
2004-07-16 04:23:49 -04:00
|
|
|
* This is the abstract class for a Display in LWJGL. LWJGL displays have some
|
2003-03-27 17:32:48 -05:00
|
|
|
* peculiar characteristics:
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2004-07-16 04:23:49 -04:00
|
|
|
* - the display may be closeable by the user or operating system, and may be minimized
|
2003-03-27 17:32:48 -05:00
|
|
|
* by the user or operating system
|
2004-07-16 04:23:49 -04:00
|
|
|
* - only one display may ever be open at once
|
|
|
|
* - the operating system may or may not be able to do fullscreen or windowed displays.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2003-03-27 17:32:48 -05:00
|
|
|
* @author foo
|
|
|
|
*/
|
2003-08-04 06:09:40 -04:00
|
|
|
|
2005-07-05 17:54:12 -04:00
|
|
|
import java.nio.ByteBuffer;
|
2004-08-20 02:26:19 -04:00
|
|
|
import java.nio.FloatBuffer;
|
2005-05-30 12:21:05 -04:00
|
|
|
import java.security.AccessController;
|
|
|
|
import java.security.PrivilegedAction;
|
2006-01-16 16:04:49 -05:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
2005-05-30 12:21:05 -04:00
|
|
|
|
2004-08-20 02:26:19 -04:00
|
|
|
import org.lwjgl.BufferUtils;
|
|
|
|
import org.lwjgl.LWJGLException;
|
2005-03-29 13:09:33 -05:00
|
|
|
import org.lwjgl.LWJGLUtil;
|
2003-08-04 06:09:40 -04:00
|
|
|
import org.lwjgl.Sys;
|
2005-06-29 16:48:58 -04:00
|
|
|
import org.lwjgl.input.Controllers;
|
2004-03-26 06:01:34 -05:00
|
|
|
import org.lwjgl.input.Keyboard;
|
2004-03-21 16:54:57 -05:00
|
|
|
import org.lwjgl.input.Mouse;
|
2003-08-04 06:09:40 -04:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
public final class Display {
|
2003-03-27 17:32:48 -05:00
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
/** The display implementor */
|
2004-11-25 17:31:38 -05:00
|
|
|
private static final DisplayImplementation display_impl;
|
2004-07-03 09:13:54 -04:00
|
|
|
|
2004-07-21 12:06:30 -04:00
|
|
|
/** The initial display mode */
|
2004-11-25 17:31:38 -05:00
|
|
|
private static final DisplayMode initial_mode;
|
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
/** The current display mode, if created */
|
|
|
|
private static DisplayMode current_mode;
|
2003-09-29 05:26:20 -04:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/** Timer for sync() */
|
|
|
|
private static long timeNow, timeThen;
|
|
|
|
|
2004-09-15 13:07:06 -04:00
|
|
|
/** X coordinate of the window */
|
2004-12-27 16:38:50 -05:00
|
|
|
private static int x = -1;
|
2005-07-16 07:15:37 -04:00
|
|
|
|
|
|
|
/** Cached window icons, for when Display is recreated */
|
|
|
|
private static ByteBuffer[] cached_icons;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* Y coordinate of the window. Y in window coordinates is from the top of the display down,
|
|
|
|
* unlike GL, where it is typically at the bottom of the display.
|
|
|
|
*/
|
2004-12-27 16:38:50 -05:00
|
|
|
private static int y = -1;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2004-07-06 12:30:28 -04:00
|
|
|
/** Title of the window (never null) */
|
|
|
|
private static String title = "Game";
|
2003-08-03 18:05:40 -04:00
|
|
|
|
|
|
|
/** Fullscreen */
|
|
|
|
private static boolean fullscreen;
|
2004-07-03 13:39:25 -04:00
|
|
|
|
2006-01-01 14:50:06 -05:00
|
|
|
/** Swap interval */
|
|
|
|
private static int swap_interval;
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2003-11-03 06:23:56 -05:00
|
|
|
/** A unique context object, so we can track different contexts between creates() and destroys() */
|
2005-02-23 06:11:08 -05:00
|
|
|
private static PeerInfo peer_info;
|
2005-02-20 06:24:22 -05:00
|
|
|
private static Context context;
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2005-02-04 07:00:24 -05:00
|
|
|
private static boolean window_created = false;
|
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
static {
|
|
|
|
Sys.initialize();
|
|
|
|
display_impl = createDisplayImplementation();
|
2005-02-20 06:24:22 -05:00
|
|
|
try {
|
|
|
|
current_mode = initial_mode = display_impl.init();
|
2005-03-29 13:09:33 -05:00
|
|
|
LWJGLUtil.log("Initial mode: " + initial_mode);
|
2005-05-30 12:21:05 -04:00
|
|
|
AccessController.doPrivileged(new PrivilegedAction() {
|
|
|
|
public Object run() {
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
|
|
|
public void run() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return null;
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the Drawable from the Display.
|
|
|
|
*
|
|
|
|
* @return the Drawable corresponding to the Display context, or null it display is
|
|
|
|
* not created.
|
|
|
|
*/
|
|
|
|
public static Drawable getDrawable() {
|
|
|
|
if (context != null) {
|
|
|
|
return new Drawable() {
|
|
|
|
public Context getContext() {
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else
|
|
|
|
return null;
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-25 17:31:38 -05:00
|
|
|
private static DisplayImplementation createDisplayImplementation() {
|
2004-11-02 07:48:58 -05:00
|
|
|
String class_name;
|
2005-04-09 13:35:37 -04:00
|
|
|
switch (LWJGLUtil.getPlatform()) {
|
|
|
|
case LWJGLUtil.PLATFORM_LINUX:
|
2005-05-04 16:41:24 -04:00
|
|
|
class_name = "org.lwjgl.opengl.LinuxDisplay";
|
2005-04-09 13:35:37 -04:00
|
|
|
break;
|
|
|
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
2005-05-04 16:41:24 -04:00
|
|
|
class_name = "org.lwjgl.opengl.Win32Display";
|
2005-04-09 13:35:37 -04:00
|
|
|
break;
|
|
|
|
case LWJGLUtil.PLATFORM_MACOSX:
|
2005-05-04 16:41:24 -04:00
|
|
|
class_name = "org.lwjgl.opengl.MacOSXDisplay";
|
2005-04-09 13:35:37 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new IllegalStateException("Unsupported platform");
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
try {
|
|
|
|
Class display_class = Class.forName(class_name);
|
|
|
|
return (DisplayImplementation)display_class.newInstance();
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
} catch (InstantiationException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2003-11-03 06:23:56 -05:00
|
|
|
* Only constructed by ourselves
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
private Display() {
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
|
|
|
|
2004-04-03 18:01:39 -05:00
|
|
|
/**
|
2004-08-09 07:55:48 -04:00
|
|
|
* Returns the entire list of possible fullscreen display modes as an array, in no
|
2004-07-02 15:02:00 -04:00
|
|
|
* particular order. Any given mode is not guaranteed to be available and
|
|
|
|
* the only certain way to check is to call create() and make sure it works.
|
|
|
|
* Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32).
|
2004-08-09 07:55:48 -04:00
|
|
|
* Only DisplayModes from this call can be used when the Display is in fullscreen
|
|
|
|
* mode.
|
2004-07-02 15:02:00 -04:00
|
|
|
*
|
|
|
|
* @return an array of all display modes the system reckons it can handle.
|
2004-04-03 18:01:39 -05:00
|
|
|
*/
|
2005-02-20 06:24:22 -05:00
|
|
|
public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
2004-11-02 07:48:58 -05:00
|
|
|
DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes();
|
2004-07-02 15:02:00 -04:00
|
|
|
|
|
|
|
if (unfilteredModes == null) {
|
|
|
|
return new DisplayMode[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll use a HashSet to filter out the duplicated modes
|
|
|
|
HashSet modes = new HashSet(unfilteredModes.length);
|
|
|
|
|
|
|
|
modes.addAll(Arrays.asList(unfilteredModes));
|
|
|
|
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
|
|
|
|
modes.toArray(filteredModes);
|
|
|
|
|
2005-03-29 13:09:33 -05:00
|
|
|
LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
|
2004-07-02 15:02:00 -04:00
|
|
|
|
|
|
|
return filteredModes;
|
2004-04-03 18:01:39 -05:00
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
|
|
|
* Return the current display mode, as set by setDisplayMode().
|
|
|
|
* @return The current display mode
|
|
|
|
*/
|
|
|
|
public static DisplayMode getDisplayMode() {
|
|
|
|
return current_mode;
|
2004-04-03 18:01:39 -05:00
|
|
|
}
|
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2004-07-02 15:02:00 -04:00
|
|
|
* Set the current display mode. If no OpenGL context has been created, the given mode will apply to
|
|
|
|
* the context when create() is called, and no immediate mode switching will happen. If there is a
|
|
|
|
* context already, it will be resized according to the given mode. If the context is also a
|
2004-07-03 09:55:25 -04:00
|
|
|
* fullscreen context, the mode will also be switched immediately. The native cursor position
|
|
|
|
* is also reset.
|
2004-07-02 15:02:00 -04:00
|
|
|
*
|
|
|
|
* @param mode The new display mode to set
|
|
|
|
* @throws LWJGLException if the display mode could not be set
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
|
2004-07-03 09:02:45 -04:00
|
|
|
if (mode == null)
|
|
|
|
throw new NullPointerException("mode must be non-null");
|
2004-07-21 17:51:37 -04:00
|
|
|
current_mode = mode;
|
2004-07-02 15:02:00 -04:00
|
|
|
if (isCreated()) {
|
|
|
|
destroyWindow();
|
2005-02-04 07:00:24 -05:00
|
|
|
// If mode is not fullscreen capable, make sure we are in windowed mode
|
|
|
|
if (!mode.isFullscreen())
|
|
|
|
resetFullscreen();
|
2004-07-21 12:06:30 -04:00
|
|
|
try {
|
2004-07-21 17:51:37 -04:00
|
|
|
if (fullscreen)
|
2004-08-09 07:55:48 -04:00
|
|
|
switchDisplayMode();
|
2004-07-21 12:06:30 -04:00
|
|
|
createWindow();
|
|
|
|
} catch (LWJGLException e) {
|
2005-02-20 06:24:22 -05:00
|
|
|
destroyContext();
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2004-07-21 12:06:30 -04:00
|
|
|
throw e;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2004-07-02 15:02:00 -04:00
|
|
|
* Create the native window peer from the given mode and fullscreen flag.
|
|
|
|
* A native context must exist, and it will be attached to the window.
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
private static void createWindow() throws LWJGLException {
|
2005-05-04 16:41:24 -04:00
|
|
|
if (window_created) {
|
|
|
|
return;
|
|
|
|
}
|
2005-01-14 07:29:19 -05:00
|
|
|
int window_x;
|
|
|
|
int window_y;
|
|
|
|
if (!fullscreen) {
|
|
|
|
// if no display location set, center window
|
|
|
|
if (x == -1 && y == -1) {
|
|
|
|
window_x = Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
|
|
|
|
window_y = Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
|
|
|
|
} else {
|
|
|
|
window_x = x;
|
|
|
|
window_y = y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window_x = 0;
|
|
|
|
window_y = 0;
|
2005-01-06 09:22:25 -05:00
|
|
|
}
|
2005-01-14 07:29:19 -05:00
|
|
|
display_impl.createWindow(current_mode, fullscreen, window_x, window_y);
|
|
|
|
makeCurrent();
|
2005-01-14 04:24:59 -05:00
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
setTitle(title);
|
2004-07-02 15:02:00 -04:00
|
|
|
initControls();
|
2006-01-01 14:50:06 -05:00
|
|
|
setSwapInterval(swap_interval);
|
2005-02-04 07:00:24 -05:00
|
|
|
window_created = true;
|
2005-07-16 07:15:37 -04:00
|
|
|
|
|
|
|
// set cached window icon if exists
|
|
|
|
if(cached_icons != null) {
|
|
|
|
setIcon(cached_icons);
|
2005-10-21 14:53:21 -04:00
|
|
|
} else {
|
|
|
|
setIcon(new ByteBuffer[] { LWJGLUtil.LWJGLIcon16x16, LWJGLUtil.LWJGLIcon32x32 });
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void destroyWindow() {
|
2005-05-04 16:41:24 -04:00
|
|
|
if (!window_created) {
|
|
|
|
return;
|
|
|
|
}
|
2005-02-23 06:11:08 -05:00
|
|
|
try {
|
2005-05-04 16:41:24 -04:00
|
|
|
if (context.isCurrent()) {
|
2006-06-07 02:35:52 -04:00
|
|
|
context.releaseDrawable();
|
2005-05-04 16:41:24 -04:00
|
|
|
Context.releaseCurrentContext();
|
|
|
|
}
|
2005-02-23 06:11:08 -05:00
|
|
|
} catch (LWJGLException e) {
|
2006-06-07 02:35:52 -04:00
|
|
|
LWJGLUtil.log("Exception occurred while trying to release context: " + e);
|
2005-02-23 06:11:08 -05:00
|
|
|
}
|
|
|
|
|
2005-05-04 16:41:24 -04:00
|
|
|
// Automatically destroy keyboard & mouse
|
2004-07-03 09:55:25 -04:00
|
|
|
if (Mouse.isCreated()) {
|
2004-07-02 15:02:00 -04:00
|
|
|
Mouse.destroy();
|
|
|
|
}
|
2004-07-03 09:55:25 -04:00
|
|
|
if (Keyboard.isCreated()) {
|
2004-07-02 15:02:00 -04:00
|
|
|
Keyboard.destroy();
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.destroyWindow();
|
2005-02-04 07:00:24 -05:00
|
|
|
window_created = false;
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
|
|
|
|
2004-08-09 07:55:48 -04:00
|
|
|
private static void switchDisplayMode() throws LWJGLException {
|
2005-05-04 16:41:24 -04:00
|
|
|
if (!current_mode.isFullscreen()) {
|
|
|
|
System.out.println("Switching to "+initial_mode);
|
|
|
|
setDisplayMode(initial_mode);
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.switchDisplayMode(current_mode);
|
2004-08-09 07:55:48 -04:00
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
|
|
|
* Set the display configuration to the specified gamma, brightness and contrast.
|
2004-07-21 12:06:30 -04:00
|
|
|
* The configuration changes will be reset when destroy() is called.
|
2004-07-02 15:02:00 -04:00
|
|
|
*
|
|
|
|
* @param gamma The gamma value
|
|
|
|
* @param brightness The brightness value between -1.0 and 1.0, inclusive
|
|
|
|
* @param contrast The contrast, larger than 0.0.
|
|
|
|
*/
|
|
|
|
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException {
|
2004-07-06 12:30:28 -04:00
|
|
|
if (!isCreated()) {
|
|
|
|
throw new LWJGLException("Display not yet created.");
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
if (brightness < -1.0f || brightness > 1.0f)
|
|
|
|
throw new IllegalArgumentException("Invalid brightness value");
|
|
|
|
if (contrast < 0.0f)
|
|
|
|
throw new IllegalArgumentException("Invalid contrast value");
|
2004-11-02 07:48:58 -05:00
|
|
|
int rampSize = display_impl.getGammaRampLength();
|
2004-07-02 15:02:00 -04:00
|
|
|
if (rampSize == 0) {
|
|
|
|
throw new LWJGLException("Display configuration not supported");
|
|
|
|
}
|
2004-07-29 07:41:11 -04:00
|
|
|
FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
|
2004-07-02 15:02:00 -04:00
|
|
|
for (int i = 0; i < rampSize; i++) {
|
|
|
|
float intensity = (float)i/(rampSize - 1);
|
|
|
|
// apply gamma
|
|
|
|
float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
|
|
|
|
// apply brightness
|
|
|
|
rampEntry += brightness;
|
|
|
|
// apply contrast
|
|
|
|
rampEntry = (rampEntry - 0.5f)*contrast + 0.5f;
|
|
|
|
// Clamp entry to [0, 1]
|
|
|
|
if (rampEntry > 1.0f)
|
|
|
|
rampEntry = 1.0f;
|
|
|
|
else if (rampEntry < 0.0f)
|
|
|
|
rampEntry = 0.0f;
|
|
|
|
gammaRamp.put(i, rampEntry);
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.setGammaRamp(gammaRamp);
|
2005-03-29 13:09:33 -05:00
|
|
|
LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
2004-07-06 12:30:28 -04:00
|
|
|
* Synchronize the display to a capped frame rate. Note that we are being "smart" about the
|
|
|
|
* desired results in our implementation; we automatically subtract 1 from the desired framerate
|
|
|
|
* to prevent just missing the frame time if vsync is set.
|
2004-07-02 15:02:00 -04:00
|
|
|
* @param fps The desired frame rate, in frames per second
|
|
|
|
*/
|
2005-04-09 12:45:14 -04:00
|
|
|
public static void sync3(int fps) {
|
2006-04-21 07:11:21 -04:00
|
|
|
float frameTime = 1.0f / (fps > 1 ? fps - 1 : 1);
|
2004-07-02 15:02:00 -04:00
|
|
|
timeNow = Sys.getTime();
|
|
|
|
while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameTime) {
|
|
|
|
// This is a system-friendly way of allowing other stuff to use CPU if it wants to
|
|
|
|
Thread.yield();
|
|
|
|
timeNow = Sys.getTime();
|
|
|
|
}
|
|
|
|
timeThen = timeNow;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
|
|
|
private static long timeLate;
|
|
|
|
|
2004-07-09 07:20:14 -04:00
|
|
|
/**
|
|
|
|
* Alternative sync method which works better on triple-buffered GL displays.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2004-07-09 07:20:14 -04:00
|
|
|
* @param fps The desired frame rate, in frames per second
|
|
|
|
*/
|
|
|
|
public static void sync2(int fps) {
|
2004-11-07 12:26:45 -05:00
|
|
|
long gapTo = Sys.getTimerResolution() / fps + timeThen;
|
2004-07-09 07:20:14 -04:00
|
|
|
timeNow = Sys.getTime();
|
|
|
|
|
|
|
|
while (gapTo > timeNow + timeLate) {
|
|
|
|
Thread.yield();
|
|
|
|
timeNow = Sys.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gapTo < timeNow)
|
|
|
|
timeLate = timeNow - gapTo;
|
|
|
|
else
|
|
|
|
timeLate = 0;
|
|
|
|
|
|
|
|
timeThen = timeNow;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2005-04-09 12:45:14 -04:00
|
|
|
/**
|
|
|
|
* Best sync method that works reliably.
|
|
|
|
*
|
|
|
|
* @param fps The desired frame rate, in frames per second
|
|
|
|
*/
|
|
|
|
public static void sync(int fps) {
|
|
|
|
long gapTo = Sys.getTimerResolution() / fps + timeThen;
|
|
|
|
timeNow = Sys.getTime();
|
|
|
|
|
|
|
|
while (gapTo > timeNow + timeLate) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(1);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
|
|
|
timeNow = Sys.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gapTo < timeNow)
|
|
|
|
timeLate = timeNow - gapTo;
|
|
|
|
else
|
|
|
|
timeLate = 0;
|
|
|
|
|
|
|
|
timeThen = timeNow;
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
|
|
|
* @return the X coordinate of the window (always 0 for fullscreen)
|
|
|
|
*/
|
2004-09-15 13:07:06 -04:00
|
|
|
/*public static int getX() {
|
|
|
|
return (fullscreen) ? 0 : x;
|
|
|
|
}*/
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
|
|
|
* @return the Y coordinate of the window (always 0 for fullscreen)
|
|
|
|
*/
|
2004-09-15 13:07:06 -04:00
|
|
|
/*public static int getY() {
|
|
|
|
return (fullscreen) ? 0 : y;
|
|
|
|
}*/
|
|
|
|
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* @return the title of the window
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static String getTitle() {
|
2003-03-27 17:32:48 -05:00
|
|
|
return title;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2005-02-04 07:00:24 -05:00
|
|
|
private static void resetFullscreen() {
|
|
|
|
if (Display.fullscreen) {
|
|
|
|
Display.fullscreen = false;
|
|
|
|
display_impl.resetDisplayMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
|
|
|
* Set the fullscreen mode of the context. If no context has been created through create(),
|
|
|
|
* the mode will apply when create() is called. If fullscreen is true, the context will become
|
|
|
|
* a fullscreen context and the display mode is switched to the mode given by getDisplayMode(). If
|
|
|
|
* fullscreen is false, the context will become a windowed context with the dimensions given in the
|
2004-07-03 09:55:25 -04:00
|
|
|
* mode returned by getDisplayMode(). The native cursor position is also reset.
|
2004-07-02 15:02:00 -04:00
|
|
|
*
|
|
|
|
* @param fullscreen Specify the fullscreen mode of the context.
|
2004-08-09 07:55:48 -04:00
|
|
|
* @throws LWJGLException If fullscreen is true, and the current DisplayMode instance is not
|
|
|
|
* from getAvailableDisplayModes() or if the mode switch fails.
|
2004-07-02 15:02:00 -04:00
|
|
|
*/
|
|
|
|
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
|
|
|
|
if (Display.fullscreen != fullscreen) {
|
|
|
|
Display.fullscreen = fullscreen;
|
2004-07-03 12:41:38 -04:00
|
|
|
if (!isCreated())
|
2004-07-02 15:02:00 -04:00
|
|
|
return;
|
|
|
|
destroyWindow();
|
|
|
|
try {
|
2004-09-15 13:07:06 -04:00
|
|
|
if (fullscreen) {
|
2004-08-09 07:55:48 -04:00
|
|
|
switchDisplayMode();
|
2004-09-22 15:25:16 -04:00
|
|
|
} else {
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2004-09-22 15:25:16 -04:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
createWindow();
|
|
|
|
} catch (LWJGLException e) {
|
2005-02-20 06:24:22 -05:00
|
|
|
destroyContext();
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2004-07-02 15:02:00 -04:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-26 09:59:50 -04:00
|
|
|
/**
|
2004-07-02 15:02:00 -04:00
|
|
|
* @return whether the Display is in fullscreen mode
|
2003-09-26 09:59:50 -04:00
|
|
|
*/
|
|
|
|
public static boolean isFullscreen() {
|
|
|
|
return fullscreen;
|
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* Set the title of the window. This may be ignored by the underlying OS.
|
|
|
|
* @param newTitle The new window title
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static void setTitle(String newTitle) {
|
2004-07-06 12:30:28 -04:00
|
|
|
if (newTitle == null) {
|
|
|
|
newTitle = "";
|
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
title = newTitle;
|
2004-07-03 06:16:28 -04:00
|
|
|
if (isCreated())
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.setTitle(title);
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-07-28 06:09:58 -04:00
|
|
|
/**
|
|
|
|
* @return true if the user or operating system has asked the window to close
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isCloseRequested() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine close requested state of uncreated window");
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.update();
|
|
|
|
return display_impl.isCloseRequested();
|
2003-07-28 06:09:58 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2004-04-04 08:53:45 -04:00
|
|
|
* @return true if the window is visible, false if not
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-04-04 08:53:45 -04:00
|
|
|
public static boolean isVisible() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine minimized state of uncreated window");
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.update();
|
|
|
|
return display_impl.isVisible();
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-07-28 06:09:58 -04:00
|
|
|
/**
|
2004-04-04 08:53:45 -04:00
|
|
|
* @return true if window is active, that is, the foreground display of the operating system.
|
2003-07-28 06:09:58 -04:00
|
|
|
*/
|
2004-04-04 08:53:45 -04:00
|
|
|
public static boolean isActive() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine focused state of uncreated window");
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.update();
|
|
|
|
return display_impl.isActive();
|
2003-07-28 06:09:58 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* Determine if the window's contents have been damaged by external events.
|
|
|
|
* If you are writing a straightforward game rendering loop and simply paint
|
|
|
|
* every frame regardless, you can ignore this flag altogether. If you are
|
|
|
|
* trying to be kind to other processes you can check this flag and only
|
2004-04-04 10:10:19 -04:00
|
|
|
* redraw when it returns true. The flag is cleared when update() or isDirty() is called.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2003-03-27 17:32:48 -05:00
|
|
|
* @return true if the window has been damaged by external changes
|
|
|
|
* and needs to repaint itself
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isDirty() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine dirty state of uncreated window");
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.update();
|
|
|
|
return display_impl.isDirty();
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2004-11-02 13:15:39 -05:00
|
|
|
* Process operating system events. Call this to update the Display's state and make sure the
|
|
|
|
* input devices receive events. This method is called from update(), and should normally not be called by
|
|
|
|
* the application.
|
|
|
|
*/
|
|
|
|
public static void processMessages() {
|
|
|
|
if (!isCreated())
|
2006-05-03 16:53:16 -04:00
|
|
|
throw new IllegalStateException("Display not created");
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-02 13:15:39 -05:00
|
|
|
display_impl.update();
|
|
|
|
}
|
|
|
|
|
2006-05-03 16:53:16 -04:00
|
|
|
/**
|
|
|
|
* Swap the display buffers. This method is called from update(), and should normally not be called by
|
|
|
|
* the application.
|
|
|
|
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
|
|
|
|
*/
|
|
|
|
public static void swapBuffers() throws LWJGLException {
|
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Display not created");
|
|
|
|
|
|
|
|
Util.checkGLError();
|
|
|
|
Context.swapBuffers();
|
|
|
|
}
|
|
|
|
|
2004-11-02 13:15:39 -05:00
|
|
|
/**
|
|
|
|
* Update the window. This calls processMessages(), and if the window is visible
|
2006-05-03 16:53:16 -04:00
|
|
|
* clears the dirty flag and calls swapBuffers() and finally polls the input devices.
|
2004-03-26 06:01:34 -05:00
|
|
|
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-03-26 06:01:34 -05:00
|
|
|
public static void update() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
2006-05-03 16:53:16 -04:00
|
|
|
throw new IllegalStateException("Display not created");
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-04-04 09:39:10 -04:00
|
|
|
// We paint only when the window is visible or dirty
|
|
|
|
if (isVisible() || isDirty()) {
|
2005-02-20 06:24:22 -05:00
|
|
|
try {
|
2006-05-03 16:53:16 -04:00
|
|
|
swapBuffers();
|
2005-02-20 06:24:22 -05:00
|
|
|
} catch (LWJGLException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-02 13:15:39 -05:00
|
|
|
processMessages();
|
2004-04-04 09:39:10 -04:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
// Poll the input devices while we're here
|
|
|
|
if (Mouse.isCreated()) {
|
|
|
|
Mouse.poll();
|
|
|
|
Mouse.updateCursor();
|
|
|
|
}
|
2005-06-29 16:48:58 -04:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
if (Keyboard.isCreated()) {
|
|
|
|
Keyboard.poll();
|
|
|
|
}
|
2005-06-29 16:48:58 -04:00
|
|
|
|
|
|
|
if(Controllers.isCreated()) {
|
|
|
|
Controllers.poll();
|
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-03-30 14:26:39 -05:00
|
|
|
|
2004-02-18 12:48:26 -05:00
|
|
|
/**
|
2006-01-02 08:49:36 -05:00
|
|
|
* Release the Display context.
|
|
|
|
*
|
|
|
|
* @throws LWJGLException If the context could not be released
|
|
|
|
*/
|
2006-01-02 09:15:24 -05:00
|
|
|
public static void releaseContext() throws LWJGLException {
|
2006-01-02 08:49:36 -05:00
|
|
|
if (!isCreated())
|
2006-01-02 09:05:30 -05:00
|
|
|
throw new IllegalStateException("Display is not created");
|
2006-01-02 08:49:36 -05:00
|
|
|
if (context.isCurrent())
|
|
|
|
Context.releaseCurrentContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the Display the current rendering context for GL calls.
|
|
|
|
*
|
2004-07-03 17:12:33 -04:00
|
|
|
* @throws LWJGLException If the context could not be made current
|
2004-02-18 12:48:26 -05:00
|
|
|
*/
|
2004-07-29 11:45:45 -04:00
|
|
|
public static void makeCurrent() throws LWJGLException {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
2006-01-02 09:05:30 -05:00
|
|
|
throw new IllegalStateException("Display is not created");
|
2005-02-20 06:24:22 -05:00
|
|
|
context.makeCurrent();
|
2004-02-18 12:48:26 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
/**
|
2004-07-02 15:02:00 -04:00
|
|
|
* Create the OpenGL context. If isFullscreen() is true or if windowed
|
|
|
|
* context are not supported on the platform, the display mode will be switched to the mode returned by
|
|
|
|
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
|
|
|
|
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
|
|
|
|
* created with the given parameters, a LWJGLException will be thrown.
|
|
|
|
*
|
2004-03-26 06:09:39 -05:00
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
2004-07-02 15:02:00 -04:00
|
|
|
*
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException
|
2004-03-26 06:01:34 -05:00
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
public static void create() throws LWJGLException {
|
|
|
|
create(new PixelFormat());
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
/**
|
2004-07-02 15:02:00 -04:00
|
|
|
* Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed
|
|
|
|
* context are not supported on the platform, the display mode will be switched to the mode returned by
|
|
|
|
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
|
|
|
|
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
|
|
|
|
* created with the given parameters, a LWJGLException will be thrown.
|
|
|
|
*
|
2004-03-26 06:09:39 -05:00
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
2004-07-02 15:02:00 -04:00
|
|
|
*
|
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill.
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
public static void create(PixelFormat pixel_format) throws LWJGLException {
|
2005-02-20 06:24:22 -05:00
|
|
|
create(pixel_format, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if windowed
|
|
|
|
* context are not supported on the platform, the display mode will be switched to the mode returned by
|
|
|
|
* getDisplayMode(), and a fullscreen context will be created. If isFullscreen() is false, a windowed context
|
|
|
|
* will be created with the dimensions given in the mode returned by getDisplayMode(). If a context can't be
|
|
|
|
* created with the given parameters, a LWJGLException will be thrown.
|
|
|
|
*
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill.
|
2005-06-16 16:59:55 -04:00
|
|
|
* @param shared_drawable The Drawable to share context with or null.
|
2005-02-20 06:24:22 -05:00
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException {
|
2004-04-04 09:01:53 -04:00
|
|
|
if (isCreated())
|
2004-07-02 15:02:00 -04:00
|
|
|
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
|
2005-06-16 16:59:55 -04:00
|
|
|
if (pixel_format == null)
|
|
|
|
throw new NullPointerException("pixel_format cannot be null");
|
2004-07-02 15:02:00 -04:00
|
|
|
if (fullscreen)
|
2004-08-09 07:55:48 -04:00
|
|
|
switchDisplayMode();
|
2004-07-02 15:02:00 -04:00
|
|
|
try {
|
2005-02-23 06:11:08 -05:00
|
|
|
peer_info = display_impl.createPeerInfo(pixel_format);
|
2005-02-20 06:24:22 -05:00
|
|
|
context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null);
|
2004-07-05 10:34:47 -04:00
|
|
|
try {
|
2005-02-20 06:24:22 -05:00
|
|
|
createWindow();
|
|
|
|
initContext();
|
2004-07-05 10:34:47 -04:00
|
|
|
} catch (LWJGLException e) {
|
2005-02-20 06:24:22 -05:00
|
|
|
destroyContext();
|
2004-07-05 10:34:47 -04:00
|
|
|
throw e;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
} catch (LWJGLException e) {
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2004-07-03 12:07:00 -04:00
|
|
|
throw e;
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
private static void initContext() {
|
2004-03-26 06:09:39 -05:00
|
|
|
// Put the window into orthographic projection mode with 1:1 pixel ratio.
|
|
|
|
// We haven't used GLU here to do this to avoid an unnecessary dependency.
|
|
|
|
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
|
|
|
GL11.glLoadIdentity();
|
2006-04-21 07:11:21 -04:00
|
|
|
GL11.glOrtho(0.0, current_mode.getWidth(), 0.0, current_mode.getHeight(), -1.0, 1.0);
|
2004-03-26 06:09:39 -05:00
|
|
|
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
|
|
|
GL11.glLoadIdentity();
|
2004-07-02 15:02:00 -04:00
|
|
|
GL11.glViewport(0, 0, current_mode.getWidth(), current_mode.getHeight());
|
|
|
|
}
|
2004-03-26 06:09:39 -05:00
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
public static DisplayImplementation getImplementation() {
|
|
|
|
return display_impl;
|
|
|
|
}
|
|
|
|
|
2005-05-30 12:21:05 -04:00
|
|
|
/**
|
|
|
|
* Gets a boolean property as a privileged action.
|
|
|
|
*/
|
2006-07-02 16:26:49 -04:00
|
|
|
private static boolean getPrivilegedBoolean(final String property_name) {
|
2005-05-30 12:21:05 -04:00
|
|
|
Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() {
|
|
|
|
public Object run() {
|
|
|
|
return new Boolean(Boolean.getBoolean(property_name));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return value.booleanValue();
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
private static void initControls() {
|
2004-03-26 06:01:34 -05:00
|
|
|
// Automatically create mouse, keyboard and controller
|
2005-05-30 12:21:05 -04:00
|
|
|
if (!getPrivilegedBoolean("org.lwjgl.opengl.Display.noinput")) {
|
|
|
|
if (!Mouse.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nomouse")) {
|
2004-04-03 16:05:57 -05:00
|
|
|
try {
|
|
|
|
Mouse.create();
|
|
|
|
} catch (LWJGLException e) {
|
2005-03-29 13:09:33 -05:00
|
|
|
if (LWJGLUtil.DEBUG) {
|
2004-04-03 16:05:57 -05:00
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
2005-03-29 13:09:33 -05:00
|
|
|
LWJGLUtil.log("Failed to create Mouse: "+e);
|
2004-04-03 16:05:57 -05:00
|
|
|
}
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
|
|
|
}
|
2005-05-30 12:21:05 -04:00
|
|
|
if (!Keyboard.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nokeyboard")) {
|
2004-04-03 16:05:57 -05:00
|
|
|
try {
|
|
|
|
Keyboard.create();
|
|
|
|
} catch (LWJGLException e) {
|
2005-03-29 13:09:33 -05:00
|
|
|
if (LWJGLUtil.DEBUG) {
|
2004-04-03 16:05:57 -05:00
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
2005-03-29 13:09:33 -05:00
|
|
|
LWJGLUtil.log("Failed to create Keyboard: "+e);
|
2004-04-03 16:05:57 -05:00
|
|
|
}
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-04 19:00:49 -04:00
|
|
|
}
|
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2004-07-02 15:02:00 -04:00
|
|
|
* Destroy the Display. After this call, there will be no current GL rendering context,
|
|
|
|
* regardless of whether the Display was the current rendering context.
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-07-29 11:45:45 -04:00
|
|
|
public static void destroy() {
|
2004-07-02 15:02:00 -04:00
|
|
|
if (!isCreated()) {
|
2003-03-28 14:02:24 -05:00
|
|
|
return;
|
2004-02-18 12:48:26 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
destroyWindow();
|
2005-02-20 06:24:22 -05:00
|
|
|
destroyContext();
|
|
|
|
x = y = -1;
|
2005-07-16 07:15:37 -04:00
|
|
|
cached_icons = null;
|
2005-02-20 06:24:22 -05:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void destroyContext() {
|
2004-07-03 17:12:33 -04:00
|
|
|
try {
|
2005-02-20 06:24:22 -05:00
|
|
|
context.forceDestroy();
|
2005-02-23 06:11:08 -05:00
|
|
|
peer_info.destroy();
|
2004-07-03 17:12:33 -04:00
|
|
|
} catch (LWJGLException e) {
|
2005-02-20 06:24:22 -05:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
} finally {
|
|
|
|
context = null;
|
2004-07-03 17:12:33 -04:00
|
|
|
}
|
2004-07-03 13:39:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-07-19 03:32:13 -04:00
|
|
|
* Reset display mode if fullscreen. This method is also called from the shutdown hook added
|
|
|
|
* in the static constructor
|
2004-07-03 13:39:25 -04:00
|
|
|
*/
|
|
|
|
private static void reset() {
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2004-11-01 18:13:30 -05:00
|
|
|
current_mode = initial_mode;
|
2003-11-03 06:23:56 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2003-11-03 06:23:56 -05:00
|
|
|
/**
|
2004-07-21 17:51:37 -04:00
|
|
|
* @return the unique Display context (or null, if the Display has not been created)
|
2003-11-03 06:23:56 -05:00
|
|
|
*/
|
2005-02-20 06:24:22 -05:00
|
|
|
public static Context getContext() {
|
2003-11-03 06:23:56 -05:00
|
|
|
return context;
|
2003-03-27 17:46:25 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 18:01:14 -05:00
|
|
|
/**
|
2003-03-28 14:02:24 -05:00
|
|
|
* @return true if the window's native peer has been created
|
2003-03-27 18:01:14 -05:00
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isCreated() {
|
2004-02-18 12:48:26 -05:00
|
|
|
return context != null;
|
2003-03-27 18:01:14 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2006-01-01 14:50:06 -05:00
|
|
|
/**
|
|
|
|
* Set the buffer swap interval. This call is a best-attempt at changing
|
|
|
|
* the monitor swap interval, which is the minimum periodicity of color buffer swaps,
|
|
|
|
* measured in video frame periods, and is not guaranteed to be successful.
|
|
|
|
*
|
|
|
|
* A video frame period is the time required to display a full frame of video data.
|
|
|
|
*
|
|
|
|
* @param sync true to synchronize; false to ignore synchronization
|
|
|
|
*/
|
|
|
|
public static void setSwapInterval(int value) {
|
|
|
|
swap_interval = value;
|
|
|
|
if (isCreated())
|
|
|
|
Context.setSwapInterval(swap_interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-20 10:17:47 -04:00
|
|
|
/**
|
|
|
|
* Enable or disable vertical monitor synchronization. This call is a best-attempt at changing
|
|
|
|
* the vertical refresh synchronization of the monitor, and is not guaranteed to be successful.
|
|
|
|
* @param sync true to synchronize; false to ignore synchronization
|
|
|
|
*/
|
|
|
|
public static void setVSyncEnabled(boolean sync) {
|
2006-01-01 14:50:06 -05:00
|
|
|
setSwapInterval(sync ? 1 : 0);
|
2003-10-20 10:17:47 -04:00
|
|
|
}
|
|
|
|
|
2004-09-15 13:07:06 -04:00
|
|
|
/**
|
|
|
|
* Set the window's location. This is a no-op on fullscreen windows.
|
|
|
|
* The window is clamped to remain entirely on the screen. If you attempt
|
|
|
|
* to position the window such that it would extend off the screen, the window
|
|
|
|
* is simply placed as close to the edge as possible.
|
2004-12-27 16:38:50 -05:00
|
|
|
* <br><b>note</b>If no location has been specified (or x == y == -1) the window will be centered
|
|
|
|
* @param x The new window location on the x axis
|
|
|
|
* @param y The new window location on the y axis
|
2004-09-15 13:07:06 -04:00
|
|
|
*/
|
|
|
|
public static void setLocation(int x, int y) {
|
|
|
|
if (fullscreen) {
|
|
|
|
return;
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
|
|
|
|
// offset if already created
|
|
|
|
if(isCreated()) {
|
|
|
|
display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
// cache position
|
|
|
|
Display.x = x;
|
2004-11-25 17:31:38 -05:00
|
|
|
Display.y = y;
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
/**
|
|
|
|
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
|
|
|
|
* "Radeon9700". If the adapter cannot be determined, this function returns null.
|
|
|
|
* @return a String
|
|
|
|
*/
|
|
|
|
public static String getAdapter() {
|
|
|
|
return display_impl.getAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined,
|
|
|
|
* this function returns null.
|
|
|
|
* @return a String
|
|
|
|
*/
|
|
|
|
public static String getVersion() {
|
|
|
|
return display_impl.getVersion();
|
|
|
|
}
|
2005-07-05 17:54:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets one or more icons for the Display.
|
|
|
|
* <ul>
|
|
|
|
* <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li>
|
|
|
|
* <li>Linux (and similar platforms) expect one 32x32 icon.</li>
|
|
|
|
* <li>Mac OS X should be supplied one 128x128 icon</li>
|
|
|
|
* </ul>
|
|
|
|
* The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform.
|
2005-07-16 07:15:37 -04:00
|
|
|
* <p>
|
|
|
|
* <b>NOTE:</b> The display will make a deep copy of the supplied byte buffer array, for the purpose
|
|
|
|
* of recreating the icons when you go back and forth fullscreen mode. You therefore only need to
|
|
|
|
* set the icon once per instance.
|
2005-07-05 17:54:12 -04:00
|
|
|
*
|
|
|
|
* @param icons Array of icons in RGBA mode
|
2005-07-16 07:15:37 -04:00
|
|
|
* @return number of icons used, or 0 if display hasn't been created
|
2005-07-05 17:54:12 -04:00
|
|
|
*/
|
|
|
|
public static int setIcon(ByteBuffer[] icons) {
|
2005-07-16 07:15:37 -04:00
|
|
|
|
|
|
|
// make deep copy so we dont rely on the supplied buffers later on
|
2005-10-21 14:53:21 -04:00
|
|
|
// don't recache!
|
|
|
|
if(cached_icons != icons) {
|
|
|
|
cached_icons = new ByteBuffer[icons.length];
|
|
|
|
for(int i=0;i<icons.length; i++) {
|
|
|
|
cached_icons[i] = BufferUtils.createByteBuffer(icons[i].capacity());
|
|
|
|
cached_icons[i].put(icons[i]);
|
|
|
|
cached_icons[i].flip();
|
|
|
|
}
|
2005-07-16 07:15:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(Display.isCreated()) {
|
|
|
|
return display_impl.setIcon(cached_icons);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-05 17:54:12 -04:00
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|