com.jme.system
Class DisplaySystem

java.lang.Object
  extended bycom.jme.system.DisplaySystem
Direct Known Subclasses:
DummyDisplaySystem, LWJGLDisplaySystem

public abstract class DisplaySystem
extends java.lang.Object

DisplaySystem defines an interface for system creation. Specifically, any implementing class will create a window for rendering. It also should create the appropriate Renderer object that allows the client to render to this window. Implmenting classes should check for the appropriate libraries to insure these libraries are indeed installed on the system. This will allow users to cleanly exit if an improper library was chosen for rendering. Example usage: DisplaySystem ds = DisplaySystem.getDisplaySystem("LWJGL");
ds.createWindow(640,480,32,60,true);
Renderer r = ds.getRenderer();

Version:
$Id: DisplaySystem.java,v 1.38 2005/04/05 23:45:48 renanse Exp $
Author:
Mark Powell, Gregg Patton, Joshua Slack - Optimizations and Headless rendering
See Also:
Renderer

Field Summary
protected  int alphaBits
          Alpha bits to use for the renderer.
protected  int bpp
          Bit depth selected for renderer.
protected  boolean created
          Is the display created already?
protected  int depthBits
          Depth bits to use for the renderer.
protected  int frq
          Frequency selected for renderer.
protected  boolean fs
          Is the display full screen?
protected  int height
          height selected for the renderer.
static java.lang.String[] rendererNames
          The list of current implemented rendering APIs that subclass Display.
protected  int samples
          Number of samples to use for the multisample buffer.
protected  int stencilBits
          Stencil bits to use for the renderer.
protected  int width
          Width selected for the renderer.
 
Constructor Summary
protected DisplaySystem()
          A new display system has been created.
 
Method Summary
abstract  void close()
          close shutdowns and destroys any window contexts.
abstract  java.awt.Canvas createCanvas(int w, int h)
          createCanvas creates an awt canvas with the desired settings.
abstract  void createHeadlessWindow(int w, int h, int bpp)
          createHeadlessWindow creates a headless window with the desired settings.
abstract  TextureRenderer createTextureRenderer(int width, int height, boolean useRGB, boolean useRGBA, boolean useDepth, boolean isRectangle, int target, int mipmaps)
          Crate a TextureRenderer using the underlying system.
abstract  void createWindow(int w, int h, int bpp, int frq, boolean fs)
          createWindow creates a window with the desired settings.
 int getBitDepth()
          Returns the set bitdepth for the display system.
static DisplaySystem getDisplaySystem()
          Returns the currently created display system.
static DisplaySystem getDisplaySystem(java.lang.String key)
          getDisplaySystem is a factory method that creates the appropriate display system specified by the key parameter.
abstract  WidgetFont getFont(java.lang.String fontName)
           
 int getFrequency()
          Returns the set frequency for the display system.
 int getHeight()
          Returns the set height for the display system.
 int getMinAlphaBits()
          Returns the minimum bits per pixel in the alpha buffer.
 int getMinDepthBits()
          Returns the minimum bits per pixel in the depth buffer.
 int getMinSamples()
          Returns the minimum samples in multisample buffer.
 int getMinStencilBits()
          Returns the minimum bits per pixel in the stencil buffer.
abstract  Renderer getRenderer()
          getRenderer returns the Renderer implementation that is compatible with the chosen DisplaySystem.
abstract  RendererType getRendererType()
          getRendererType returns an instance of a strongly typed enumeration that can be used to determine the renderer that the DisplaySystem is currently using.
abstract  Vector3f getScreenCoordinates(Vector3f worldPosition)
          Translate world to screen coordinates
abstract  Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store)
          Translate world to screen coordinates
 int getWidth()
          Returns the set width for the display system.
abstract  Vector3f getWorldCoordinates(Vector2f screenPosition, float zPos)
          Translate screen to world coordinates.
abstract  Vector3f getWorldCoordinates(Vector2f screenPosition, float zPos, Vector3f store)
          Translate screen to world coordinates.
abstract  boolean isClosing()
          isClosing notifies if the window is currently closing.
 boolean isCreated()
          isCreated returns the current status of the display system.
 boolean isFullScreen()
          Returns whether or not the display system is set to be full screen.
abstract  boolean isValidDisplayMode(int width, int height, int bpp, int freq)
          isValidDisplayMode determines if the given parameters constitute a valid display mode on this system.
abstract  void recreateWindow(int w, int h, int bpp, int frq, boolean fs)
          recreateWindow recreates a window with the desired settings.
