org.lwjgl.opengl
Class Display

java.lang.Object
  extended by org.lwjgl.opengl.Display

public final class Display
extends java.lang.Object


Method Summary
static void create()
          Create the OpenGL context.
static void create(PixelFormat pixel_format)
          Create the OpenGL context with the given minimum parameters.
static void create(PixelFormat pixel_format, ContextAttribs attribs)
          Create the OpenGL context with the given minimum parameters.
static void create(PixelFormat pixel_format, Drawable shared_drawable)
          Create the OpenGL context with the given minimum parameters.
static void create(PixelFormat pixel_format, Drawable shared_drawable, ContextAttribs attribs)
          Create the OpenGL context with the given minimum parameters.
static void destroy()
          Destroy the Display.
static java.lang.String getAdapter()
          Get the driver adapter string.
static DisplayMode[] getAvailableDisplayModes()
          Returns the entire list of possible fullscreen display modes as an array, in no particular order.
static DisplayMode getDesktopDisplayMode()
          Return the initial desktop display mode.
static DisplayMode getDisplayMode()
          Return the current display mode, as set by setDisplayMode().
static Drawable getDrawable()
          Fetch the Drawable from the Display.
static java.awt.Canvas getParent()
          Return the last parent set with setParent().
static java.lang.String getTitle()
           
static java.lang.String getVersion()
          Get the driver version.
static boolean isActive()
           
static boolean isCloseRequested()
           
static boolean isCreated()
           
static boolean isCurrent()
          Returns true if the Display's context is current in the current thread.
static boolean isDirty()
          Determine if the window's contents have been damaged by external events.
static boolean isFullscreen()
           
static boolean isVisible()
           
static void makeCurrent()
          Make the Display the current rendering context for GL calls.
static void processMessages()
          Process operating system events.
static void releaseContext()
          Release the Display context.
static void setDisplayConfiguration(float gamma, float brightness, float contrast)
          Set the display configuration to the specified gamma, brightness and contrast.
static void setDisplayMode(DisplayMode mode)
          Set the current display mode.
static void setDisplayModeAndFullscreen(DisplayMode mode)
          Set the mode of the context.
static void setFullscreen(boolean fullscreen)
          Set the fullscreen mode of the context.
static int setIcon(java.nio.ByteBuffer[] icons)
          Sets one or more icons for the Display.
static void setInitialBackground(float red, float green, float blue)
          Set the initial color of the Display.
static void setLocation(int new_x, int new_y)
          Set the window's location.
static void setParent(java.awt.Canvas parent)
          Set the parent of the Display.
static void setSwapInterval(int value)
          Set the buffer swap interval.
static void setTitle(java.lang.String newTitle)
          Set the title of the window.
static void setVSyncEnabled(boolean sync)
          Enable or disable vertical monitor synchronization.
static void swapBuffers()
          Swap the display buffers.
static void sync(int fps)
          Best sync method that works reliably.
static void update()
          Update the window.
static void update(boolean processMessages)
          Update the window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDrawable

public static Drawable getDrawable()
Fetch the Drawable from the Display.

Returns:
the Drawable corresponding to the Display context

getAvailableDisplayModes

public static DisplayMode[] getAvailableDisplayModes()
                                              throws LWJGLException
Returns the entire list of possible fullscreen display modes as an array, in no 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.

The only certain way to check is to call create() and make sure it works. Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32). Only DisplayModes from this call can be used when the Display is in fullscreen mode.

Returns:
an array of all display modes the system reckons it can handle.
Throws:
LWJGLException

getDesktopDisplayMode

public static DisplayMode getDesktopDisplayMode()
Return the initial desktop display mode.

Returns:
The desktop display mode

getDisplayMode

public static DisplayMode getDisplayMode()
Return the current display mode, as set by setDisplayMode().

Returns:
The current display mode

setDisplayMode

public static void setDisplayMode(DisplayMode mode)
                           throws LWJGLException
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 fullscreen context, the mode will also be switched immediately. The native cursor position is also reset.

Parameters:
mode - The new display mode to set
Throws:
LWJGLException - if the display mode could not be set

setDisplayConfiguration

public static void setDisplayConfiguration(float gamma,
                                           float brightness,
                                           float contrast)
                                    throws LWJGLException
Set the display configuration to the specified gamma, brightness and contrast. The configuration changes will be reset when destroy() is called.

Parameters:
gamma - The gamma value
brightness - The brightness value between -1.0 and 1.0, inclusive
contrast - The contrast, larger than 0.0.
Throws:
LWJGLException

sync

public static void sync(int fps)
Best sync method that works reliably.

Parameters:
fps - The desired frame rate, in frames per second

getTitle

public static java.lang.String getTitle()
Returns:
the title of the window

getParent

public static java.awt.Canvas getParent()
Return the last parent set with setParent().


setParent

public static void setParent(java.awt.Canvas parent)
                      throws LWJGLException
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.

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.

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.

Throws:
LWJGLException

setFullscreen

public static void setFullscreen(boolean fullscreen)
                          throws LWJGLException
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 mode returned by getDisplayMode(). The native cursor position is also reset.

Parameters:
fullscreen - Specify the fullscreen mode of the context.
Throws:
LWJGLException - If fullscreen is true, and the current DisplayMode instance is not from getAvailableDisplayModes() or if the mode switch fails.

