2004-11-25 17:31:38 -05:00
|
|
|
/*
|
2008-04-07 14:36:09 -04:00
|
|
|
* Copyright (c) 2002-2008 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
|
|
|
|
2013-04-17 15:19:38 -04:00
|
|
|
import org.lwjgl.BufferUtils;
|
|
|
|
import org.lwjgl.LWJGLException;
|
|
|
|
import org.lwjgl.LWJGLUtil;
|
|
|
|
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
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.ComponentAdapter;
|
|
|
|
import java.awt.event.ComponentEvent;
|
|
|
|
import java.awt.event.ComponentListener;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.FloatBuffer;
|
|
|
|
import java.security.AccessController;
|
|
|
|
import java.security.PrivilegedAction;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
public final class Display {
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2006-10-26 15:41:15 -04:00
|
|
|
private static final Thread shutdown_hook = new Thread() {
|
2008-08-19 12:46:03 -04:00
|
|
|
public void run() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
};
|
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;
|
|
|
|
|
2008-04-06 16:56:52 -04:00
|
|
|
/** The parent, if any */
|
|
|
|
private static Canvas parent;
|
|
|
|
|
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-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;
|
2008-08-19 12:46:03 -04:00
|
|
|
|
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;
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
/** the width of the Display window */
|
|
|
|
private static int width = 0;
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
/** the height of the Display window */
|
|
|
|
private static int height = 0;
|
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
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
/** The Drawable instance that tracks the current Display context */
|
2011-05-17 12:53:57 -04:00
|
|
|
private static DrawableLWJGL drawable;
|
2007-02-12 07:18:26 -05:00
|
|
|
|
2010-04-22 19:21:48 -04:00
|
|
|
private static boolean window_created;
|
2005-02-04 07:00:24 -05:00
|
|
|
|
2008-04-07 15:21:40 -04:00
|
|
|
private static boolean parent_resized;
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
private static boolean window_resized;
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
private static boolean window_resizable;
|
2010-04-03 15:03:49 -04:00
|
|
|
|
2009-12-01 10:12:52 -05:00
|
|
|
/** Initial Background Color of Display */
|
2010-09-28 17:11:35 -04:00
|
|
|
private static float r, g, b;
|
2008-04-07 15:21:40 -04:00
|
|
|
|
2010-09-28 17:11:35 -04:00
|
|
|
private static final ComponentListener component_listener = new ComponentAdapter() {
|
2008-08-19 12:46:03 -04:00
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
|
synchronized ( GlobalLock.lock ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
parent_resized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-02-20 06:24:22 -05:00
|
|
|
} catch (LWJGLException e) {
|
|
|
|
throw new RuntimeException(e);
|
2007-02-12 07:18:26 -05:00
|
|
|
};
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the Drawable from the Display.
|
|
|
|
*
|
2007-02-12 07:18:26 -05:00
|
|
|
* @return the Drawable corresponding to the Display context
|
2005-02-20 06:24:22 -05:00
|
|
|
*/
|
|
|
|
public static Drawable getDrawable() {
|
2007-02-12 07:18:26 -05:00
|
|
|
return drawable;
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
|
|
|
|
2004-11-25 17:31:38 -05:00
|
|
|
private static DisplayImplementation createDisplayImplementation() {
|
2008-08-19 12:46:03 -04:00
|
|
|
switch ( LWJGLUtil.getPlatform() ) {
|
2005-04-09 13:35:37 -04:00
|
|
|
case LWJGLUtil.PLATFORM_LINUX:
|
2007-01-17 07:58:38 -05:00
|
|
|
return new LinuxDisplay();
|
2005-04-09 13:35:37 -04:00
|
|
|
case LWJGLUtil.PLATFORM_WINDOWS:
|
2007-01-17 07:58:38 -05:00
|
|
|
return new WindowsDisplay();
|
2005-04-09 13:35:37 -04:00
|
|
|
case LWJGLUtil.PLATFORM_MACOSX:
|
2007-01-17 07:58:38 -05:00
|
|
|
return new MacOSXDisplay();
|
2005-04-09 13:35:37 -04:00
|
|
|
default:
|
|
|
|
throw new IllegalStateException("Unsupported platform");
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** Only constructed by ourselves */
|
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
|
2007-01-22 05:14:13 -05:00
|
|
|
* particular order. Although best attempts to filter out invalid modes are done, any
|
|
|
|
* given mode is not guaranteed to be available nor is it guaranteed to be within the
|
|
|
|
* current monitor specs (this is especially a problem with the frequency parameter).
|
|
|
|
* Furthermore, it is not guaranteed that create() will detect an illegal display mode.
|
2008-08-19 12:46:03 -04:00
|
|
|
* <p/>
|
2007-01-22 05:14:13 -05:00
|
|
|
* The only certain way to check
|
|
|
|
* is to call create() and make sure it works.
|
2004-07-02 15:02:00 -04:00
|
|
|
* 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 {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes();
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( unfilteredModes == null ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
return new DisplayMode[0];
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
// We'll use a HashSet to filter out the duplicated modes
|
2010-09-28 17:11:35 -04:00
|
|
|
HashSet<DisplayMode> modes = new HashSet<DisplayMode>(unfilteredModes.length);
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
modes.addAll(Arrays.asList(unfilteredModes));
|
|
|
|
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
|
|
|
|
modes.toArray(filteredModes);
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
return filteredModes;
|
|
|
|
}
|
2004-04-03 18:01:39 -05:00
|
|
|
}
|
|
|
|
|
2008-10-02 03:34:22 -04:00
|
|
|
/**
|
|
|
|
* Return the initial desktop display mode.
|
|
|
|
*
|
|
|
|
* @return The desktop display mode
|
|
|
|
*/
|
|
|
|
public static DisplayMode getDesktopDisplayMode() {
|
2008-10-02 04:10:47 -04:00
|
|
|
return initial_mode;
|
2008-10-02 03:34:22 -04:00
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
/**
|
|
|
|
* Return the current display mode, as set by setDisplayMode().
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2004-07-02 15:02:00 -04:00
|
|
|
* @return The current display mode
|
|
|
|
*/
|
|
|
|
public static DisplayMode getDisplayMode() {
|
2008-10-02 04:10:47 -04:00
|
|
|
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
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2004-07-02 15:02:00 -04:00
|
|
|
* @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 {
|
2010-04-22 19:21:48 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( mode == null )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new NullPointerException("mode must be non-null");
|
2008-10-02 04:10:47 -04:00
|
|
|
boolean was_fullscreen = isFullscreen();
|
2007-02-12 07:18:26 -05:00
|
|
|
current_mode = mode;
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( isCreated() ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
destroyWindow();
|
|
|
|
// If mode is not fullscreen capable, make sure we are in windowed mode
|
|
|
|
try {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( was_fullscreen && !isFullscreen() )
|
2008-10-02 04:10:47 -04:00
|
|
|
display_impl.resetDisplayMode();
|
2012-11-01 16:54:17 -04:00
|
|
|
else if ( isFullscreen() )
|
2007-02-12 07:18:26 -05:00
|
|
|
switchDisplayMode();
|
|
|
|
createWindow();
|
2007-04-28 16:10:21 -04:00
|
|
|
makeCurrentAndSetSwapInterval();
|
2007-02-12 07:18:26 -05:00
|
|
|
} catch (LWJGLException e) {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.destroy();
|
2007-02-12 07:18:26 -05:00
|
|
|
display_impl.resetDisplayMode();
|
|
|
|
throw e;
|
|
|
|
}
|
2004-07-21 12:06:30 -04:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2008-04-07 15:21:40 -04:00
|
|
|
private static DisplayMode getEffectiveMode() {
|
2011-10-11 15:24:55 -04:00
|
|
|
return !isFullscreen() && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode;
|
2008-04-07 15:21:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private static int getWindowX() {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( !isFullscreen() && parent == null ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
// if no display location set, center window
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( x == -1 ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
|
|
|
|
} else {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int getWindowY() {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( !isFullscreen() && parent == null ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
// if no display location set, center window
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( y == -1 ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
|
|
|
|
} else {
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( window_created ) {
|
2005-05-04 16:41:24 -04:00
|
|
|
return;
|
|
|
|
}
|
2008-10-02 04:10:47 -04:00
|
|
|
Canvas tmp_parent = isFullscreen() ? null : parent;
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( tmp_parent != null && !tmp_parent.isDisplayable() ) // Only a best effort check, since the parent can turn undisplayable hereafter
|
2008-04-06 16:56:52 -04:00
|
|
|
throw new LWJGLException("Parent.isDisplayable() must be true");
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( tmp_parent != null ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
tmp_parent.addComponentListener(component_listener);
|
|
|
|
}
|
|
|
|
DisplayMode mode = getEffectiveMode();
|
2011-05-17 12:53:57 -04:00
|
|
|
display_impl.createWindow(drawable, mode, tmp_parent, getWindowX(), getWindowY());
|
2006-09-19 09:41:18 -04:00
|
|
|
window_created = true;
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
width = Display.getDisplayMode().getWidth();
|
|
|
|
height = Display.getDisplayMode().getHeight();
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2004-11-02 07:48:58 -05:00
|
|
|
setTitle(title);
|
2004-07-02 15:02:00 -04:00
|
|
|
initControls();
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-07-16 07:15:37 -04:00
|
|
|
// set cached window icon if exists
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( cached_icons != null ) {
|
2005-07-16 07:15:37 -04:00
|
|
|
setIcon(cached_icons);
|
2005-10-21 14:53:21 -04:00
|
|
|
} else {
|
2006-07-22 17:30:31 -04:00
|
|
|
setIcon(new ByteBuffer[] { LWJGLUtil.LWJGLIcon32x32, LWJGLUtil.LWJGLIcon16x16 });
|
2005-10-21 14:53:21 -04:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
|
|
|
|
2008-04-13 14:11:38 -04:00
|
|
|
private static void releaseDrawable() {
|
2005-02-23 06:11:08 -05:00
|
|
|
try {
|
2011-05-17 12:53:57 -04:00
|
|
|
Context context = drawable.getContext();
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( context != null && context.isCurrent() ) {
|
2011-05-17 12:53:57 -04:00
|
|
|
context.releaseCurrent();
|
2007-08-30 14:27:12 -04:00
|
|
|
context.releaseDrawable();
|
2005-05-04 16:41:24 -04:00
|
|
|
}
|
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
|
|
|
}
|
2008-04-13 14:11:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void destroyWindow() {
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( !window_created ) {
|
2008-04-13 14:11:38 -04:00
|
|
|
return;
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( parent != null ) {
|
2008-04-13 14:11:38 -04:00
|
|
|
parent.removeComponentListener(component_listener);
|
|
|
|
}
|
|
|
|
releaseDrawable();
|
2005-02-23 06:11:08 -05:00
|
|
|
|
2005-05-04 16:41:24 -04:00
|
|
|
// Automatically destroy keyboard & mouse
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( Mouse.isCreated() ) {
|
2004-07-02 15:02:00 -04:00
|
|
|
Mouse.destroy();
|
|
|
|
}
|
2008-08-19 12:46:03 -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 {
|
2008-12-28 12:50:08 -05:00
|
|
|
if ( !current_mode.isFullscreenCapable() ) {
|
2007-08-16 04:55:06 -04:00
|
|
|
throw new IllegalStateException("Only modes acquired from getAvailableDisplayModes() can be used for fullscreen display");
|
2005-05-04 16:41:24 -04:00
|
|
|
}
|
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
|
|
|
*
|
2008-08-19 12:46:03 -04:00
|
|
|
* @param gamma The gamma value
|
2004-07-02 15:02:00 -04:00
|
|
|
* @param brightness The brightness value between -1.0 and 1.0, inclusive
|
2008-08-19 12:46:03 -04:00
|
|
|
* @param contrast The contrast, larger than 0.0.
|
2004-07-02 15:02:00 -04:00
|
|
|
*/
|
|
|
|
public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new LWJGLException("Display not yet created.");
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( brightness < -1.0f || brightness > 1.0f )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalArgumentException("Invalid brightness value");
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( contrast < 0.0f )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalArgumentException("Invalid contrast value");
|
|
|
|
int rampSize = display_impl.getGammaRampLength();
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( rampSize == 0 ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new LWJGLException("Display configuration not supported");
|
|
|
|
}
|
|
|
|
FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
|
2008-08-19 12:46:03 -04:00
|
|
|
for ( int i = 0; i < rampSize; i++ ) {
|
|
|
|
float intensity = (float)i / (rampSize - 1);
|
2007-02-12 07:18:26 -05:00
|
|
|
// apply gamma
|
|
|
|
float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
|
|
|
|
// apply brightness
|
|
|
|
rampEntry += brightness;
|
|
|
|
// apply contrast
|
2008-08-19 12:46:03 -04:00
|
|
|
rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
|
2007-02-12 07:18:26 -05:00
|
|
|
// Clamp entry to [0, 1]
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( rampEntry > 1.0f )
|
2007-02-12 07:18:26 -05:00
|
|
|
rampEntry = 1.0f;
|
2008-08-19 12:46:03 -04:00
|
|
|
else if ( rampEntry < 0.0f )
|
2007-02-12 07:18:26 -05:00
|
|
|
rampEntry = 0.0f;
|
|
|
|
gammaRamp.put(i, rampEntry);
|
|
|
|
}
|
|
|
|
display_impl.setGammaRamp(gammaRamp);
|
|
|
|
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
|
|
|
|
2005-04-09 12:45:14 -04:00
|
|
|
/**
|
2012-03-23 20:20:02 -04:00
|
|
|
* An accurate sync method that will attempt to run at a constant frame rate.
|
2012-03-23 20:04:52 -04:00
|
|
|
* It should be called once every frame.
|
2013-01-29 15:53:11 -05:00
|
|
|
*
|
2012-03-23 20:04:52 -04:00
|
|
|
* @param fps - the desired frame rate, in frames per second
|
2005-04-09 12:45:14 -04:00
|
|
|
*/
|
|
|
|
public static void sync(int fps) {
|
2012-03-23 20:04:52 -04:00
|
|
|
Sync.sync(fps);
|
2012-02-29 18:18:35 -05:00
|
|
|
}
|
2007-08-30 08:34:56 -04:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** @return the title of the window */
|
2003-08-02 13:11:33 -04:00
|
|
|
public static String getTitle() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
return title;
|
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** Return the last parent set with setParent(). */
|
2008-04-06 16:56:52 -04:00
|
|
|
public static Canvas getParent() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2008-04-06 16:56:52 -04:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the parent of the Display. If parent is null, the Display will appear as a top level window.
|
|
|
|
* If parent is not null, the Display is made a child of the parent. A parent's isDisplayable() must be true when
|
|
|
|
* setParent() is called and remain true until setParent() is called again with
|
|
|
|
* null or a different parent. This generally means that the parent component must remain added to it's parent container.<p>
|
|
|
|
* It is not advisable to call this method from an AWT thread, since the context will be made current on the thread
|
|
|
|
* and it is difficult to predict which AWT thread will process any given AWT event.<p>
|
2008-04-07 16:39:46 -04:00
|
|
|
* While the Display is in fullscreen mode, the current parent will be ignored. Additionally, when a non null parent is specified,
|
|
|
|
* the Dispaly will inherit the size of the parent, disregarding the currently set display mode.<p>
|
2008-04-06 16:56:52 -04:00
|
|
|
*/
|
|
|
|
public static void setParent(Canvas parent) throws LWJGLException {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( Display.parent != parent ) {
|
2008-04-06 16:56:52 -04:00
|
|
|
Display.parent = parent;
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( !isCreated() )
|
2008-04-06 16:56:52 -04:00
|
|
|
return;
|
|
|
|
destroyWindow();
|
|
|
|
try {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( isFullscreen() ) {
|
2008-04-06 16:56:52 -04:00
|
|
|
switchDisplayMode();
|
|
|
|
} else {
|
|
|
|
display_impl.resetDisplayMode();
|
|
|
|
}
|
|
|
|
createWindow();
|
|
|
|
makeCurrentAndSetSwapInterval();
|
|
|
|
} catch (LWJGLException e) {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.destroy();
|
2008-04-06 16:56:52 -04:00
|
|
|
display_impl.resetDisplayMode();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2004-08-09 07:55:48 -04:00
|
|
|
* @throws LWJGLException If fullscreen is true, and the current DisplayMode instance is not
|
2008-08-19 12:46:03 -04:00
|
|
|
* from getAvailableDisplayModes() or if the mode switch fails.
|
2004-07-02 15:02:00 -04:00
|
|
|
*/
|
|
|
|
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
|
2008-12-28 14:30:43 -05:00
|
|
|
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 {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( mode == null )
|
2008-12-28 14:30:43 -05:00
|
|
|
throw new NullPointerException("mode must be non-null");
|
|
|
|
DisplayMode old_mode = current_mode;
|
|
|
|
current_mode = mode;
|
2008-10-02 04:10:47 -04:00
|
|
|
boolean was_fullscreen = isFullscreen();
|
|
|
|
Display.fullscreen = fullscreen;
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( was_fullscreen != isFullscreen() || !mode.equals(old_mode) ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
return;
|
|
|
|
destroyWindow();
|
|
|
|
try {
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( isFullscreen() ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
switchDisplayMode();
|
|
|
|
} else {
|
|
|
|
display_impl.resetDisplayMode();
|
|
|
|
}
|
|
|
|
createWindow();
|
2007-04-28 16:10:21 -04:00
|
|
|
makeCurrentAndSetSwapInterval();
|
2007-02-12 07:18:26 -05:00
|
|
|
} catch (LWJGLException e) {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.destroy();
|
2004-11-02 07:48:58 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2007-02-12 07:18:26 -05:00
|
|
|
throw e;
|
2004-09-22 15:25:16 -04:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** @return whether the Display is in fullscreen mode */
|
2003-09-26 09:59:50 -04:00
|
|
|
public static boolean isFullscreen() {
|
2010-04-22 19:21:48 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2008-12-28 12:50:08 -05:00
|
|
|
return fullscreen && current_mode.isFullscreenCapable();
|
2007-02-12 07:18:26 -05:00
|
|
|
}
|
2003-09-26 09:59:50 -04:00
|
|
|
}
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2003-03-27 17:32:48 -05:00
|
|
|
* @param newTitle The new window title
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static void setTitle(String newTitle) {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( newTitle == null ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
newTitle = "";
|
|
|
|
}
|
|
|
|
title = newTitle;
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
display_impl.setTitle(title);
|
2004-07-06 12:30:28 -04:00
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2008-08-19 12:46:03 -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() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Cannot determine close requested state of uncreated window");
|
|
|
|
return display_impl.isCloseRequested();
|
|
|
|
}
|
2003-07-28 06:09:58 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** @return true if the window is visible, false if not */
|
2004-04-04 08:53:45 -04:00
|
|
|
public static boolean isVisible() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Cannot determine minimized state of uncreated window");
|
|
|
|
return display_impl.isVisible();
|
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** @return true if window is active, that is, the foreground display of the operating system. */
|
2004-04-04 08:53:45 -04:00
|
|
|
public static boolean isActive() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Cannot determine focused state of uncreated window");
|
|
|
|
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
|
2008-08-19 12:46:03 -04:00
|
|
|
* and needs to repaint itself
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isDirty() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Cannot determine dirty state of uncreated window");
|
|
|
|
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
|
|
|
/**
|
2008-03-02 13:16:39 -05:00
|
|
|
* Process operating system events. Call this to update the Display's state and to receive new
|
|
|
|
* input device events. This method is called from update(), so it is not necessary to call
|
|
|
|
* this method if update() is called periodically.
|
2004-11-02 13:15:39 -05:00
|
|
|
*/
|
|
|
|
public static void processMessages() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Display not created");
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
display_impl.update();
|
|
|
|
}
|
2010-03-31 19:56:24 -04:00
|
|
|
pollDevices();
|
2004-11-02 13:15:39 -05:00
|
|
|
}
|
|
|
|
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2010-09-28 17:11:35 -04:00
|
|
|
* @throws OpenGLException if an OpenGL error has occured since the last call to glGetError()
|
2006-05-03 16:53:16 -04:00
|
|
|
*/
|
|
|
|
public static void swapBuffers() throws LWJGLException {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Display not created");
|
2006-05-03 16:53:16 -04:00
|
|
|
|
2009-09-08 08:27:59 -04:00
|
|
|
if ( LWJGLUtil.DEBUG )
|
2011-05-17 12:53:57 -04:00
|
|
|
drawable.checkGLError();
|
|
|
|
drawable.swapBuffers();
|
2007-02-12 07:18:26 -05:00
|
|
|
}
|
2006-05-03 16:53:16 -04:00
|
|
|
}
|
|
|
|
|
2004-11-02 13:15:39 -05:00
|
|
|
/**
|
2010-04-03 15:03:49 -04:00
|
|
|
* Update the window. If the window is visible clears
|
|
|
|
* the dirty flag and calls swapBuffers() and finally
|
|
|
|
* polls the input devices.
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-03-26 06:01:34 -05:00
|
|
|
public static void update() {
|
2010-04-03 15:03:49 -04:00
|
|
|
update(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the window. If the window is visible clears
|
|
|
|
* the dirty flag and calls swapBuffers() and finally
|
|
|
|
* polls the input devices if processMessages is true.
|
|
|
|
*
|
|
|
|
* @param processMessages Poll input devices if true
|
|
|
|
*/
|
|
|
|
public static void update(boolean processMessages) {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Display not created");
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
// We paint only when the window is visible or dirty
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( display_impl.isVisible() || display_impl.isDirty() ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
try {
|
|
|
|
swapBuffers();
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
window_resized = !isFullscreen() && parent == null && display_impl.wasResized();
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
if ( window_resized ) {
|
|
|
|
width = display_impl.getWidth();
|
|
|
|
height = display_impl.getHeight();
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( parent_resized ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
reshape();
|
|
|
|
parent_resized = false;
|
2012-05-13 14:01:12 -04:00
|
|
|
window_resized = true;
|
2008-04-07 15:21:40 -04:00
|
|
|
}
|
2010-04-03 15:03:49 -04:00
|
|
|
|
|
|
|
if ( processMessages )
|
|
|
|
processMessages();
|
2007-02-12 07:18:26 -05:00
|
|
|
}
|
2006-10-26 15:41:15 -04:00
|
|
|
}
|
2004-04-04 09:39:10 -04:00
|
|
|
|
2006-10-26 15:41:15 -04:00
|
|
|
static void pollDevices() {
|
2004-03-26 06:01:34 -05:00
|
|
|
// Poll the input devices while we're here
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( Mouse.isCreated() ) {
|
2004-03-26 06:01:34 -05:00
|
|
|
Mouse.poll();
|
|
|
|
Mouse.updateCursor();
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
|
|
|
if ( Keyboard.isCreated() ) {
|
2004-03-26 06:01:34 -05:00
|
|
|
Keyboard.poll();
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
|
|
|
if ( Controllers.isCreated() ) {
|
2005-06-29 16:48:58 -04:00
|
|
|
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 {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.releaseContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns true if the Display's context is current in the current thread. */
|
|
|
|
public static boolean isCurrent() throws LWJGLException {
|
|
|
|
return drawable.isCurrent();
|
2006-01-02 08:49:36 -05:00
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2006-01-02 08:49:36 -05:00
|
|
|
/**
|
|
|
|
* 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 {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.makeCurrent();
|
2004-02-18 12:48:26 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
private static void removeShutdownHook() {
|
2010-09-28 17:11:35 -04:00
|
|
|
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
2008-08-19 12:46:03 -04:00
|
|
|
public Object run() {
|
|
|
|
Runtime.getRuntime().removeShutdownHook(shutdown_hook);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void registerShutdownHook() {
|
2010-09-28 17:11:35 -04:00
|
|
|
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
2008-08-19 12:46:03 -04:00
|
|
|
public Object run() {
|
|
|
|
Runtime.getRuntime().addShutdownHook(shutdown_hook);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-07-10 13:45:43 -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.
|
|
|
|
* <p/>
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
public static void create() throws LWJGLException {
|
2011-10-12 14:54:40 -04:00
|
|
|
create(new PixelFormat());
|
2011-07-10 13:45:43 -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.
|
2008-08-19 12:46:03 -04:00
|
|
|
* <p/>
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2004-07-02 15:02:00 -04:00
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
public static void create(PixelFormat pixel_format) throws LWJGLException {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2011-10-12 14:54:40 -04:00
|
|
|
create(pixel_format, null, (ContextAttribs)null);
|
2007-02-12 07:18:26 -05:00
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -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.
|
|
|
|
* <p/>
|
|
|
|
* <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.
|
|
|
|
* @param shared_drawable The Drawable to share context with. (optional, may be null)
|
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException {
|
|
|
|
synchronized ( GlobalLock.lock ) {
|
2011-10-12 14:54:40 -04:00
|
|
|
create(pixel_format, shared_drawable, (ContextAttribs)null);
|
2008-08-19 12:46:03 -04:00
|
|
|
}
|
2006-11-19 06:43:00 -05:00
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -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.
|
|
|
|
* <p/>
|
|
|
|
* <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.
|
|
|
|
* @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
|
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
public static void create(PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException {
|
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
create(pixel_format, null, attribs);
|
|
|
|
}
|
2006-11-19 06:43:00 -05:00
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05: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.
|
2008-08-19 12:46:03 -04:00
|
|
|
* <p/>
|
2005-02-20 06:24:22 -05:00
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
2008-08-19 12:46:03 -04:00
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill.
|
|
|
|
* @param shared_drawable The Drawable to share context with. (optional, may be null)
|
|
|
|
* @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
|
|
|
|
*
|
2005-02-20 06:24:22 -05:00
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
2008-08-19 12:46:03 -04:00
|
|
|
public static void create(PixelFormat pixel_format, Drawable shared_drawable, ContextAttribs attribs) throws LWJGLException {
|
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( isCreated() )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( pixel_format == null )
|
2007-02-12 07:18:26 -05:00
|
|
|
throw new NullPointerException("pixel_format cannot be null");
|
|
|
|
removeShutdownHook();
|
|
|
|
registerShutdownHook();
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( isFullscreen() )
|
2007-02-12 07:18:26 -05:00
|
|
|
switchDisplayMode();
|
2011-05-17 12:53:57 -04:00
|
|
|
|
|
|
|
final DrawableGL drawable = new DrawableGL() {
|
|
|
|
public void destroy() {
|
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
releaseDrawable();
|
|
|
|
super.destroy();
|
|
|
|
destroyWindow();
|
|
|
|
x = y = -1;
|
|
|
|
cached_icons = null;
|
|
|
|
reset();
|
|
|
|
removeShutdownHook();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Display.drawable = drawable;
|
|
|
|
|
|
|
|
try {
|
2011-09-03 14:52:45 -04:00
|
|
|
drawable.setPixelFormat(pixel_format, attribs);
|
2011-05-17 12:53:57 -04:00
|
|
|
try {
|
|
|
|
createWindow();
|
|
|
|
try {
|
|
|
|
drawable.context = new ContextGL(drawable.peer_info, attribs, shared_drawable != null ? ((DrawableGL)shared_drawable).getContext() : null);
|
|
|
|
try {
|
|
|
|
makeCurrentAndSetSwapInterval();
|
|
|
|
initContext();
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
drawable.destroy();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
destroyWindow();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
drawable.destroy();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
display_impl.resetDisplayMode();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the OpenGL ES 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/>
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
2011-10-12 14:54:40 -04:00
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
|
2011-05-17 12:53:57 -04:00
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
|
|
|
|
2011-10-12 14:54:40 -04:00
|
|
|
public static void create(PixelFormatLWJGL pixel_format) throws LWJGLException {
|
2011-05-17 12:53:57 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
create(pixel_format, null, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-12 14:54:40 -04:00
|
|
|
* Create the OpenGL ES context with the given minimum parameters. If isFullscreen() is true or if windowed
|
2011-05-17 12:53:57 -04:00
|
|
|
* 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/>
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
2011-10-12 14:54:40 -04:00
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
|
2011-05-17 12:53:57 -04:00
|
|
|
* @param shared_drawable The Drawable to share context with. (optional, may be null)
|
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
2011-10-12 14:54:40 -04:00
|
|
|
public static void create(PixelFormatLWJGL pixel_format, Drawable shared_drawable) throws LWJGLException {
|
2011-05-17 12:53:57 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
create(pixel_format, shared_drawable, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-12 14:54:40 -04:00
|
|
|
* Create the OpenGL ES context with the given minimum parameters. If isFullscreen() is true or if windowed
|
2011-05-17 12:53:57 -04:00
|
|
|
* 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/>
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
2011-10-12 14:54:40 -04:00
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
|
2011-05-17 12:53:57 -04:00
|
|
|
* @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
|
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
2011-10-12 14:54:40 -04:00
|
|
|
public static void create(PixelFormatLWJGL pixel_format, org.lwjgl.opengles.ContextAttribs attribs) throws LWJGLException {
|
2011-05-17 12:53:57 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
create(pixel_format, null, attribs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the OpenGL ES 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/>
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
*
|
2011-10-12 14:54:40 -04:00
|
|
|
* @param pixel_format Describes the minimum specifications the context must fulfill. Must be an instance of org.lwjgl.opengles.PixelFormat.
|
2011-05-17 12:53:57 -04:00
|
|
|
* @param shared_drawable The Drawable to share context with. (optional, may be null)
|
|
|
|
* @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
|
|
|
|
*
|
|
|
|
* @throws LWJGLException
|
|
|
|
*/
|
2011-10-12 14:54:40 -04:00
|
|
|
public static void create(PixelFormatLWJGL pixel_format, Drawable shared_drawable, org.lwjgl.opengles.ContextAttribs attribs) throws LWJGLException {
|
2011-05-17 12:53:57 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( isCreated() )
|
|
|
|
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
|
|
|
|
if ( pixel_format == null )
|
|
|
|
throw new NullPointerException("pixel_format cannot be null");
|
|
|
|
removeShutdownHook();
|
|
|
|
registerShutdownHook();
|
|
|
|
if ( isFullscreen() )
|
|
|
|
switchDisplayMode();
|
|
|
|
|
|
|
|
final DrawableGLES drawable = new DrawableGLES() {
|
2011-09-03 14:52:45 -04:00
|
|
|
|
|
|
|
public void setPixelFormat(final PixelFormatLWJGL pf, final ContextAttribs attribs) throws LWJGLException {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2011-05-17 12:53:57 -04:00
|
|
|
public void destroy() {
|
|
|
|
synchronized ( GlobalLock.lock ) {
|
|
|
|
if ( !isCreated() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
releaseDrawable();
|
|
|
|
super.destroy();
|
|
|
|
destroyWindow();
|
|
|
|
x = y = -1;
|
|
|
|
cached_icons = null;
|
|
|
|
reset();
|
|
|
|
removeShutdownHook();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Display.drawable = drawable;
|
|
|
|
|
2004-07-05 10:34:47 -04:00
|
|
|
try {
|
2011-05-17 12:53:57 -04:00
|
|
|
drawable.setPixelFormat(pixel_format);
|
2006-09-19 09:41:18 -04:00
|
|
|
try {
|
2007-02-12 07:18:26 -05:00
|
|
|
createWindow();
|
2006-09-19 09:41:18 -04:00
|
|
|
try {
|
2011-05-17 12:53:57 -04:00
|
|
|
drawable.createContext(attribs, shared_drawable);
|
2007-02-12 07:18:26 -05:00
|
|
|
try {
|
2007-04-28 16:10:21 -04:00
|
|
|
makeCurrentAndSetSwapInterval();
|
2007-02-12 07:18:26 -05:00
|
|
|
initContext();
|
|
|
|
} catch (LWJGLException e) {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.destroy();
|
2007-02-12 07:18:26 -05:00
|
|
|
throw e;
|
|
|
|
}
|
2006-09-19 09:41:18 -04:00
|
|
|
} catch (LWJGLException e) {
|
2007-02-12 07:18:26 -05:00
|
|
|
destroyWindow();
|
2006-09-19 09:41:18 -04:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
} catch (LWJGLException e) {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.destroy();
|
2006-09-19 09:41:18 -04:00
|
|
|
throw e;
|
|
|
|
}
|
2004-07-05 10:34:47 -04:00
|
|
|
} catch (LWJGLException e) {
|
2007-02-12 07:18:26 -05:00
|
|
|
display_impl.resetDisplayMode();
|
2004-07-05 10:34:47 -04:00
|
|
|
throw e;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
}
|
2010-04-03 15:03:49 -04:00
|
|
|
|
2009-12-01 10:12:52 -05:00
|
|
|
/**
|
2010-04-22 19:21:48 -04:00
|
|
|
* Set the initial color of the Display. This method is called before the Display is created and will set the
|
|
|
|
* background color to the one specified in this method.
|
|
|
|
*
|
|
|
|
* @param red - color value between 0 - 1
|
|
|
|
* @param green - color value between 0 - 1
|
|
|
|
* @param blue - color value between 0 - 1
|
|
|
|
*/
|
2009-12-01 10:12:52 -05:00
|
|
|
public static void setInitialBackground(float red, float green, float blue) {
|
|
|
|
r = red;
|
|
|
|
g = green;
|
|
|
|
b = blue;
|
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2007-04-28 16:10:21 -04:00
|
|
|
private static void makeCurrentAndSetSwapInterval() throws LWJGLException {
|
|
|
|
makeCurrent();
|
2010-02-10 06:22:16 -05:00
|
|
|
try {
|
2011-05-17 12:53:57 -04:00
|
|
|
drawable.checkGLError();
|
2010-02-10 06:22:16 -05:00
|
|
|
} catch (OpenGLException e) {
|
|
|
|
LWJGLUtil.log("OpenGL error during context creation: " + e.getMessage());
|
|
|
|
}
|
2006-09-19 09:41:18 -04:00
|
|
|
setSwapInterval(swap_interval);
|
2007-04-28 16:10:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void initContext() {
|
2011-05-17 12:53:57 -04:00
|
|
|
drawable.initContext(r, g, b);
|
2007-01-04 09:12:36 -05:00
|
|
|
update();
|
2004-07-02 15:02:00 -04:00
|
|
|
}
|
2004-03-26 06:09:39 -05:00
|
|
|
|
2006-10-08 05:05:16 -04:00
|
|
|
static DisplayImplementation getImplementation() {
|
2004-11-02 07:48:58 -05:00
|
|
|
return display_impl;
|
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** Gets a boolean property as a privileged action. */
|
2006-07-02 18:45:56 -04:00
|
|
|
static boolean getPrivilegedBoolean(final String property_name) {
|
2010-09-28 17:11:35 -04:00
|
|
|
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
|
|
|
public Boolean run() {
|
|
|
|
return Boolean.getBoolean(property_name);
|
2005-05-30 12:21:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-27 11:07:07 -04:00
|
|
|
|
|
|
|
/** Gets a string property as a privileged action. */
|
|
|
|
static String getPrivilegedString(final String property_name) {
|
|
|
|
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
|
|
|
public String run() {
|
|
|
|
return System.getProperty(property_name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
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
|
2008-08-19 12:46:03 -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) {
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( LWJGLUtil.DEBUG ) {
|
2004-04-03 16:05:57 -05:00
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
2008-08-19 12:46:03 -04:00
|
|
|
LWJGLUtil.log("Failed to create Mouse: " + e);
|
2004-04-03 16:05:57 -05:00
|
|
|
}
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
|
|
|
}
|
2008-08-19 12:46:03 -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) {
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( LWJGLUtil.DEBUG ) {
|
2004-04-03 16:05:57 -05:00
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
2008-08-19 12:46:03 -04: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() {
|
2011-10-18 13:23:39 -04:00
|
|
|
if(isCreated()) {
|
|
|
|
drawable.destroy();
|
|
|
|
}
|
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
|
|
|
*/
|
2010-04-22 19:21:48 -04:00
|
|
|
|
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
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
/** @return true if the window's native peer has been created */
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isCreated() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
return window_created;
|
|
|
|
}
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
* <p/>
|
2006-01-01 14:50:06 -05:00
|
|
|
* A video frame period is the time required to display a full frame of video data.
|
|
|
|
*
|
2008-01-21 17:15:12 -05:00
|
|
|
* @param value The swap interval in frames, 0 to disable
|
2006-01-01 14:50:06 -05:00
|
|
|
*/
|
|
|
|
public static void setSwapInterval(int value) {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
swap_interval = value;
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( isCreated() )
|
2011-05-17 12:53:57 -04:00
|
|
|
drawable.setSwapInterval(swap_interval);
|
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
}
|
2006-01-01 14:50:06 -05:00
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2003-10-20 10:17:47 -04:00
|
|
|
* @param sync true to synchronize; false to ignore synchronization
|
|
|
|
*/
|
|
|
|
public static void setVSyncEnabled(boolean sync) {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
setSwapInterval(sync ? 1 : 0);
|
|
|
|
}
|
2003-10-20 10:17:47 -04:00
|
|
|
}
|
|
|
|
|
2004-09-15 13:07:06 -04:00
|
|
|
/**
|
2008-04-06 16:56:52 -04:00
|
|
|
* Set the window's location. This is a no-op on fullscreen windows or when getParent() != null.
|
2004-09-15 13:07:06 -04:00
|
|
|
* 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.
|
2008-01-21 17:15:12 -05:00
|
|
|
* <br><b>note</b>If no location has been specified (or x == y == -1) the window will be centered
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2008-01-21 17:15:12 -05:00
|
|
|
* @param new_x The new window location on the x axis
|
|
|
|
* @param new_y The new window location on the y axis
|
2004-09-15 13:07:06 -04:00
|
|
|
*/
|
2007-02-12 07:18:26 -05:00
|
|
|
public static void setLocation(int new_x, int new_y) {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
// cache position
|
|
|
|
x = new_x;
|
|
|
|
y = new_y;
|
2004-11-02 07:48:58 -05:00
|
|
|
|
2007-02-12 07:18:26 -05:00
|
|
|
// offset if already created
|
2010-04-22 19:21:48 -04:00
|
|
|
if ( isCreated() && !isFullscreen() ) {
|
2008-04-07 15:21:40 -04:00
|
|
|
reshape();
|
2007-02-12 07:18:26 -05:00
|
|
|
}
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2008-04-07 15:21:40 -04:00
|
|
|
private static void reshape() {
|
|
|
|
DisplayMode mode = getEffectiveMode();
|
|
|
|
display_impl.reshape(getWindowX(), getWindowY(), mode.getWidth(), mode.getHeight());
|
|
|
|
}
|
|
|
|
|
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.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2004-11-02 07:48:58 -05:00
|
|
|
* @return a String
|
|
|
|
*/
|
|
|
|
public static String getAdapter() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
return display_impl.getAdapter();
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined,
|
|
|
|
* this function returns null.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
2004-11-02 07:48:58 -05:00
|
|
|
* @return a String
|
|
|
|
*/
|
|
|
|
public static String getVersion() {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
return display_impl.getVersion();
|
|
|
|
}
|
2004-11-02 07:48:58 -05:00
|
|
|
}
|
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>
|
2013-11-09 14:47:32 -05:00
|
|
|
* The implementation will use the supplied ByteBuffers with image data in RGBA (size must be a power of two) and perform any conversions nescesarry for the specific platform.
|
2008-08-19 12:46:03 -04:00
|
|
|
* <p/>
|
2005-07-16 07:15:37 -04:00
|
|
|
* <b>NOTE:</b> The display will make a deep copy of the supplied byte buffer array, for the purpose
|
2008-08-19 12:46:03 -04:00
|
|
|
* of recreating the icons when you go back and forth fullscreen mode. You therefore only need to
|
2005-07-16 07:15:37 -04:00
|
|
|
* set the icon once per instance.
|
2005-07-05 17:54:12 -04:00
|
|
|
*
|
2006-07-22 17:30:31 -04:00
|
|
|
* @param icons Array of icons in RGBA mode. Pass the icons in order of preference.
|
2008-08-19 12:46:03 -04:00
|
|
|
*
|
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) {
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( GlobalLock.lock ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
// make deep copy so we dont rely on the supplied buffers later on
|
|
|
|
// don't recache!
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( cached_icons != icons ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
cached_icons = new ByteBuffer[icons.length];
|
2008-08-19 12:46:03 -04:00
|
|
|
for ( int i = 0; i < icons.length; i++ ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
cached_icons[i] = BufferUtils.createByteBuffer(icons[i].capacity());
|
2008-06-16 14:29:18 -04:00
|
|
|
int old_position = icons[i].position();
|
2007-02-12 07:18:26 -05:00
|
|
|
cached_icons[i].put(icons[i]);
|
2008-06-16 14:29:18 -04:00
|
|
|
icons[i].position(old_position);
|
2007-02-12 07:18:26 -05:00
|
|
|
cached_icons[i].flip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( Display.isCreated() && parent == null ) {
|
2007-02-12 07:18:26 -05:00
|
|
|
return display_impl.setIcon(cached_icons);
|
|
|
|
} else {
|
|
|
|
return 0;
|
2005-10-21 14:53:21 -04:00
|
|
|
}
|
2005-07-16 07:15:37 -04:00
|
|
|
}
|
2005-07-05 17:54:12 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-12 18:07:32 -04:00
|
|
|
/**
|
|
|
|
* Enable or disable the Display window to be resized.
|
|
|
|
*
|
2011-09-03 14:52:45 -04:00
|
|
|
* @param resizable set to true to make the Display window resizable;
|
2011-07-12 18:07:32 -04:00
|
|
|
* false to disable resizing on the Display window.
|
|
|
|
*/
|
|
|
|
public static void setResizable(boolean resizable) {
|
2011-07-13 18:15:35 -04:00
|
|
|
window_resizable = resizable;
|
|
|
|
if ( isCreated() ) {
|
|
|
|
display_impl.setResizable(resizable);
|
|
|
|
}
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-12 18:07:32 -04:00
|
|
|
/**
|
|
|
|
* @return true if the Display window is resizable.
|
|
|
|
*/
|
|
|
|
public static boolean isResizable() {
|
2011-07-13 18:15:35 -04:00
|
|
|
return window_resizable;
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-12 18:07:32 -04:00
|
|
|
/**
|
|
|
|
* @return true if the Display window has been resized.
|
|
|
|
* This value will be updated after a call to Display.update().
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2011-07-13 15:29:15 -04:00
|
|
|
* This will return false if running in fullscreen or with Display.setParent(Canvas parent)
|
2011-07-12 18:07:32 -04:00
|
|
|
*/
|
|
|
|
public static boolean wasResized() {
|
2011-07-13 18:15:35 -04:00
|
|
|
return window_resized;
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2012-02-18 11:30:38 -05:00
|
|
|
/**
|
|
|
|
* @return this method will return the x position (top-left) of the Display window.
|
|
|
|
*
|
|
|
|
* If running in fullscreen mode it will return 0.
|
2013-01-29 15:53:11 -05:00
|
|
|
* If Display.setParent(Canvas parent) is being used, the x position of
|
2012-02-18 11:30:38 -05:00
|
|
|
* the parent will be returned.
|
|
|
|
*/
|
|
|
|
public static int getX() {
|
|
|
|
|
|
|
|
if (Display.isFullscreen()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent != null) {
|
|
|
|
return parent.getX();
|
|
|
|
}
|
|
|
|
|
|
|
|
return display_impl.getX();
|
|
|
|
}
|
2013-01-29 15:53:11 -05:00
|
|
|
|
2012-02-18 11:30:38 -05:00
|
|
|
/**
|
|
|
|
* @return this method will return the y position (top-left) of the Display window.
|
|
|
|
*
|
|
|
|
* If running in fullscreen mode it will return 0.
|
2013-01-29 15:53:11 -05:00
|
|
|
* If Display.setParent(Canvas parent) is being used, the y position of
|
2012-02-18 11:30:38 -05:00
|
|
|
* the parent will be returned.
|
|
|
|
*/
|
|
|
|
public static int getY() {
|
|
|
|
|
|
|
|
if (Display.isFullscreen()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent != null) {
|
|
|
|
return parent.getY();
|
|
|
|
}
|
|
|
|
|
|
|
|
return display_impl.getY();
|
|
|
|
}
|
2013-01-29 15:53:11 -05:00
|
|
|
|
2011-07-12 18:07:32 -04:00
|
|
|
/**
|
|
|
|
* @return this method will return the width of the Display window.
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2011-07-13 15:29:15 -04:00
|
|
|
* If running in fullscreen mode it will return the width of the current set DisplayMode.
|
2012-02-18 11:30:38 -05:00
|
|
|
* If Display.setParent(Canvas parent) is being used, the width of the parent
|
2011-07-13 15:29:15 -04:00
|
|
|
* will be returned.
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2011-07-12 18:07:32 -04:00
|
|
|
* This value will be updated after a call to Display.update().
|
|
|
|
*/
|
|
|
|
public static int getWidth() {
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
if (Display.isFullscreen()) {
|
|
|
|
return Display.getDisplayMode().getWidth();
|
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
if (parent != null) {
|
|
|
|
return parent.getWidth();
|
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
return width;
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-12 18:07:32 -04:00
|
|
|
/**
|
|
|
|
* @return this method will return the height of the Display window.
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2011-07-13 15:29:15 -04:00
|
|
|
* If running in fullscreen mode it will return the height of the current set DisplayMode.
|
2012-02-18 11:30:38 -05:00
|
|
|
* If Display.setParent(Canvas parent) is being used, the height of the parent
|
2011-07-13 15:29:15 -04:00
|
|
|
* will be returned.
|
2011-09-03 14:52:45 -04:00
|
|
|
*
|
2011-07-12 18:07:32 -04:00
|
|
|
* This value will be updated after a call to Display.update().
|
|
|
|
*/
|
|
|
|
public static int getHeight() {
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
if (Display.isFullscreen()) {
|
|
|
|
return Display.getDisplayMode().getHeight();
|
2011-09-03 14:52:45 -04:00
|
|
|
}
|
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
if (parent != null) {
|
|
|
|
return parent.getHeight();
|
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-13 18:15:35 -04:00
|
|
|
return height;
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2013-11-11 18:12:51 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return this method will return the pixel scale factor of the Display window.
|
|
|
|
*
|
|
|
|
* This method should be used when running in high DPI mode. In such modes Operating
|
|
|
|
* Systems will scale the Display window to avoid the window shrinking due to high
|
|
|
|
* resolutions. The OpenGL frame buffer will however use the higher resolution and
|
|
|
|
* not be scaled to match the Display window size.
|
|
|
|
*
|
|
|
|
* OpenGL methods that require pixel dependent values e.g. glViewport, glTexImage2D,
|
2013-11-11 20:25:06 -05:00
|
|
|
* glReadPixels, glScissor, glLineWidth, glRenderbufferStorage, etc can convert the
|
|
|
|
* scaled Display and Mouse coordinates to the correct high resolution value by
|
|
|
|
* multiplying them by the pixel scale factor.
|
2013-11-11 18:12:51 -05:00
|
|
|
*
|
|
|
|
* e.g. Display.getWidth() * Display.getPixelScaleFactor() will return the high DPI
|
|
|
|
* width of the OpenGL frame buffer. Whereas Display.getWidth() will be the same as
|
|
|
|
* the OpenGL frame buffer in non high DPI mode.
|
|
|
|
*
|
|
|
|
* Where high DPI mode is not available this method will just return 1.0f therefore
|
|
|
|
* not have any effect on values that are multiplied by it.
|
|
|
|
*/
|
|
|
|
public static float getPixelScaleFactor() {
|
|
|
|
return display_impl.getPixelScaleFactor();
|
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|