abstract  void reset()
          reset cleans up the display system for closing or restarting.
 void setMinAlphaBits(int alphaBits)
          Sets the minimum bits per pixel in the alpha buffer.
 void setMinDepthBits(int depthBits)
          Sets the minimum bits per pixel in the depth buffer.
 void setMinSamples(int samples)
          Sets the minimum samples in the multisample buffer.
 void setMinStencilBits(int stencilBits)
          Sets the minimum bits per pixel in the stencil buffer.
abstract  void setRenderer(Renderer r)
           
abstract  void setTitle(java.lang.String title)
          Sets the title of the display system.
abstract  void setVSyncEnabled(boolean enabled)
          setVSyncEnabled attempts to enable or disable monitor vertical synchronization.
static void updateStates(Renderer r)
          Called when the display system is created, this function sets the default render states for the renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected int width
Width selected for the renderer.


height

protected int height
height selected for the renderer.


bpp

protected int bpp
Bit depth selected for renderer.


frq

protected int frq
Frequency selected for renderer.


fs

protected boolean fs
Is the display full screen?


created

protected boolean created
Is the display created already?


alphaBits

protected int alphaBits
Alpha bits to use for the renderer.


depthBits

protected int depthBits
Depth bits to use for the renderer.


stencilBits

protected int stencilBits
Stencil bits to use for the renderer.


samples

protected int samples
Number of samples to use for the multisample buffer.


rendererNames

public static final java.lang.String[] rendererNames
The list of current implemented rendering APIs that subclass Display.

Constructor Detail

DisplaySystem

protected DisplaySystem()
A new display system has been created. The default static display system is set to the newly created display system.

Method Detail

getDisplaySystem

public static DisplaySystem getDisplaySystem(java.lang.String key)
getDisplaySystem is a factory method that creates the appropriate display system specified by the key parameter. If the key given is not a valid identifier for a specific display system, null is returned. For valid display systems see the rendererNames array.

Parameters:
key - the display system to use.
Returns:
the appropriate display system specified by the key.

getDisplaySystem

public static DisplaySystem getDisplaySystem()
Returns the currently created display system.

Returns:
The current display system.

getWidth

public int getWidth()
Returns the set width for the display system.

Returns:
The set width.

getHeight

public int getHeight()
Returns the set height for the display system.

Returns:
The set height.

getBitDepth

public int getBitDepth()
Returns the set bitdepth for the display system.

Returns:
the set bit depth

getFrequency

public int getFrequency()
Returns the set frequency for the display system.

Returns:
the set frequency

isFullScreen

public boolean isFullScreen()
Returns whether or not the display system is set to be full screen.

Returns:
true if full screen

isValidDisplayMode

public abstract boolean isValidDisplayMode(int width,
                                           int height,
                                           int bpp,
                                           int freq)
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.

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).

setVSyncEnabled

public abstract void setVSyncEnabled(boolean enabled)
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.

Parameters:
enabled - true to synchronize, false to ignore synchronization

setTitle

public abstract void setTitle(java.lang.String title)
Sets the title of the display system. This is usually reflected by the renderer as text in the menu bar.

Parameters:
title - The new display title.

createWindow

public abstract void createWindow(int w,
                                  int h,
                                  int bpp,
                                  int frq,
                                  boolean fs)
createWindow creates a window with the desired settings. The width and height defined by w and h define the size of the window if fullscreen is false, otherwise it defines the resolution of the fullscreen display. The color depth is defined by bpp. The implementing class should only allow 16, 24, and 32. The monitor frequency is defined by the frq parameter and should not exceed the capabilities of the connected hardware, the implementing class should attempt to assure this does not happen. Lastly, the boolean flag fs determines if the display should be windowed or fullscreen. If false, windowed is chosen. This window will be placed in the center of the screen initially. If true fullscreen mode will be entered with the appropriate settings.

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.

createHeadlessWindow

public abstract void createHeadlessWindow(int w,
                                          int h,
                                          int bpp)
createHeadlessWindow creates a headless window with the desired settings. A headless window is a rendering target that is not shown on screen. It is useful for doing offline rendering, integration and so forth. You can not have a regular and headless window at the same time. The width and height defined by w and h define the size of the window. The color depth is defined by bpp.

Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.
bpp - the color depth of the display.

createCanvas

public abstract java.awt.Canvas createCanvas(int w,
                                             int h)
createCanvas creates an awt canvas with the desired settings. The width and height defined by w and h define the size of the canvas.

Parameters:
w - the width/horizontal resolution of the display.
h - the height/vertical resolution of the display.

recreateWindow

public abstract void recreateWindow(int w,
                                    int h,
                                    int bpp,
                                    int frq,
                                    boolean fs)
recreateWindow recreates a window with the desired settings.

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.

getRenderer