setDisplayModeAndFullscreen

public static void setDisplayModeAndFullscreen(DisplayMode mode)
                                        throws LWJGLException
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.

Parameters:
mode - The new display mode to set. Must be non-null.
Throws:
LWJGLException - If the mode switch fails.

isFullscreen

public static boolean isFullscreen()
Returns:
whether the Display is in fullscreen mode

setTitle

public static void setTitle(java.lang.String newTitle)
Set the title of the window. This may be ignored by the underlying OS.

Parameters:
newTitle - The new window title

isCloseRequested

public static boolean isCloseRequested()
Returns:
true if the user or operating system has asked the window to close

isVisible

public static boolean isVisible()
Returns:
true if the window is visible, false if not

isActive

public static boolean isActive()
Returns:
true if window is active, that is, the foreground display of the operating system.

isDirty

public static boolean isDirty()
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 update() or isDirty() is called.

Returns:
true if the window has been damaged by external changes and needs to repaint itself

processMessages

public static void processMessages()
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.


swapBuffers

public static void swapBuffers()
                        throws LWJGLException
Swap the display buffers. This method is called from update(), and should normally not be called by the application.

Throws:
OpenGLException - if an OpenGL error has occured since the last call to glGetError()
LWJGLException

update

public static void update()
Update the window. If the window is visible clears the dirty flag and calls swapBuffers() and finally polls the input devices.


update

public static void update(boolean processMessages)
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.

Parameters:
processMessages - Poll input devices if true

releaseContext

public static void releaseContext()
                           throws LWJGLException
Release the Display context.

Throws:
LWJGLException - If the context could not be released

isCurrent

public static boolean isCurrent()
                         throws LWJGLException
Returns true if the Display's context is current in the current thread.

Throws:
LWJGLException

makeCurrent

public static void makeCurrent()
                        throws LWJGLException
Make the Display the current rendering context for GL calls.

Throws:
LWJGLException - If the context could not be made current

create

public static void create()
                   throws LWJGLException
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.

The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.

Throws:
LWJGLException

create

public static void create(PixelFormat pixel_format)
                   throws LWJGLException
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.

The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.

Parameters:
pixel_format - Describes the minimum specifications the context must fulfill.
Throws:
LWJGLException

create

public static void create(PixelFormat pixel_format,
                          Drawable shared_drawable)
                   throws LWJGLException
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.

The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.

Parameters:
pixel_format - Describes the minimum specifications the context must fulfill.
shared_drawable - The Drawable to share context with. (optional, may be null)
Throws:
LWJGLException

create

public static void create(PixelFormat pixel_format,
                          ContextAttribs attribs)
                   throws LWJGLException
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.

The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.

Parameters:
pixel_format - Describes the minimum specifications the context must fulfill.
attribs - The ContextAttribs to use when creating the context. (optional, may be null)
Throws:
LWJGLException

create

public static void create(PixelFormat pixel_format,
                          Drawable shared_drawable,
                          ContextAttribs attribs)
                   throws LWJGLException
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.

The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with GL coordinates.

Parameters:
pixel_format - Describes the minimum specifications the context must fulfill.
shared_drawable - The Drawable to share context with. (optional, may be null)
attribs - The ContextAttribs to use when creating the context. (optional, may be null)
Throws:
LWJGLException

setInitialBackground

public static void setInitialBackground(float red,
                                        float green,
                                        float blue)
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.

Parameters:
red - - color value between 0 - 1
green - - color value between 0 - 1
blue - - color value between 0 - 1

destroy

public static void destroy()
Destroy the Display. After this call, there will be no current GL rendering context, regardless of whether the Display was the current rendering context.


isCreated

public static boolean isCreated()
Returns:
true if the window's native peer has been created

setSwapInterval

public static void setSwapInterval(int value)
Set the buffer swap interval. This call is a best-attempt at changing the monitor swap interval, which is the minimum periodicity of color buffer swaps, measured in video frame periods, and is not guaranteed to be successful.

A video frame period is the time required to display a full frame of video data.

Parameters:
value - The swap interval in frames, 0 to disable

setVSyncEnabled

public static void setVSyncEnabled(boolean sync)
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.

Parameters:
sync - true to synchronize; false to ignore synchronization

setLocation

public static void setLocation(int new_x,
                               int new_y)
Set the window's location. This is a no-op on fullscreen windows or when getParent() != null. 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.
noteIf no location has been specified (or x == y == -1) the window will be centered

Parameters:
new_x - The new window location on the x axis
new_y - The new window location on the y axis

getAdapter

public static java.lang.String getAdapter()
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.

Returns:
a String

getVersion

public static java.lang.String getVersion()
Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined, this function returns null.

Returns:
a String

setIcon

public static int setIcon(java.nio.ByteBuffer[] icons)
Sets one or more icons for the Display. The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform.

NOTE: The display will make a deep copy of the supplied byte buffer array, for the purpose of recreating the icons when you go back and forth fullscreen mode. You therefore only need to set the icon once per instance.

Parameters:
icons - Array of icons in RGBA mode. Pass the icons in order of preference.
Returns:
number of icons used, or 0 if display hasn't been created


Copyright © 2002-2009 lwjgl.org. All Rights Reserved.