com.jme.renderer.lwjgl
Class LWJGLRenderer

java.lang.Object
  extended bycom.jme.renderer.lwjgl.LWJGLRenderer
All Implemented Interfaces:
Renderer

public class LWJGLRenderer
extends java.lang.Object
implements Renderer

LWJGLRenderer provides an implementation of the Renderer interface using the LWJGL API.

Version:
$Id: LWJGLRenderer.java,v 1.60 2005/04/07 19:07:20 renanse Exp $
Author:
Mark Powell, Joshua Slack - Optimizations and Headless rendering
See Also:
Renderer

Field Summary
 
Fields inherited from interface com.jme.renderer.Renderer
QUEUE_INHERIT, QUEUE_OPAQUE, QUEUE_ORTHO, QUEUE_SKIP, QUEUE_TRANSPARENT
 
Constructor Summary
LWJGLRenderer(int width, int height)
          Constructor instantiates a new LWJGLRenderer object.
 
Method Summary
 boolean checkAndAdd(Spatial s)
          Check a given Spatial to see if it should be queued.
 void clearBuffers()
          clearBuffers clears both the color and the depth buffer.
 void clearColorBuffer()
          clearBackBuffer clears the OpenGL color buffer.
 void clearStatistics()
          clearStatistics resets the vertices and triangles counter for the statistics information.
 void clearStrictBuffers()
          clearBuffers clears both the color and the depth buffer for only the part of the buffer defined by the renderer width/height.
 void clearZBuffer()
          clearZBuffer clears the OpenGL depth buffer.
 AlphaState createAlphaState()
          createAlphaState returns a new LWJGLAlphaState object as a regular AlphaState.
 AttributeState createAttributeState()
          createAttributeState returns a new LWJGLAttributeState object as a regular AttributeState.
 Camera createCamera(int width, int height)
          createCamera returns a default camera for use with the LWJGL renderer.
 CullState createCullState()
          createCullState returns a new LWJGLCullState object as a regular CullState.
 DitherState createDitherState()
          createDitherState returns a new LWJGLDitherState object as a regular DitherState.
 FogState createFogState()
          createFogState returns a new LWJGLFogState object as a regular FogState.
 FragmentProgramState createFragmentProgramState()
          createFragmentProgramState returns a new LWJGLFragmentProgramState object as a regular FragmentProgramState.
 GLSLShaderObjectsState createGLSLShaderObjectsState()
          createShaderObjectsState returns a new LWJGLShaderObjectsState object as a regular ShaderObjectsState.
 LightState createLightState()
          createLightState returns a new LWJGLLightState object as a regular LightState.
 MaterialState createMaterialState()
          createMaterialState returns a new LWJGLMaterialState object as a regular MaterialState.
 ShadeState createShadeState()
          createShadeState returns a new LWJGLShadeState object as a regular ShadeState.
 StencilState createStencilState()
          createStencilState returns a new LWJGLStencilState object as a regular StencilState.
 TextureState createTextureState()
          createTextureState returns a new LWJGLTextureState object as a regular TextureState.
 VertexProgramState createVertexProgramState()
          createVertexProgramState returns a new LWJGLVertexProgramState object as a regular VertexProgramState.
 WireframeState createWireframeState()
          createWireframeState returns a new LWJGLWireframeState object as a regular WireframeState.
 ZBufferState createZBufferState()
          createZBufferState returns a new LWJGLZBufferState object as a regular ZBufferState.
 void displayBackBuffer()
          displayBackBuffer renders any queued items then flips the rendered buffer (back) with the currently displayed buffer.
 void draw(CompositeMesh t)
          draw renders a CompositeMesh object including it's normals, colors, textures and vertices.
 void draw(Curve c)
          draw renders a curve object.
 void draw(Line l)
          draw draws a line object where a line contains a collection of vertices, normals, colors and texture coordinates.
 void draw(Point p)
          draw draws a point object where a point contains a collection of vertices, normals, colors and texture coordinates.
 void draw(Spatial s)
          draw renders a scene by calling the nodes onDraw method.
 void draw(Text t)
          draw renders a text object using a predefined font.
 void draw(TriMesh t)
          draw renders a TriMesh object including it's normals, colors, textures and vertices.
 void draw(WidgetRenderer wr)
          draw renders a WidgetRenderer object to the back buffer.
 void drawBounds(BoundingVolume bv)
          draw renders a TriMesh object including it's normals, colors, textures and vertices.
 void drawBounds(Geometry g)
          draw renders a TriMesh object including it's normals, colors, textures and vertices.
 void drawBounds(Spatial s)
          drawBounds renders a scene by calling the nodes onDraw method.
 void enableStatistics(boolean value)
          enableStatistics will turn on statistics gathering.
 ColorRGBA getBackgroundColor()
          getBackgroundColor retrieves the clear color of the current OpenGL context.
 Camera getCamera()
          getCamera returns the camera used by this renderer.
 int getHeight()
          Retrieve the height set on this renderer.
 RenderQueue getQueue()
          Get the render queue associated with this Renderer.
 java.lang.String getStatistics()
          getStatistics returns a string value of the rendering statistics information (number of triangles and number of vertices).
 java.lang.StringBuffer getStatistics(java.lang.StringBuffer a)
          getStatistics returns a string value of the rendering statistics information (number of triangles and number of vertices).
 int getWidth()
          Retrieve the width set on this renderer.
 void grabScreenContents(java.nio.IntBuffer buff, int x, int y, int w, int h)
          grabScreenContents reads a block of pixels from the current framebuffer.
 boolean isHeadless()
          See Renderer.isHeadless()
 boolean isProcessingQueue()
          Return true if this renderer is in the middle of processing its RenderQueue.
 void prepVBO(Geometry g)
           
 void reinit(int width, int height)
          Reinitialize the renderer with the given width/height.
 void setBackgroundColor(ColorRGBA c)
          setBackgroundColor sets the OpenGL clear color to the color specified.
 void setCamera(Camera camera)
          setCamera sets the camera this renderer is using.
 void setHeadless(boolean headless)
          See Renderer.setHeadless()
 void setOrtho()
          setOrtho sets the display system to be in orthographic mode.
 void setOrthoCenter()
          setOrthoCenter sets the display system to be in orthographic mode.
 boolean supportsVBO()
          Return true if the system running this supports VBO
 boolean takeScreenShot(java.lang.String filename)
          takeScreenShot saves the current buffer to a file.
 void unsetOrtho()
          unsetOrhto unsets the display system from orthographic mode back into regular projection mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LWJGLRenderer

