2004-04-03 16:05:57 -05:00
|
|
|
/*
|
2004-02-04 17:06:18 -05:00
|
|
|
* Copyright (c) 2002-2004 Light Weight Java Game Library Project
|
|
|
|
* All rights reserved.
|
2004-04-03 16:05:57 -05:00
|
|
|
*
|
2004-02-04 17:06:18 -05:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2004-04-03 16:05:57 -05:00
|
|
|
* modification, are permitted provided that the following conditions are
|
2004-02-04 17:06:18 -05:00
|
|
|
* met:
|
2004-04-03 16:05:57 -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-04-03 16:05:57 -05:00
|
|
|
* * Neither the name of 'Light Weight Java Game Library' 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-04-03 16:05:57 -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-04-03 16:05:57 -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-04-03 16:05:57 -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
|
|
|
*/
|
2004-02-04 17:06:18 -05:00
|
|
|
|
2003-08-04 06:09:40 -04:00
|
|
|
package org.lwjgl.opengl;
|
2003-03-27 17:32:48 -05:00
|
|
|
|
|
|
|
/**
|
2003-08-03 18:05:40 -04:00
|
|
|
* This is the abstract class for a Window in LWJGL. LWJGL windows have some
|
2003-03-27 17:32:48 -05:00
|
|
|
* peculiar characteristics:
|
2004-04-03 16:05:57 -05:00
|
|
|
*
|
2003-03-27 17:32:48 -05:00
|
|
|
* - width and height are always fixed and cannot be changed
|
|
|
|
* - the position of the window may or may not be programmable but once specified
|
2003-08-02 13:11:33 -04:00
|
|
|
* cannot be changed programmatically
|
2003-03-27 17:32:48 -05:00
|
|
|
* - the window may be closeable by the user or operating system, and may be minimized
|
|
|
|
* by the user or operating system
|
2003-03-27 17:46:25 -05:00
|
|
|
* - only one window may ever be open at once
|
2003-03-27 17:32:48 -05:00
|
|
|
* - the operating system may or may not be able to do fullscreen or windowed windows.
|
2004-04-03 16:05:57 -05:00
|
|
|
*
|
2003-03-27 17:32:48 -05:00
|
|
|
* @author foo
|
|
|
|
*/
|
2003-08-04 06:09:40 -04:00
|
|
|
|
|
|
|
import org.lwjgl.Display;
|
|
|
|
import org.lwjgl.Sys;
|
2004-03-26 06:01:34 -05:00
|
|
|
import org.lwjgl.input.Controller;
|
|
|
|
import org.lwjgl.input.Keyboard;
|
2004-03-21 16:54:57 -05:00
|
|
|
import org.lwjgl.input.Mouse;
|
2004-03-27 10:05:24 -05:00
|
|
|
import org.lwjgl.LWJGLException;
|
2003-08-04 06:09:40 -04:00
|
|
|
|
2003-08-03 18:05:40 -04:00
|
|
|
public final class Window {
|
2003-03-27 17:32:48 -05:00
|
|
|
|
|
|
|
static {
|
2004-03-27 08:48:58 -05:00
|
|
|
Sys.initialize();
|
2003-10-01 05:33:22 -04:00
|
|
|
}
|
2003-09-29 05:26:20 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/** X coordinate of the window */
|
2003-08-02 13:11:33 -04:00
|
|
|
private static int x;
|
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.
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
private static int y;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/** Width of the window */
|
2003-08-02 13:11:33 -04:00
|
|
|
private static int width;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/** Height of the window */
|
2003-08-02 13:11:33 -04:00
|
|
|
private static int height;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/** Title of the window */
|
2003-08-02 13:11:33 -04:00
|
|
|
private static String title;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
|
|
|
/** Fullscreen */
|
|
|
|
private static boolean fullscreen;
|
2004-04-03 18:01:39 -05:00
|
|
|
|
|
|
|
/** Undecorated */
|
|
|
|
private static boolean undecorated;
|
2004-02-15 10:27:02 -05:00
|
|
|
|
2003-08-04 19:00:49 -04:00
|
|
|
/** Tracks VBO state for the window context */
|
|
|
|
private static VBOTracker vbo_tracker;
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2003-11-03 06:23:56 -05:00
|
|
|
/** A unique context object, so we can track different contexts between creates() and destroys() */
|
2004-02-23 11:30:48 -05:00
|
|
|
private static Window context;
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
/** Whether we created the Mouse */
|
|
|
|
private static boolean createdMouse;
|
|
|
|
|
|
|
|
/** Whether we created the Keyboard */
|
|
|
|
private static boolean createdKeyboard;
|
|
|
|
|
|
|
|
/** Whether we created the Controller */
|
|
|
|
private static boolean createdController;
|
2003-08-04 19:00:49 -04:00
|
|
|
|
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
|
|
|
*/
|
2003-08-03 18:05:40 -04:00
|
|
|
private Window() {
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
|
|
|
|
2004-04-03 18:01:39 -05:00
|
|
|
/**
|
|
|
|
* @return the X coordinate of the window (always 0 for fullscreen)
|
|
|
|
*/
|
|
|
|
public static int getX() {
|
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot get X on uncreated window");
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the Y coordinate of the window (always 0 for fullscreen)
|
|
|
|
*/
|
|
|
|
public static int getY() {
|
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot get Y on uncreated window");
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* @return the width of the window
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static int getWidth() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot get width on uncreated window");
|
2003-03-27 17:32:48 -05:00
|
|
|
return width;
|
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* @return the height of the window
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static int getHeight() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot get height on uncreated window");
|
2003-03-27 17:32:48 -05:00
|
|
|
return height;
|
|
|
|
}
|
2003-08-03 18:05:40 -04: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() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot get title on uncreated window");
|
2003-03-27 17:32:48 -05:00
|
|
|
return title;
|
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2003-09-26 09:59:50 -04:00
|
|
|
/**
|
|
|
|
* @return whether this window is in fullscreen mode
|
|
|
|
*/
|
|
|
|
public static boolean isFullscreen() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine fullscreen state of uncreated window");
|
2003-09-26 09:59:50 -04:00
|
|
|
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-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot set title on uncreated window");
|
2003-03-27 17:32:48 -05:00
|
|
|
title = newTitle;
|
2003-03-30 14:26:39 -05:00
|
|
|
nSetTitle(title);
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* Native implementation of setTitle(). This will read the window's title member
|
|
|
|
* and stash it in the native title of the window.
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
private static native void nSetTitle(String title);
|
2003-03-27 17:32:48 -05: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");
|
2003-10-01 05:33:22 -04:00
|
|
|
return nIsCloseRequested();
|
2003-07-28 06:09:58 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-08-04 06:09:40 -04:00
|
|
|
private static native boolean nIsCloseRequested();
|
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
|
|
|
* @return true if the window is minimized or otherwise not visible
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isMinimized() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine minimized state of uncreated window");
|
2003-08-04 06:09:40 -04:00
|
|
|
return nIsMinimized();
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-08-04 06:09:40 -04:00
|
|
|
private static native boolean nIsMinimized();
|
|
|
|
|
2003-07-28 06:09:58 -04:00
|
|
|
/**
|
|
|
|
* @return true if window is focused
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static boolean isFocused() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot determine focused state of uncreated window");
|
2003-08-04 06:09:40 -04:00
|
|
|
return nIsFocused();
|
2003-07-28 06:09:58 -04:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-08-04 06:09:40 -04:00
|
|
|
private static native boolean nIsFocused();
|
|
|
|
|
2003-06-04 17:49:46 -04:00
|
|
|
/**
|
|
|
|
* Minimize the game and allow the operating system's default display to become
|
2003-06-12 10:08:10 -04:00
|
|
|
* visible. It is the responsibility of LWJGL's native code to restore the display
|
2003-06-04 17:49:46 -04:00
|
|
|
* to its normal display settings.
|
2004-04-03 16:05:57 -05:00
|
|
|
*
|
2003-06-04 17:49:46 -04:00
|
|
|
* If the display is already minimized then this is a no-op.
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static native void minimize();
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-06-04 17:49:46 -04:00
|
|
|
/**
|
2003-06-12 10:08:10 -04:00
|
|
|
* Restore the game and hide the operating system away. It is the responsibility of
|
2003-06-04 17:49:46 -04:00
|
|
|
* LWJGL's native code to restore the display to its game display settings.
|
2004-04-03 16:05:57 -05:00
|
|
|
*
|
2003-06-04 17:49:46 -04:00
|
|
|
* If the display is not minimized then this is a no-op/
|
|
|
|
*/
|
2003-08-02 13:11:33 -04:00
|
|
|
public static native void restore();
|
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
|
|
|
|
* redraw when it returns true. The flag is cleared when you call paint().
|
2004-04-03 16:05:57 -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");
|
2003-08-04 06:09:40 -04:00
|
|
|
return nIsDirty();
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2003-08-04 06:09:40 -04:00
|
|
|
private static native boolean nIsDirty();
|
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2004-03-26 06:01:34 -05:00
|
|
|
* Update the window. This processes operating system events, and if the window is visible
|
|
|
|
* clears the dirty flag and swaps the buffers.
|
|
|
|
* @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())
|
2004-03-28 15:29:52 -05:00
|
|
|
throw new IllegalStateException("Cannot update uncreated window");
|
2004-03-26 06:01:34 -05:00
|
|
|
nUpdate();
|
|
|
|
if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) {
|
|
|
|
Util.checkGLError();
|
|
|
|
swapBuffers();
|
|
|
|
}
|
|
|
|
// Poll the input devices while we're here
|
|
|
|
if (Mouse.isCreated()) {
|
|
|
|
Mouse.poll();
|
|
|
|
if (Mouse.isBuffered()) {
|
|
|
|
Mouse.read();
|
|
|
|
}
|
|
|
|
Mouse.updateCursor();
|
|
|
|
}
|
|
|
|
if (Keyboard.isCreated()) {
|
|
|
|
Keyboard.poll();
|
|
|
|
if (Keyboard.isBuffered()) {
|
|
|
|
Keyboard.read();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Controller.isCreated()) {
|
|
|
|
Controller.poll();
|
|
|
|
if (Controller.isBuffered()) {
|
|
|
|
Controller.read();
|
|
|
|
}
|
|
|
|
}
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|
2003-03-30 14:26:39 -05:00
|
|
|
|
2003-03-28 14:02:24 -05:00
|
|
|
/**
|
2003-08-03 18:05:40 -04:00
|
|
|
* Swap double buffers.
|
2003-03-28 14:02:24 -05:00
|
|
|
*/
|
2003-08-03 18:05:40 -04:00
|
|
|
private static native void swapBuffers();
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-02-18 12:48:26 -05:00
|
|
|
/**
|
|
|
|
* Make the Window the current rendering context for GL calls.
|
|
|
|
*/
|
|
|
|
public static synchronized void makeCurrent() {
|
2004-03-27 06:55:07 -05:00
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("No window created to make current");
|
2004-02-18 12:48:26 -05:00
|
|
|
nMakeCurrent();
|
2004-02-24 09:31:39 -05:00
|
|
|
GLContext.useContext(context);
|
2004-02-18 12:48:26 -05:00
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-02-18 12:48:26 -05:00
|
|
|
/**
|
|
|
|
* Make the window the current rendering context for GL calls.
|
|
|
|
*/
|
|
|
|
private static native void nMakeCurrent();
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
/**
|
|
|
|
* Create a fullscreen window that matches the current display depth. Default common values are chosen
|
|
|
|
* for common OpenGL rendering operations: you will get at least a 16-bit depth buffer, an 8 bit stencil
|
|
|
|
* buffer, probably no alpha buffer, and probably no multisampling.
|
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-03-26 06:01:34 -05:00
|
|
|
* @param title
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException
|
2004-03-26 06:01:34 -05:00
|
|
|
*/
|
2004-03-27 10:05:24 -05:00
|
|
|
public static void create(String title) throws LWJGLException {
|
2004-03-26 06:01:34 -05:00
|
|
|
create(title, Display.getDepth(), 0, 16, 8, 0);
|
|
|
|
}
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
/**
|
|
|
|
* Create a fullscreen window. If the underlying OS does not
|
|
|
|
* support fullscreen mode, then a window will be created instead. If this
|
2004-03-27 10:05:24 -05:00
|
|
|
* fails too then an 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-03-26 06:01:34 -05:00
|
|
|
* @param title The title of the window
|
|
|
|
* @param bpp Minimum bits per pixel
|
|
|
|
* @param alpha Minimum bits per pixel in alpha buffer
|
|
|
|
* @param depth Minimum bits per pixel in depth buffer
|
|
|
|
* @param stencil Minimum bits per pixel in stencil buffer
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException if the window could not be created for any reason; typically because
|
2004-03-26 06:01:34 -05:00
|
|
|
* the minimum requirements could not be met satisfactorily
|
|
|
|
*/
|
2004-03-27 10:05:24 -05:00
|
|
|
public static void create(String title, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
|
2004-03-26 06:01:34 -05:00
|
|
|
create(title, bpp, alpha, depth, stencil, 0);
|
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2003-08-03 18:05:40 -04:00
|
|
|
/**
|
|
|
|
* Create a fullscreen window. If the underlying OS does not
|
|
|
|
* support fullscreen mode, then a window will be created instead. If this
|
2004-03-27 10:05:24 -05:00
|
|
|
* fails too then an 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.
|
2003-08-03 18:05:40 -04:00
|
|
|
* @param title The title of the window
|
|
|
|
* @param bpp Minimum bits per pixel
|
|
|
|
* @param alpha Minimum bits per pixel in alpha buffer
|
|
|
|
* @param depth Minimum bits per pixel in depth buffer
|
|
|
|
* @param stencil Minimum bits per pixel in stencil buffer
|
2004-02-15 10:27:02 -05:00
|
|
|
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec).
|
|
|
|
Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException if the window could not be created for any reason; typically because
|
2003-08-03 18:05:40 -04:00
|
|
|
* the minimum requirements could not be met satisfactorily
|
|
|
|
*/
|
2004-03-27 10:05:24 -05:00
|
|
|
public static void create(String title, int bpp, int alpha, int depth, int stencil, int samples) throws LWJGLException {
|
2003-08-03 18:05:40 -04:00
|
|
|
if (isCreated())
|
2004-03-27 06:55:07 -05:00
|
|
|
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
|
2004-02-15 10:27:02 -05:00
|
|
|
Window.fullscreen = true;
|
2004-04-03 18:01:39 -05:00
|
|
|
Window.undecorated = true;
|
2003-08-03 18:05:40 -04:00
|
|
|
Window.x = 0;
|
|
|
|
Window.y = 0;
|
|
|
|
Window.width = Display.getWidth();
|
|
|
|
Window.height = Display.getHeight();
|
2004-02-15 10:27:02 -05:00
|
|
|
Window.title = title;
|
|
|
|
createWindow(bpp, alpha, depth, stencil, samples);
|
2003-08-03 18:05:40 -04:00
|
|
|
}
|
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
/**
|
|
|
|
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
2004-03-27 10:05:24 -05:00
|
|
|
* display will be created instead. If this fails too then an LWJGLException will be thrown.
|
2004-03-26 06:01:34 -05:00
|
|
|
* If the window is created fullscreen, then its size may not match the specified size
|
|
|
|
* here.
|
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-03-26 06:01:34 -05:00
|
|
|
* @param title The title of the window
|
|
|
|
* @param x The position of the window on the x axis. May be ignored.
|
|
|
|
* @param y The position of the window on the y axis. May be ignored.
|
|
|
|
* @param width The width of the window's client area
|
|
|
|
* @param height The height of the window's client area
|
|
|
|
* @param bpp Minimum bits per pixel
|
|
|
|
* @param alpha Minimum bits per pixel in alpha buffer
|
|
|
|
* @param depth Minimum bits per pixel in depth buffer
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException if the window could not be created for any reason; typically because
|
2004-03-26 06:01:34 -05:00
|
|
|
* the minimum requirements could not be met satisfactorily
|
|
|
|
*/
|
2004-03-27 10:05:24 -05:00
|
|
|
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
|
2004-04-03 18:01:39 -05:00
|
|
|
create(title, x, y, width, height, false, bpp, alpha, depth, stencil);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
|
|
|
* display will be created instead. If this fails too then an LWJGLException will be thrown.
|
|
|
|
* If the window is created fullscreen, then its size may not match the specified size
|
|
|
|
* here.
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
* @param title The title of the window
|
|
|
|
* @param x The position of the window on the x axis. May be ignored.
|
|
|
|
* @param y The position of the window on the y axis. May be ignored.
|
|
|
|
* @param width The width of the window's client area
|
|
|
|
* @param height The height of the window's client area
|
|
|
|
* @param undecorated A hint to specify that the window should not have OS decorations such as drag bar and close box
|
|
|
|
* @param bpp Minimum bits per pixel
|
|
|
|
* @param alpha Minimum bits per pixel in alpha buffer
|
|
|
|
* @param depth Minimum bits per pixel in depth buffer
|
|
|
|
* @throws LWJGLException if the window could not be created for any reason; typically because
|
|
|
|
* the minimum requirements could not be met satisfactorily
|
|
|
|
*/
|
|
|
|
public static void create(String title, int x, int y, int width, int height, boolean undecorated, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
|
|
|
|
create(title, x, y, width, height, undecorated, bpp, alpha, depth, stencil, 0);
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
|
|
|
|
2003-03-28 14:02:24 -05:00
|
|
|
/**
|
2003-08-03 18:05:40 -04:00
|
|
|
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
2004-03-27 10:05:24 -05:00
|
|
|
* display will be created instead. If this fails too then an LWJGLException will be thrown.
|
2003-08-03 18:05:40 -04:00
|
|
|
* If the window is created fullscreen, then its size may not match the specified size
|
|
|
|
* here.
|
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.
|
2003-08-03 18:05:40 -04:00
|
|
|
* @param title The title of the window
|
|
|
|
* @param x The position of the window on the x axis. May be ignored.
|
|
|
|
* @param y The position of the window on the y axis. May be ignored.
|
|
|
|
* @param width The width of the window's client area
|
|
|
|
* @param height The height of the window's client area
|
|
|
|
* @param bpp Minimum bits per pixel
|
|
|
|
* @param alpha Minimum bits per pixel in alpha buffer
|
|
|
|
* @param depth Minimum bits per pixel in depth buffer
|
|
|
|
* @param stencil Minimum bits per pixel in stencil buffer
|
2004-02-15 10:27:02 -05:00
|
|
|
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec).
|
|
|
|
Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException if the window could not be created for any reason; typically because
|
2003-08-03 18:05:40 -04:00
|
|
|
* the minimum requirements could not be met satisfactorily
|
|
|
|
*/
|
2004-02-15 10:27:02 -05:00
|
|
|
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil, int samples)
|
2004-03-27 10:05:24 -05:00
|
|
|
throws LWJGLException {
|
2004-04-03 18:01:39 -05:00
|
|
|
|
|
|
|
create(title, x, y, width, height, false, bpp, alpha, depth, stencil, samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
|
|
|
* display will be created instead. If this fails too then an LWJGLException will be thrown.
|
|
|
|
* If the window is created fullscreen, then its size may not match the specified size
|
|
|
|
* here.
|
|
|
|
* <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.
|
|
|
|
* @param title The title of the window
|
|
|
|
* @param x The position of the window on the x axis. May be ignored.
|
|
|
|
* @param y The position of the window on the y axis. May be ignored.
|
|
|
|
* @param width The width of the window's client area
|
|
|
|
* @param height The height of the window's client area
|
|
|
|
* @param undecorated A hint to specify that the window should not have OS decorations such as drag bar and close box
|
|
|
|
* @param bpp Minimum bits per pixel
|
|
|
|
* @param alpha Minimum bits per pixel in alpha buffer
|
|
|
|
* @param depth Minimum bits per pixel in depth buffer
|
|
|
|
* @param stencil Minimum bits per pixel in stencil buffer
|
|
|
|
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec).
|
|
|
|
Pass 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
|
|
|
|
* @throws LWJGLException if the window could not be created for any reason; typically because
|
|
|
|
* the minimum requirements could not be met satisfactorily
|
|
|
|
*/
|
|
|
|
public static void create(String title, int x, int y, int width, int height, boolean undecorated, int bpp, int alpha, int depth, int stencil, int samples)
|
|
|
|
throws LWJGLException {
|
2003-08-03 18:05:40 -04:00
|
|
|
if (isCreated())
|
2004-03-27 06:55:07 -05:00
|
|
|
throw new IllegalStateException("Only one LWJGL window may be instantiated at any one time.");
|
2004-02-15 10:27:02 -05:00
|
|
|
Window.fullscreen = false;
|
2004-04-03 18:01:39 -05:00
|
|
|
Window.undecorated = undecorated;
|
2003-08-03 18:05:40 -04:00
|
|
|
Window.x = x;
|
|
|
|
Window.y = y;
|
|
|
|
Window.width = width;
|
|
|
|
Window.height = height;
|
|
|
|
Window.title = title;
|
2004-02-15 10:27:02 -05:00
|
|
|
createWindow(bpp, alpha, depth, stencil, samples);
|
2003-08-03 18:05:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the native window peer.
|
2004-03-27 10:05:24 -05:00
|
|
|
* @throws LWJGLException
|
2003-03-28 14:02:24 -05:00
|
|
|
*/
|
2003-08-03 18:05:40 -04:00
|
|
|
private static native void nCreate(
|
|
|
|
String title,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
boolean fullscreen,
|
2004-04-04 04:10:48 -04:00
|
|
|
boolean undecorated,
|
2003-08-03 18:05:40 -04:00
|
|
|
int bpp,
|
|
|
|
int alpha,
|
|
|
|
int depth,
|
2003-09-26 09:59:50 -04:00
|
|
|
int stencil,
|
2004-02-23 18:42:58 -05:00
|
|
|
int samples)
|
2004-03-27 10:05:24 -05:00
|
|
|
throws LWJGLException;
|
2003-08-03 18:05:40 -04:00
|
|
|
|
2004-03-27 10:05:24 -05:00
|
|
|
private static void createWindow(int bpp, int alpha, int depth, int stencil, int samples) throws LWJGLException {
|
2004-04-03 18:01:39 -05:00
|
|
|
nCreate(title, x, y, width, height, fullscreen, undecorated, bpp, alpha, depth, stencil, samples);
|
2004-02-23 11:30:48 -05:00
|
|
|
context = new Window();
|
|
|
|
makeCurrent();
|
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();
|
|
|
|
GL11.glOrtho(0.0, (double) width, 0.0, (double) height, -1.0, 1.0);
|
|
|
|
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
|
|
|
GL11.glLoadIdentity();
|
|
|
|
GL11.glViewport(0, 0, width, height);
|
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
// Automatically create mouse, keyboard and controller
|
2004-04-03 16:05:57 -05:00
|
|
|
if (!Boolean.getBoolean("org.lwjgl.opengl.Window.noinput")) {
|
|
|
|
if (!Mouse.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Window.nomouse")) {
|
|
|
|
try {
|
|
|
|
Mouse.create();
|
|
|
|
createdMouse = true;
|
|
|
|
Mouse.enableBuffer();
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
if (Sys.DEBUG) {
|
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
|
|
|
Sys.log("Failed to create Mouse: "+e);
|
|
|
|
}
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
if (!Keyboard.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Window.nokeyboard")) {
|
|
|
|
try {
|
|
|
|
Keyboard.create();
|
|
|
|
createdKeyboard = true;
|
|
|
|
Keyboard.enableBuffer();
|
|
|
|
Keyboard.enableTranslation();
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
if (Sys.DEBUG) {
|
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
|
|
|
Sys.log("Failed to create Keyboard: "+e);
|
|
|
|
}
|
2004-03-26 06:01:34 -05:00
|
|
|
}
|
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
if (!Controller.isCreated() && !Boolean.getBoolean("org.lwjgl.opengl.Window.nocontroller")) {
|
|
|
|
try {
|
|
|
|
Controller.create();
|
|
|
|
createdController = true;
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
if (Sys.DEBUG) {
|
|
|
|
e.printStackTrace(System.err);
|
|
|
|
} else {
|
|
|
|
Sys.log("Failed to create Controller: "+e);
|
|
|
|
}
|
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-02-18 12:48:26 -05:00
|
|
|
* Destroy the Window. After this call, there will be no current GL rendering context,
|
|
|
|
* regardless of whether the Window was the current rendering context.
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-02-18 12:48:26 -05:00
|
|
|
public static synchronized void destroy() {
|
|
|
|
if (context == null) {
|
2003-03-28 14:02:24 -05:00
|
|
|
return;
|
2004-02-18 12:48:26 -05:00
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-03-26 06:01:34 -05:00
|
|
|
// Automatically destroy keyboard, mouse, and controller
|
|
|
|
if (createdMouse && Mouse.isCreated()) {
|
|
|
|
Mouse.destroy();
|
|
|
|
createdMouse = false;
|
|
|
|
}
|
|
|
|
if (createdKeyboard && Keyboard.isCreated()) {
|
|
|
|
Keyboard.destroy();
|
|
|
|
createdKeyboard = false;
|
|
|
|
}
|
|
|
|
if (createdController && Controller.isCreated()) {
|
|
|
|
Controller.destroy();
|
|
|
|
createdController = false;
|
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-02-18 12:48:26 -05:00
|
|
|
makeCurrent();
|
2003-08-03 18:05:40 -04:00
|
|
|
nDestroy();
|
2003-11-03 06:23:56 -05:00
|
|
|
context = null;
|
|
|
|
}
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2003-11-03 06:23:56 -05:00
|
|
|
/**
|
2004-02-18 12:48:26 -05:00
|
|
|
* @return the unique Window context (or null, if the Window has not been created)
|
2003-11-03 06:23:56 -05:00
|
|
|
*/
|
2004-02-23 11:30:48 -05:00
|
|
|
public static Object 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 17:32:48 -05:00
|
|
|
/**
|
2003-08-03 18:05:40 -04:00
|
|
|
* Destroy the native window peer.
|
2003-03-27 17:32:48 -05:00
|
|
|
*/
|
2004-03-28 15:29:52 -05:00
|
|
|
private static native void nDestroy();
|
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
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
/**
|
2003-08-17 05:27:32 -04:00
|
|
|
* Updates the windows internal state. This must be called at least once per video frame
|
2003-03-27 17:32:48 -05:00
|
|
|
* to handle window close requests, moves, paints, etc.
|
|
|
|
*/
|
2004-03-26 06:01:34 -05:00
|
|
|
private static native void nUpdate();
|
2003-10-20 10:17:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines to the best of the platform's ability whether monitor vysnc is enabled on
|
|
|
|
* this window. The failsafe assumption is that when vsync cannot be determined, this
|
|
|
|
* method returns false, and you should rely on using a hires timer to throttle your
|
|
|
|
* framerate rather than relying on monitor sync (even if monitor sync is actually working).
|
|
|
|
* Therefore you can guarantee that if we return true from this method that we're pretty
|
|
|
|
* certain vsync is enabled.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static boolean isVSyncEnabled() {
|
2004-03-28 15:29:52 -05:00
|
|
|
if (!isCreated())
|
2004-03-27 06:55:07 -05:00
|
|
|
throw new IllegalStateException("Cannot determine vsync state of uncreated window");
|
2003-10-20 10:17:47 -04:00
|
|
|
return nIsVSyncEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static native boolean nIsVSyncEnabled();
|
2004-04-03 16:05:57 -05: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.
|
|
|
|
* To check whether the call <em>might</em> have been successful, call isVSyncEnabled().
|
|
|
|
* @param sync true to synchronize; false to ignore synchronization
|
|
|
|
*/
|
|
|
|
public static void setVSyncEnabled(boolean sync) {
|
2004-03-28 15:29:52 -05:00
|
|
|
if (!isCreated())
|
2004-03-27 06:55:07 -05:00
|
|
|
throw new IllegalStateException("Cannot set vsync state of uncreated window");
|
2003-10-20 10:17:47 -04:00
|
|
|
nSetVSyncEnabled(sync);
|
|
|
|
}
|
|
|
|
|
2003-11-25 17:34:04 -05:00
|
|
|
private static native void nSetVSyncEnabled(boolean sync);
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2004-04-03 18:01:39 -05:00
|
|
|
/**
|
|
|
|
* Set the window's location. This is a no-op on fullscreen windows.
|
2004-04-03 18:14:19 -05: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.
|
2004-04-03 18:01:39 -05:00
|
|
|
* @param x, y The new window location
|
|
|
|
*/
|
|
|
|
public static void setLocation(int x, int y) {
|
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot move uncreated window");
|
|
|
|
if (fullscreen) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-03 18:14:19 -05:00
|
|
|
Window.x = Math.max(0, Math.min(Display.getWidth() - Window.width, x));
|
|
|
|
Window.y = Math.max(0, Math.min(Display.getHeight() - Window.height, y));
|
2004-04-03 18:01:39 -05:00
|
|
|
nReshape(Window.x, Window.y, Window.width, Window.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the window's size. This is a no-op on fullscreen windows.
|
2004-04-03 18:14:19 -05: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.
|
2004-04-03 18:01:39 -05:00
|
|
|
* @param width, height The new window dimensions
|
|
|
|
*/
|
|
|
|
public static void setSize(int width, int height) {
|
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot resize uncreated window");
|
|
|
|
if (fullscreen) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-03 18:14:19 -05:00
|
|
|
Window.width = Math.max(0, Math.min(Display.getWidth() - Window.x, width));
|
|
|
|
Window.height = Math.max(0, Math.min(Display.getHeight() - Window.y, height));
|
2004-04-03 18:01:39 -05:00
|
|
|
nReshape(Window.x, Window.y, Window.width, Window.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-04-03 18:14:19 -05:00
|
|
|
* Set the window's bounds. This is a no-op on fullscreen windows.
|
|
|
|
* The window is clamped to remain entirely on the screen.
|
2004-04-03 18:01:39 -05:00
|
|
|
* @param x, y The new window location
|
|
|
|
* @param width, height The new window dimensions
|
|
|
|
*/
|
|
|
|
public static void setBounds(int x, int y, int width, int height) {
|
|
|
|
if (!isCreated())
|
|
|
|
throw new IllegalStateException("Cannot reshape uncreated window");
|
|
|
|
if (fullscreen) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-03 18:14:19 -05:00
|
|
|
width = Math.max(0, Math.min(Display.getWidth(), width));
|
|
|
|
height = Math.max(0, Math.min(Display.getHeight(), height));
|
|
|
|
Window.x = Math.max(0, Math.min(Display.getWidth() - width, x));
|
|
|
|
Window.y = Math.max(0, Math.min(Display.getHeight() - height, y));
|
|
|
|
Window.width = Math.max(0, Math.min(Display.getWidth() - Window.x, width));
|
|
|
|
Window.height = Math.max(0, Math.min(Display.getHeight() - Window.y, height));
|
2004-04-03 18:01:39 -05:00
|
|
|
nReshape(Window.x, Window.y, Window.width, Window.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native method to reshape the window
|
|
|
|
* @param x, y The new window location
|
|
|
|
* @param width, height The new window dimensions
|
|
|
|
*/
|
|
|
|
private static native void nReshape(int x, int y, int width, int height);
|
2004-04-03 16:05:57 -05:00
|
|
|
|
2003-03-27 17:32:48 -05:00
|
|
|
}
|