Class Java2DRenderer

java.lang.Object
nl.colorize.multimedialib.renderer.java2d.Java2DRenderer
All Implemented Interfaces:
Renderer, SceneContext

public class Java2DRenderer extends Object implements Renderer, SceneContext
Implementation of a renderer that uses APIs from the Java standard library. Graphics are displayed using Java 2D, AWT is used to create windows and capture keyboard events, and Java Sound is used to play audio.

The renderer will use two different threads: the rendering thread is used to update the graphics, while the Swing thread is used to listen for user input.

  • Constructor Details

    • Java2DRenderer

      public Java2DRenderer()
  • Method Details

    • start

      public void start(RenderConfig config, Scene initialScene)
      Description copied from interface: Renderer
      Starts this renderer based on the specified configuration. The renderer will initially display the specified scene.

      This method can be called from any thread. The renderer will run in its own thread, which is started by calling this method. All callback methods will be called from the renderer thread.

      Specified by:
      start in interface Renderer
    • createMesh

      public Mesh createMesh(Shape3D shape, ColorRGB color)
      Description copied from interface: SceneContext
      Programmatically creates a 3D polygon mesh with a solid color, based on the specified shape.
      Specified by:
      createMesh in interface SceneContext
    • project

      public Point2D project(Point3D position)
      Description copied from interface: SceneContext
      Returns the 3D world coordinates that correspond to the specified 2D canvas coordinates, based on the current camera position.
      Specified by:
      project in interface SceneContext
    • castPickRay

      public boolean castPickRay(Point2D canvasPosition, Box area)
      Description copied from interface: SceneContext
      Casts a pick ray from the specified 2D canvas position, and returns true if the pick ray intersects with the specified 3D world coordinates.
      Specified by:
      castPickRay in interface SceneContext
    • isSupported

      public boolean isSupported(GraphicsMode graphicsMode)
      Specified by:
      isSupported in interface Renderer
    • terminate

      public void terminate()
      Description copied from interface: SceneContext
      Terminates the renderer, which will end the animation loop and quit the application.
      Specified by:
      terminate in interface SceneContext
    • takeScreenshot

      public void takeScreenshot(File screenshotFile)
      Description copied from interface: SceneContext
      Captures a screenshot of the renderer's current graphics and then exports the screenshot to a PNG file.
      Specified by:
      takeScreenshot in interface SceneContext
    • getRendererName

      public String getRendererName()
      Description copied from interface: SceneContext
      Returns the display name for the underlying renderer. The display name will not include the word "renderer".
      Specified by:
      getRendererName in interface SceneContext
    • getConfig

      public RenderConfig getConfig()
      Specified by:
      getConfig in interface SceneContext
    • getInput

      public AWTInput getInput()
      Specified by:
      getInput in interface SceneContext
    • getMediaLoader

      public StandardMediaLoader getMediaLoader()
      Specified by:
      getMediaLoader in interface SceneContext
    • getNetwork

      public Network getNetwork()
      Specified by:
      getNetwork in interface SceneContext
    • getSceneManager

      public SceneManager getSceneManager()
      Specified by:
      getSceneManager in interface SceneContext
    • getStage

      public Stage getStage()
      Specified by:
      getStage in interface SceneContext