com.jme.system.lwjgl
Class LWJGLDisplaySystem

java.lang.Object
  extended by com.jme.system.DisplaySystem
      extended by com.jme.system.lwjgl.LWJGLDisplaySystem

public class LWJGLDisplaySystem
extends DisplaySystem

LWJGLDisplaySystem defines an implementation of DisplaySystem that uses the LWJGL API for window creation and rendering via OpenGL. LWJGLRenderer is also created that gives a way of displaying data to the created window.

Version:
$Id: LWJGLDisplaySystem.java 4390 2009-06-07 13:23:43Z christoph.luder@gmail.com $
Author:
Mark Powell, Gregg Patton, Joshua Slack - Optimizations, Headless rendering, RenderContexts, AWT integration

Field Summary
 
Fields inherited from class com.jme.system.DisplaySystem
alphaBits, bpp, brightness, contrast, created, depthBits, frq, fs, gamma, height, samples, stencilBits, width
 
Constructor Summary
LWJGLDisplaySystem()
          Constructor instantiates a new LWJGLDisplaySystem object.
 
Method Summary
 void close()
          close destroys the LWJGL Display context.
 JMECanvas createCanvas(int w, int h)
          createCanvas will create an OpenGL capable Canvas context.
 JMECanvas createCanvas(int w, int h, java.lang.String type, java.util.HashMap<java.lang.String,java.lang.Object> props)
          createCanvas will create an OpenGL capable Canvas context.
 void createHeadlessWindow(int w, int h, int bpp)
          createHeadlessWindow will create a headless LWJGL display context.
 TextureRenderer createTextureRenderer(int width, int height, TextureRenderer.Target target)
          createTextureRenderer builds the renderer used to render to a texture.
 void createWindow(int w, int h, int bpp, int frq, boolean fs)
          createWindow will create a LWJGL display context.
 java.lang.String getAdapter()
          getAdapter returns the name of the underlying system's graphics adapter for debugging / display purposes.
 RenderContext<? extends java.lang.Object> getCurrentContext()
           
 java.lang.String getDisplayAPIVersion()
          getDisplayAPIVersion returns the API version supported
 java.lang.String getDisplayRenderer()
          getDisplayRenderer returns details of the adapter
 java.lang.String getDisplayVendor()
          getDisplayVendor returns the vendor of the graphics adapter
 java.lang.String getDriverVersion()
          getDriverVersion returns a string representing the version of driver installed on the underlying system.
 PixelFormat getFormat()
          Returns a new PixelFormat with the current settings.
 Pbuffer getHeadlessDisplay()
          Returns the Pbuffer used for headless display or null if not headless.
 LWJGLRenderer getRenderer()
          getRenderer returns the created rendering class for LWJGL ( LWJGLRenderer).
 void initForApplet(int w, int h)
          Initializes the displaysystem for use in Applets.
 void initForCanvas(int width, int height)
           
 boolean isActive()
          isActive returns true if the display is active.
 boolean isClosing()
          isClosing returns any close requests.
 boolean isValidDisplayMode(int width, int height, int bpp, int freq)
          isValidDisplayMode determines if the given parameters constitute a valid display mode on this system.
 void moveWindowTo(int locX, int locY)
          If running in windowed mode, move the window's position to the given display coordinates.
 void recreateWindow(int w, int h, int bpp, int frq, boolean fs)
          recreateWindow will recreate a LWJGL display context.
 RenderContext<? extends java.lang.Object> removeContext(java.lang.Object contextKey)
          Switches to another RenderContext identified by the contextKey or to a new RenderContext if none is provided.
 void reset()
          reset prepares the window for closing or restarting.
 void setIcon(Image[] iconImages)
          Sets one or more icons for the DisplaySystem.
 void setRenderer(Renderer r)
          setRenderer sets the supplied renderer as this display's renderer.
 void setTitle(java.lang.String title)
          setTitle sets the window title of the created window.
 void setVSyncEnabled(boolean enabled)
          setVSyncEnabled attempts to enable or disable monitor vertical synchronization.
 RenderContext<? extends java.lang.Object> switchContext(java.lang.Object contextKey)
          Switches to another RenderContext identified by the contextKey or to a new RenderContext if none is provided.
protected  void updateDisplayBGC()
          Update the display's gamma, brightness and contrast based on the set values.
 
Methods inherited from class com.jme.system.DisplaySystem
getBitDepth, getBrightness, getContrast, getDisplaySystem, getDisplaySystem, getFrequency, getGamma, getHeight, getMinAlphaBits, getMinDepthBits, getMinSamples, getMinStencilBits, getPickRay, getScreenCoordinates, getScreenCoordinates, getSystemProvider, getSystemProviderIdentifiers, getWidth, getWorldCoordinates, getWorldCoordinates, isCreated, isFullScreen, makeCanvasConstructor, registerCanvasConstructor, resetSystemProvider, setBrightness, setBrightnessGammaContrast, setContrast, setGamma, setHeight, setMinAlphaBits, setMinDepthBits, setMinSamples, setMinStencilBits, setSystemProvider, setWidth, updateStates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LWJGLDisplaySystem