public abstract Renderer getRenderer()
getRenderer returns the Renderer implementation that is compatible with the chosen DisplaySystem. For example, if LWJGLDisplaySystem is used, the returned Renderer will be LWJGLRenderer.

Returns:
the appropriate Renderer implementation that is compatible with the used DisplaySystem.
See Also:
Renderer

setRenderer

public abstract void setRenderer(Renderer r)

getRendererType

public abstract RendererType getRendererType()
getRendererType returns an instance of a strongly typed enumeration that can be used to determine the renderer that the DisplaySystem is currently using.

Returns:
See Also:
JmeType

isCreated

public boolean isCreated()
isCreated returns the current status of the display system. If the window and renderer are created, true is returned, otherwise false.

Returns:
whether the display system is created.

isClosing

public abstract boolean isClosing()
isClosing notifies if the window is currently closing. This could be caused via the application itself or external interrupts such as alt-f4 etc.

Returns:
true if the window is closing, false otherwise.

reset

public abstract void reset()
reset cleans up the display system for closing or restarting.


close

public abstract void close()
close shutdowns and destroys any window contexts.


getFont

public abstract WidgetFont getFont(java.lang.String fontName)
Parameters:
fontName - - name of the font to loaded
Returns:
an instance of the requested font, null of the isn't loaded.

getMinAlphaBits

public int getMinAlphaBits()
Returns the minimum bits per pixel in the alpha buffer.

Returns:
the int value of alphaBits.

setMinAlphaBits

public void setMinAlphaBits(int alphaBits)
Sets the minimum bits per pixel in the alpha buffer.

Parameters:
alphaBits - - the new value for alphaBits

getMinDepthBits

public int getMinDepthBits()
Returns the minimum bits per pixel in the depth buffer.

Returns:
the int value of depthBits.

setMinDepthBits

public void setMinDepthBits(int depthBits)
Sets the minimum bits per pixel in the depth buffer.

Parameters:
depthBits - - the new value for depthBits

getMinStencilBits

public int getMinStencilBits()
Returns the minimum bits per pixel in the stencil buffer.

Returns:
the int value of stencilBits.

setMinStencilBits

public void setMinStencilBits(int stencilBits)
Sets the minimum bits per pixel in the stencil buffer.

Parameters:
stencilBits - - the new value for stencilBits

getMinSamples

public int getMinSamples()
Returns the minimum samples in multisample buffer.

Returns:
the int value of samples.

setMinSamples

public void setMinSamples(int samples)
Sets the minimum samples in the multisample buffer.

Parameters:
samples - - the new value for samples

updateStates

public static void updateStates(Renderer r)
Called when the display system is created, this function sets the default render states for the renderer. It should not be called directly by the user.

Parameters:
r - The renderer to get the default states from.

createTextureRenderer

public abstract TextureRenderer createTextureRenderer(int width,
                                                      int height,
                                                      boolean useRGB,
                                                      boolean useRGBA,
                                                      boolean useDepth,
                                                      boolean isRectangle,
                                                      int target,
                                                      int mipmaps)
Crate a TextureRenderer using the underlying system. This should not be user called. It is called when the display system is created.

Parameters:
width - width of texture
height - height of texture
useRGB - if this is true, useRGBA should not be
useRGBA - if this is true, useRGB should not be
useDepth -
isRectangle -
target -
mipmaps -
Returns:
A TextureRenderer for the display system.

getScreenCoordinates

public abstract Vector3f getScreenCoordinates(Vector3f worldPosition)
Translate world to screen coordinates

Parameters:
worldPosition - Vector3f representing the world position to retrieve.
Returns:
Vector2f The screen position of that vector3f world position.

getScreenCoordinates

public abstract Vector3f getScreenCoordinates(Vector3f worldPosition,
                                              Vector3f store)
Translate world to screen coordinates

Parameters:
worldPosition - Vector3f representing the world position to retrieve.
store - Vector3f to store the world position in.
Returns:
Vector3f The store vector3f, after storing.

getWorldCoordinates

public abstract Vector3f getWorldCoordinates(Vector2f screenPosition,
                                             float zPos)
Translate screen to world coordinates.

Parameters:
screenPosition - Vector2f representing the screen position with 0,0 at the bottom left.
zPos - float The z position away from the viewing plane.
Returns:
Vector3f A vector3f representing the vector's world position.

getWorldCoordinates

public abstract Vector3f getWorldCoordinates(Vector2f screenPosition,
                                             float zPos,
                                             Vector3f store)
Translate screen to world coordinates.

Parameters:
screenPosition - Vector2f representing the screen position with 0,0 at the bottom left
zPos - float The z position away from the viewing plane.
store - Vector3f The vector to store the result in.
Returns:
Vector3f The store vector, after storing it's result.