jme.system
Class DisplaySystem

java.lang.Object
  extended byjme.system.DisplaySystem

public class DisplaySystem
extends java.lang.Object

DisplaySystem manages the Window and OpenGL context of the application. There are five parameters that are needed to describe the creation of the window and assciated rendering context. First, the width and height of the window. This can be considered the resolution of the application. For example: width = 1024, height = 768. BPP describes the depth or bits per pixel of the window. There are two modes supported: 16 and 32. Next, fullscreen describes if the application is in windowed or fullscreen mode. Lastly, title is used to display an application name in the title bar. The title is not very important if we are rendering in fullscreen mode. DisplaySystem is a singleton class and cannot be instantiated directly. Use the createDisplaySystem method. You can then used the getDisplaySystem method to obtain the object. After the DisplaySystem is created, the GL and GLU objects are created and can be retrieved via the getter methods. You can change the attributes of the rendering system dynamically using the the setAttributes method. This will destroy the current system and create a new system.

Version:
$Id: DisplaySystem.java,v 1.10 2003/09/08 20:29:28 mojomonkey Exp $
Author:
Mark Powell

Method Summary
static void createDisplaySystem(int width, int height, int bpp, int freq, boolean fullscreen, java.lang.String title)
          createDisplaySystem creates a new DisplaySystem which in turns creates the window and OpenGL context.
static void createDisplaySystem(java.lang.String title, java.lang.String imageFile, boolean always)
          createDisplaySystem creates a new DisplaySystem which in turns creates the window and OpenGL context.
 void cullMode(int mode, boolean on)
          cullMode sets the culling mode.
static DisplaySystem getDisplaySystem()
          getDisplaySystem returns the reference to the singleton object of the DisplaySystem.
 DisplayMode getValidDisplayMode(int width, int height, int bpp, int freq)
          getValidDisplayMode returns a DisplayMode object that has the requested width, height and color depth.
static java.lang.String getVersion()
          getVersion returns a string representation of what version jME is currently running.
 void setAttributes(int width, int height, int bpp, int freq, boolean fullscreen, java.lang.String title)
          setAttributes changes the attributes of the current display.
 boolean takeScreenShot(java.lang.String filename)
          takeScreenShot writes the screen pixels to a png image file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setAttributes

public void setAttributes(int width,
                          int height,
                          int bpp,
                          int freq,
                          boolean fullscreen,
                          java.lang.String title)
setAttributes changes the attributes of the current display. This requires that the current display be destroyed and recreated. The new width and height values must be greater than 0. bpp must be either 16 or 32. It is important to realize that the gl context is being reinitialized. Therefore, all previous gl states are gone and will have to be reset. For example, textures.

Parameters:
width - the width of the window. Must be greater than 0.
height - the height of the window. Must be greater than 0.
bpp - the color depth of the display. Must be either 16 or 32.
freq - the frequency of the monitor.
fullscreen - flag to run fullscreen or not. True is fullscreen, false is windowed.
title - the title of the window.
Throws:
MonkeyRuntimeException - is thrown if width or height is less than or equal to 0, or bpp is not either 16, 24 or 32.

createDisplaySystem

public static void createDisplaySystem(int width,
                                       int height,
                                       int bpp,
                                       int freq,
                                       boolean fullscreen,
                                       java.lang.String title)
createDisplaySystem creates a new DisplaySystem which in turns creates the window and OpenGL context. This is a static method used to initialize the singleton DisplaySystem object. After the DisplaySystem has been initialized via this method call, getDisplaySystem can be used to retrieve the object reference. If the DisplaySystem has already been created, a second call to createDisplaySystem is ignored. Use the setter methods to alter the attributes of the display.

Parameters:
width - the width of the window. Must be greater than 0.
height - the height of the window. Must be greater than 0.
bpp - the color depth of the window. Must be 16 or 32.
freq - the frequency of the monitor.
fullscreen - flag to run fullscreen or not. True is fullscreen, false is windowed.
title - the title of the window.
Throws:
MonkeyRuntimeException - if width or height is less than or equal to 0 or bpp is not 16, 24 or 32.

createDisplaySystem

public static void createDisplaySystem(java.lang.String title,
                                       java.lang.String imageFile,
                                       boolean always)
createDisplaySystem creates a new DisplaySystem which in turns creates the window and OpenGL context. This is a static method used to initialize the singleton DisplaySystem object. After the DisplaySystem has been initialized via this method call, getDisplaySystem can be used to retrieve the object reference. If the DisplaySystem has already been created, a second call to createDisplaySystem is ignored. Use the setter methods to alter the attributes of the display. No display properties are passed, as this method makes use of the PropertiesIO class to obtain needed information from the properties file, if the file does not exist a dialog will appear for the user to check them. A flag can also be set to always display this dialog.

Parameters:
title - the title of the window.
imageFile - the image to use for the properties dialog.
always - a flag declaring how often the properties dialog should be displayed. True will display the dialog every time, false will display the dialog only when the properties file is missing.

getDisplaySystem

public static DisplaySystem getDisplaySystem()
getDisplaySystem returns the reference to the singleton object of the DisplaySystem. After a call to createDisplaySystem is made, you can retrieve any display system information using this object.

Returns:
the singleton instance of the DisplaySystem. If createDisplaySystem has not been called before invoking this method, null will be returned.

getValidDisplayMode

public DisplayMode getValidDisplayMode(int width,
                                       int height,
                                       int bpp,
                                       int freq)
getValidDisplayMode returns a DisplayMode object that has the requested width, height and color depth. If there is no mode that supports a requested resolution, null is returned.

Parameters:
width - the width of the desired mode.
height - the height of the desired mode.
bpp - the color depth of the desired mode.
freq - the frequency of the monitor.
Returns:
DisplayMode object that supports the requested resolutions. Null is returned if no valid modes are found.

getVersion

public static java.lang.String getVersion()
getVersion returns a string representation of what version jME is currently running.

Returns:
the version of this API.

cullMode

public void cullMode(int mode,
                     boolean on)
cullMode sets the culling mode.

Parameters:
mode - the mode to cull.
on - true turn on culling, false turn it off.

takeScreenShot

public boolean takeScreenShot(java.lang.String filename)
takeScreenShot writes the screen pixels to a png image file. The client is required to supply the method with the name of the file. This can include subdirectories. Do not supply a file extension, as .png will be appended to it. For example: "screenshot" will create a file of screenshot.png.

Parameters:
filename - the filename to save the screenshot as.
Returns:
true if the screenshot was successfully captured, false if it wasn't.
Throws:
MonkeyRuntimeException - if the filename is null.