public LWJGLRenderer(int width,
                     int height)
Constructor instantiates a new LWJGLRenderer object. The size of the rendering window is passed during construction.

Parameters:
width - the width of the rendering context.
height - the height of the rendering context.
Method Detail

reinit

public void reinit(int width,
                   int height)
Reinitialize the renderer with the given width/height. Also calls resize on the attached camera if present.

Specified by:
reinit in interface Renderer
Parameters:
width - int
height - int

setCamera

public void setCamera(Camera camera)
setCamera sets the camera this renderer is using. It asserts that the camera is of type LWJGLCamera.

Specified by:
setCamera in interface Renderer
Parameters:
camera - the camera object to use with this Renderer.
See Also:
Renderer.setCamera(com.jme.renderer.Camera)

getCamera

public Camera getCamera()
getCamera returns the camera used by this renderer.

Specified by:
getCamera in interface Renderer
Returns:
the camera this renderer is using.
See Also:
Renderer.getCamera()

createCamera

public Camera createCamera(int width,
                           int height)
createCamera returns a default camera for use with the LWJGL renderer.

Specified by:
createCamera in interface Renderer
Parameters:
width - the width of the frame.
height - the height of the frame.
Returns:
a default LWJGL camera.

createAlphaState

public AlphaState createAlphaState()
createAlphaState returns a new LWJGLAlphaState object as a regular AlphaState.

