Package org.lwjgl.opengl

# Class Display

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

public final class Display extends Object

## Method Summary

Modifier and Type
Method
Description
`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(PixelFormatLWJGL pixel_format)`
Create the OpenGL ES context with the given minimum parameters.
`static void`
`create(PixelFormatLWJGL pixel_format, Drawable shared_drawable)`
Create the OpenGL ES context with the given minimum parameters.
`static void`
`create(PixelFormatLWJGL pixel_format, Drawable shared_drawable, ContextAttribs attribs)`
Create the OpenGL ES context with the given minimum parameters.
`static void`
`create(PixelFormatLWJGL pixel_format, ContextAttribs attribs)`
Create the OpenGL ES 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 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 int`
`getHeight()`
`static Canvas`
`getParent()`
Return the last parent set with setParent().
`static float`
`getPixelScaleFactor()`
`static String`
`getTitle()`
`static String`
`getVersion()`
Get the driver version.
`static int`
`getWidth()`
`static int`
`getX()`
`static int`
`getY()`
`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`
`isResizable()`
`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(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(Canvas parent)`
Set the parent of the Display.
`static void`
`setResizable(boolean resizable)`
Enable or disable the Display window to be resized.
`static void`
`setSwapInterval(int value)`
Set the buffer swap interval.
`static void`
`setTitle(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)`
An accurate sync method that will attempt to run at a constant frame rate.
`static void`
`update()`
Update the window.
`static void`
`update(boolean processMessages)`
Update the window.
`static boolean`
`wasResized()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### 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)
An accurate sync method that will attempt to run at a constant frame rate. It should be called once every frame.

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

### getTitle

public static String getTitle()

Returns:
  the title of the window

### getParent

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

### setParent

public static void setParent(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(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`

### create

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

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. Must be an instance of org.lwjgl.opengles.PixelFormat.
Throws:
  `LWJGLException`

### create

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

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. Must be an instance of org.lwjgl.opengles.PixelFormat.
  `shared_drawable` - The Drawable to share context with. (optional, may be null)
Throws:
  `LWJGLException`

### create

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

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. Must be an instance of org.lwjgl.opengles.PixelFormat.
  `attribs` - The ContextAttribs to use when creating the context. (optional, may be null)
Throws:
  `LWJGLException`

### create

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

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. Must be an instance of org.lwjgl.opengles.PixelFormat.
  `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 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 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(ByteBuffer[] icons)
Sets one or more icons for the Display.

- On Windows you should supply at least one 16x16 icon and one 32x32.
- Linux (and similar platforms) expect one 32x32 icon.
- Mac OS X should be supplied one 128x128 icon

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.

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

### setResizable

public static void setResizable(boolean resizable)
Enable or disable the Display window to be resized.

Parameters:
  `resizable` - set to true to make the Display window resizable; false to disable resizing on the Display window.

### isResizable

public static boolean isResizable()

Returns:
  true if the Display window is resizable.

### wasResized

public static boolean wasResized()

Returns:
  true if the Display window has been resized. This value will be updated after a call to Display.update(). This will return false if running in fullscreen or with Display.setParent(Canvas parent)

### getX

public static int getX()

Returns:
  this method will return the x position (top-left) of the Display window. If running in fullscreen mode it will return 0. If Display.setParent(Canvas parent) is being used, the x position of the parent will be returned.

### getY

public static int getY()

Returns:
  this method will return the y position (top-left) of the Display window. If running in fullscreen mode it will return 0. If Display.setParent(Canvas parent) is being used, the y position of the parent will be returned.

### getWidth

public static int getWidth()

Returns:
  this method will return the width of the Display window. If running in fullscreen mode it will return the width of the current set DisplayMode. If Display.setParent(Canvas parent) is being used, the width of the parent will be returned. This value will be updated after a call to Display.update().

### getHeight

public static int getHeight()

Returns:
  this method will return the height of the Display window. If running in fullscreen mode it will return the height of the current set DisplayMode. If Display.setParent(Canvas parent) is being used, the height of the parent will be returned. This value will be updated after a call to Display.update().

### getPixelScaleFactor

public static float getPixelScaleFactor()

Returns:
  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, 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. 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.