public LWJGLDisplaySystem()
Constructor instantiates a new LWJGLDisplaySystem object. During instantiation confirmation is made to determine if the LWJGL API is installed properly. If not, a JmeException is thrown.

Method Detail

isValidDisplayMode

public boolean isValidDisplayMode(int width,
                                  int height,
                                  int bpp,
                                  int freq)
Description copied from class: DisplaySystem
isValidDisplayMode determines if the given parameters constitute a valid display mode on this system. Returning true does not necessarily guarantee that the system is capable of running in the specified display mode, merely that it believes it is possible.

Specified by:
isValidDisplayMode in class DisplaySystem
Parameters:
width - the width/horizontal resolution of the display.
height - the height/vertical resolution of the display.
bpp - the bit depth of the display.
freq - the frequency of refresh of the display (in Hz).
See Also:
DisplaySystem.isValidDisplayMode(int, int, int, int)

setVSyncEnabled

public void setVSyncEnabled(boolean enabled)
Description copied from class: DisplaySystem
setVSyncEnabled attempts to enable or disable monitor vertical synchronization. The method is a "best attempt" to change the monitor vertical refresh synchronization, and is not guaranteed to be successful. This is dependant on OS.

Specified by:
setVSyncEnabled in class DisplaySystem
Parameters:
enabled - true to synchronize, false to ignore synchronization
See Also:
DisplaySystem.setVSyncEnabled(boolean)

setTitle

public void setTitle(java.lang.String title)
setTitle sets the window title of the created window.

Specified by:
setTitle in class DisplaySystem
Parameters:
title - the title.

createWindow

public void createWindow(int w,
                         int h,
                         int bpp,
                         int frq,
                         boolean fs)
                  throws JmeException
createWindow will create a LWJGL display context. This window will be a purely native context as defined by the LWJGL API.

Specified by:
createWindow in class DisplaySystem
Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.
bpp - the color depth of the display.
frq - the frequency of refresh of the display.
fs - flag determining if fullscreen is to be used or not. True will use fullscreen, false will use windowed mode.
Throws:
JmeException
See Also:
DisplaySystem.createWindow(int, int, int, int, boolean)

createHeadlessWindow

public void createHeadlessWindow(int w,
                                 int h,
                                 int bpp)
createHeadlessWindow will create a headless LWJGL display context. This window will be a purely native context as defined by the LWJGL API.

Specified by:
createHeadlessWindow in class DisplaySystem
Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.
bpp - the color depth of the display.
See Also:
DisplaySystem.createHeadlessWindow(int, int, int)

createCanvas

public JMECanvas createCanvas(int w,
                              int h)
createCanvas will create an OpenGL capable Canvas context. This window will be a purely native context as defined by the LWJGL API.

Overrides:
createCanvas in class DisplaySystem
Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.
See Also:
DisplaySystem.createCanvas(int, int)

createCanvas

public JMECanvas createCanvas(int w,
                              int h,
                              java.lang.String type,
                              java.util.HashMap<java.lang.String,java.lang.Object> props)
createCanvas will create an OpenGL capable Canvas context. This window will be a purely native context as defined by the LWJGL API.

Specified by:
createCanvas in class DisplaySystem
Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.
type - the type of canvas to make. e.g. "AWT", "SWT".
props - the properties we want to use (if any) for constructing our canvas.
See Also:
DisplaySystem.createCanvas(int, int, String, HashMap)

getHeadlessDisplay

public Pbuffer getHeadlessDisplay()
Returns the Pbuffer used for headless display or null if not headless.

Returns:
Pbuffer

recreateWindow

public void recreateWindow(int w,
                           int h,
                           int bpp,
                           int frq,
                           boolean fs)
recreateWindow will recreate a LWJGL display context. This window will be a purely native context as defined by the LWJGL API.

If a window is not already created, it calls createWindow and exits. Other wise it calls reinitDisplay and renderer.reinit(width,height)

Specified by:
recreateWindow in class DisplaySystem
Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.
bpp - the color depth of the display.
frq - the frequency of refresh of the display.
fs - flag determining if fullscreen is to be used or not. True will use fullscreen, false will use windowed mode.
See Also:
DisplaySystem.recreateWindow(int, int, int, int, boolean)

getRenderer

public LWJGLRenderer getRenderer()
getRenderer returns the created rendering class for LWJGL ( LWJGLRenderer). This will give the needed access to display data to the window.