Specified by:
createAlphaState in interface Renderer
Returns:
an AlphaState object.

createAttributeState

public AttributeState createAttributeState()
createAttributeState returns a new LWJGLAttributeState object as a regular AttributeState.

Specified by:
createAttributeState in interface Renderer
Returns:
an AttributeState object.

createCullState

public CullState createCullState()
createCullState returns a new LWJGLCullState object as a regular CullState.

Specified by:
createCullState in interface Renderer
Returns:
a CullState object.
See Also:
Renderer.createCullState()

createDitherState

public DitherState createDitherState()
createDitherState returns a new LWJGLDitherState object as a regular DitherState.

Specified by:
createDitherState in interface Renderer
Returns:
an DitherState object.

createFogState

public FogState createFogState()
createFogState returns a new LWJGLFogState object as a regular FogState.

Specified by:
createFogState in interface Renderer
Returns:
an FogState object.

createLightState

public LightState createLightState()
createLightState returns a new LWJGLLightState object as a regular LightState.

Specified by:
createLightState in interface Renderer
Returns:
an LightState object.

createMaterialState

public MaterialState createMaterialState()
createMaterialState returns a new LWJGLMaterialState object as a regular MaterialState.

Specified by:
createMaterialState in interface Renderer
Returns:
an MaterialState object.

createShadeState

public ShadeState createShadeState()
createShadeState returns a new LWJGLShadeState object as a regular ShadeState.

Specified by:
createShadeState in interface Renderer
Returns:
an ShadeState object.

createTextureState

public TextureState createTextureState()
createTextureState returns a new LWJGLTextureState object as a regular TextureState.

Specified by:
createTextureState in interface Renderer
Returns:
an TextureState object.

createWireframeState

public WireframeState createWireframeState()
createWireframeState returns a new LWJGLWireframeState object as a regular WireframeState.

Specified by:
createWireframeState in interface Renderer
Returns:
an WireframeState object.

createZBufferState

public ZBufferState createZBufferState()
createZBufferState returns a new LWJGLZBufferState object as a regular ZBufferState.

Specified by:
createZBufferState in interface Renderer
Returns:
a ZBufferState object.

createVertexProgramState

public VertexProgramState createVertexProgramState()
createVertexProgramState returns a new LWJGLVertexProgramState object as a regular VertexProgramState.

Specified by:
createVertexProgramState in interface Renderer
Returns:
a LWJGLVertexProgramState object.

createFragmentProgramState

public FragmentProgramState createFragmentProgramState()
createFragmentProgramState returns a new LWJGLFragmentProgramState object as a regular FragmentProgramState.

Specified by:
createFragmentProgramState in interface Renderer
Returns:
a LWJGLFragmentProgramState object.

createGLSLShaderObjectsState

public GLSLShaderObjectsState createGLSLShaderObjectsState()
createShaderObjectsState returns a new LWJGLShaderObjectsState object as a regular ShaderObjectsState.

Specified by:
createGLSLShaderObjectsState in interface Renderer
Returns:
an ShaderObjectsState object.

createStencilState

public StencilState createStencilState()
createStencilState returns a new LWJGLStencilState object as a regular StencilState.

Specified by:
createStencilState in interface Renderer
Returns:
a StencilState object.

setBackgroundColor

public void setBackgroundColor(ColorRGBA c)
setBackgroundColor sets the OpenGL clear color to the color specified.

Specified by:
setBackgroundColor in interface Renderer
Parameters:
c - the color to set the background color to.
See Also:
Renderer.setBackgroundColor(com.jme.renderer.ColorRGBA)

getBackgroundColor

public ColorRGBA getBackgroundColor()
getBackgroundColor retrieves the clear color of the current OpenGL context.

Specified by:
getBackgroundColor in interface Renderer
Returns:
the current clear color.
See Also:
Renderer.getBackgroundColor()

clearZBuffer

public void clearZBuffer()
clearZBuffer clears the OpenGL depth buffer.

Specified by:
clearZBuffer in interface Renderer
See Also:
Renderer.clearZBuffer()

clearColorBuffer

public void clearColorBuffer()
clearBackBuffer clears the OpenGL color buffer.

Specified by:
clearColorBuffer in interface Renderer
See Also:
com.jme.renderer.Renderer#clearBackBuffer()

clearBuffers

public void clearBuffers()
clearBuffers clears both the color and the depth buffer.

Specified by:
clearBuffers in interface Renderer
See Also:
Renderer.clearBuffers()

clearStrictBuffers

public void clearStrictBuffers()
clearBuffers clears both the color and the depth buffer for only the part of the buffer defined by the renderer width/height.

Specified by:
clearStrictBuffers in interface Renderer
See Also:
Renderer.clearBuffers()

displayBackBuffer

public void displayBackBuffer()
displayBackBuffer renders any queued items then flips the rendered buffer (back) with the currently displayed buffer.

Specified by:
displayBackBuffer in interface Renderer
See Also:
Renderer.displayBackBuffer()

setOrtho

public void setOrtho()
Description copied from interface: Renderer
setOrtho sets the display system to be in orthographic mode. If the system has already been set to orthographic mode a JmeException is thrown. The origin (0,0) is the bottom left of the screen.

Specified by:
setOrtho in interface Renderer

setOrthoCenter

public void setOrthoCenter()
Description copied from interface: Renderer
setOrthoCenter sets the display system to be in orthographic mode. If the system has already been set to orthographic mode a JmeException is thrown. The origin (0,0) is the center of the screen.

Specified by:
setOrthoCenter in interface Renderer

unsetOrtho

public void unsetOrtho()
Description copied from interface: Renderer
unsetOrhto unsets the display system from orthographic mode back into regular projection mode. If the system is not in orthographic mode a JmeException is thrown.

Specified by:
unsetOrtho in interface Renderer

takeScreenShot

public boolean takeScreenShot(java.lang.String filename)
takeScreenShot saves the current buffer to a file. The file name is provided, and .png will be appended. True is returned if the capture was successful, false otherwise.

Specified by:
takeScreenShot in interface Renderer
Parameters:
filename - the name of the file to save.
Returns:
true if successful, false otherwise.

grabScreenContents

public void grabScreenContents(java.nio.IntBuffer buff,
                               int x,
                               int y,
                               int w,
                               int h)
grabScreenContents reads a block of pixels from the current framebuffer.

Specified by:
grabScreenContents in interface Renderer
Parameters:
buff - a buffer to store contents in.
x - - x starting point of block
y - - y starting point of block
w - - width of block
h - - height of block

draw

public void draw(Point p)
draw draws a point object where a point contains a collection of vertices, normals, colors and texture coordinates.

Specified by:
draw in interface Renderer
Parameters:
p - the point object to render.
See Also:
Renderer.draw(com.jme.scene.Point)

draw

public void draw(Line l)
draw draws a line object where a line contains a collection of vertices, normals, colors and texture coordinates.

Specified by:
draw in interface Renderer
Parameters:
l - the line object to render.
See Also:
Renderer.draw(com.jme.scene.Line)

draw

public void draw(Curve c)
draw renders a curve object.

Specified by:
draw in interface Renderer
Parameters:
c - the curve object to render.

draw

public void draw(TriMesh t)
draw renders a TriMesh object including it's normals, colors, textures and vertices.

Specified by:
draw in interface Renderer
Parameters:
t - the mesh to render.
See Also:
Renderer.draw(com.jme.scene.TriMesh)

draw

public void draw(CompositeMesh t)
draw renders a CompositeMesh object including it's normals, colors, textures and vertices.

Specified by:
draw in interface Renderer
Parameters:
t - the mesh to render.
See Also:
Renderer.draw(com.jme.scene.CompositeMesh)

prepVBO

public void prepVBO(Geometry g)

drawBounds

public void drawBounds(Geometry g)
draw renders a TriMesh object including it's normals, colors, textures and vertices.