Specified by:
getRenderer in class DisplaySystem
Returns:
the appropriate Renderer implementation that is compatible with the used DisplaySystem.
See Also:
DisplaySystem.getRenderer()

isClosing

public boolean isClosing()
isClosing returns any close requests. True if any exist, false otherwise.

Specified by:
isClosing in class DisplaySystem
Returns:
true if a close request is active.
See Also:
DisplaySystem.isClosing()

isActive

public boolean isActive()
Description copied from class: DisplaySystem
isActive returns true if the display is active.

Specified by:
isActive in class DisplaySystem
Returns:
whether the display system is active.

reset

public void reset()
reset prepares the window for closing or restarting.

Specified by:
reset in class DisplaySystem
See Also:
DisplaySystem.reset()

close

public void close()
close destroys the LWJGL Display context.

Specified by:
close in class DisplaySystem

createTextureRenderer

public TextureRenderer createTextureRenderer(int width,
                                             int height,
                                             TextureRenderer.Target target)
createTextureRenderer builds the renderer used to render to a texture.

Specified by:
createTextureRenderer in class DisplaySystem
Parameters:
width - width of texture
height - height of texture
Returns:
A TextureRenderer for the display system.

setRenderer

public void setRenderer(Renderer r)
setRenderer sets the supplied renderer as this display's renderer. NOTE: If the supplied renderer is not LWJGLRenderer, then it is ignored.

Specified by:
setRenderer in class DisplaySystem
Parameters:
r - the renderer to set.

updateDisplayBGC

protected void updateDisplayBGC()
Update the display's gamma, brightness and contrast based on the set values.

Specified by:
updateDisplayBGC in class DisplaySystem

setIcon

public void setIcon(Image[] iconImages)
Description copied from class: DisplaySystem
Sets one or more icons for the DisplaySystem.

As a reference for usual platforms on number of icons and their sizes:

Images should be in format RGBA8888. If they are not jME will try to convert them using ImageUtils. If that fails a JmeException could be thrown.

Specified by:
setIcon in class DisplaySystem
Parameters:
iconImages - Array of Images to be used as icons.
See Also:
DisplaySystem.setIcon(com.jme.image.Image[])

getAdapter

public java.lang.String getAdapter()
Description copied from class: DisplaySystem
getAdapter returns the name of the underlying system's graphics adapter for debugging / display purposes.

Specified by:
getAdapter in class DisplaySystem
Returns:
the adapter's name as a String

getDriverVersion

public java.lang.String getDriverVersion()
Description copied from class: DisplaySystem
getDriverVersion returns a string representing the version of driver installed on the underlying system.

Specified by:
getDriverVersion in class DisplaySystem
Returns:
the version as a String

getDisplayVendor

public java.lang.String getDisplayVendor()
getDisplayVendor returns the vendor of the graphics adapter

Specified by:
getDisplayVendor in class DisplaySystem
Returns:
The adapter vendor

getDisplayRenderer

public java.lang.String getDisplayRenderer()
getDisplayRenderer returns details of the adapter

Specified by:
getDisplayRenderer in class DisplaySystem
Returns:
The adapter details

getDisplayAPIVersion

public java.lang.String getDisplayAPIVersion()
getDisplayAPIVersion returns the API version supported

Specified by:
getDisplayAPIVersion in class DisplaySystem
Returns:
The api version supported

getFormat

public PixelFormat getFormat()
Returns a new PixelFormat with the current settings.

Returns:
a new PixelFormat with the current settings

getCurrentContext

public RenderContext<? extends java.lang.Object> getCurrentContext()
Specified by:
getCurrentContext in class DisplaySystem
Returns:
a RenderContext object representing the current OpenGL context.

switchContext

public RenderContext<? extends java.lang.Object> switchContext(java.lang.Object contextKey)
Switches to another RenderContext identified by the contextKey or to a new RenderContext if none is provided.

Parameters:
contextKey - key identifier
Returns:
RenderContext identified by the contextKey or new RenderContext if none provided

initForCanvas

public void initForCanvas(int width,
                          int height)

removeContext

public RenderContext<? extends java.lang.Object> removeContext(java.lang.Object contextKey)
Switches to another RenderContext identified by the contextKey or to a new RenderContext if none is provided.

Parameters:
contextKey - key identifier
Returns:
RenderContext identified by the contextKey or new RenderContext if none provided

moveWindowTo

public void moveWindowTo(int locX,
                         int locY)
Description copied from class: DisplaySystem
If running in windowed mode, move the window's position to the given display coordinates.

Specified by:
moveWindowTo in class DisplaySystem

initForApplet

public void initForApplet(int w,
                          int h)
Initializes the displaysystem for use in Applets.

Parameters:
w - width of the applet
h - height of the applet