Specified by:
drawBounds in interface Renderer
Parameters:
g - the mesh to render.
See Also:
Renderer.draw(com.jme.scene.TriMesh)

drawBounds

public void drawBounds(BoundingVolume bv)
draw renders a TriMesh object including it's normals, colors, textures and vertices.

Specified by:
drawBounds in interface Renderer
Parameters:
bv - the mesh to render.
See Also:
Renderer.draw(com.jme.scene.TriMesh)

draw

public void draw(Spatial s)
draw renders a scene by calling the nodes onDraw method.

Specified by:
draw in interface Renderer
Parameters:
s - the scene to render.
See Also:
Renderer.draw(com.jme.scene.Spatial)

drawBounds

public void drawBounds(Spatial s)
drawBounds renders a scene by calling the nodes onDraw method.

Specified by:
drawBounds in interface Renderer
Parameters:
s - the Spatial to render bounds for.
See Also:
Renderer.draw(com.jme.scene.Spatial)

draw

public void draw(Text t)
draw renders a text object using a predefined font.

Specified by:
draw in interface Renderer
Parameters:
t - the text object to be rendered.
See Also:
Renderer.draw(com.jme.scene.Text)

draw

public void draw(WidgetRenderer wr)
draw renders a WidgetRenderer object to the back buffer.

Specified by:
draw in interface Renderer
Parameters:
wr - the WidgetPanel to be rendered.
See Also:
Renderer.draw(WidgetRenderer)

enableStatistics

public void enableStatistics(boolean value)
enableStatistics will turn on statistics gathering.

Specified by:
enableStatistics in interface Renderer
Parameters:
value - true to use statistics, false otherwise.

clearStatistics

public void clearStatistics()
clearStatistics resets the vertices and triangles counter for the statistics information.

Specified by:
clearStatistics in interface Renderer

getStatistics

public java.lang.String getStatistics()
getStatistics returns a string value of the rendering statistics information (number of triangles and number of vertices).

Specified by:
getStatistics in interface Renderer
Returns:
the string representation of the current statistics.

getStatistics

public java.lang.StringBuffer getStatistics(java.lang.StringBuffer a)
getStatistics returns a string value of the rendering statistics information (number of triangles and number of vertices).

Specified by:
getStatistics in interface Renderer
Parameters:
a - The string buffer to store the result in.
Returns:
the string representation of the current statistics.

isHeadless

public boolean isHeadless()
See Renderer.isHeadless()

Specified by:
isHeadless in interface Renderer
Returns:
boolean

setHeadless

public void setHeadless(boolean headless)
See Renderer.setHeadless()

Specified by:
setHeadless in interface Renderer
Parameters:
headless - boolean
Returns:
boolean

checkAndAdd

public boolean checkAndAdd(Spatial s)
Description copied from interface: Renderer
Check a given Spatial to see if it should be queued. return true if it was queued.

Specified by:
checkAndAdd in interface Renderer
Parameters:
s - Spatial to check
Returns:
true if it was queued.

getQueue

public RenderQueue getQueue()
Description copied from interface: Renderer
Get the render queue associated with this Renderer.

Specified by:
getQueue in interface Renderer
Returns:
RenderQueue

isProcessingQueue

public boolean isProcessingQueue()
Description copied from interface: Renderer
Return true if this renderer is in the middle of processing its RenderQueue.

Specified by:
isProcessingQueue in interface Renderer
Returns:
boolean

supportsVBO

public boolean supportsVBO()
Return true if the system running this supports VBO

Specified by:
supportsVBO in interface Renderer
Returns:
boolean true if VBO supported

getWidth

public int getWidth()
Description copied from interface: Renderer
Retrieve the width set on this renderer.

Specified by:
getWidth in interface Renderer
Returns:
width

getHeight

public int getHeight()
Description copied from interface: Renderer
Retrieve the height set on this renderer.

Specified by:
getHeight in interface Renderer
Returns:
height