Class TextRendering3D

java.lang.Object
edu.cnu.mdi.mdi3D.panel.TextRendering3D

public final class TextRendering3D extends Object
Utility for rendering crisp, screen-space text associated with 3D world positions in an MDI-3D Panel3D.

The class projects a world-space point into window coordinates and then uses JOGL's TextRenderer to draw the text in pixel coordinates. This gives the text a constant on-screen size regardless of zoom, which is usually what is wanted for axes, tick labels, point labels, and plot annotations.

Important implementation detail: TextRenderer.beginRendering(...) installs a 2D projection. Therefore this helper snapshots the 3D scene matrices before the first text draw in each pass and uses those saved matrices for all later world-to-screen projections in that pass.

  • Constructor Details

    • TextRendering3D

      public TextRendering3D(Font font)
      Create a text-rendering helper for a font.
      Parameters:
      font - font to use; if null, a 12-point sans-serif font is used
  • Method Details

    • begin

      public void begin(com.jogamp.opengl.GLAutoDrawable drawable)
      Begin a batched text rendering pass. Call end() when done.
      Parameters:
      drawable - current drawable
    • end

      public void end()
      End the current batched text rendering pass.
    • dispose

      public void dispose()
      Release the underlying JOGL text renderer.
    • drawWorld

      public boolean drawWorld(Panel3D panel3D, com.jogamp.opengl.GL2 gl, String text, float x, float y, float z, int dx, int dy, TextRendering3D.Anchor anchor, TextRendering3D.Style style)
      Draw text attached to a 3D world coordinate.
      Parameters:
      panel3D - owning panel, retained for call-site clarity
      gl - current GL2 context while the 3D model-view/projection state is active
      text - text to draw; blank or null text is ignored
      x - world x coordinate
      y - world y coordinate
      z - world z coordinate
      dx - pixel offset applied after projection, positive right
      dy - pixel offset applied after projection, positive up
      anchor - text anchor; if null, TextRendering3D.Anchor.LEFT is used
      style - drawing style; if null, TextRendering3D.Style.label() is used
      Returns:
      true if the label was drawn; false if skipped
    • drawProjected

      public boolean drawProjected(String text, float winX, float winY, float winZ, int dx, int dy, TextRendering3D.Anchor anchor, TextRendering3D.Style style)
      Draw text at already-projected window coordinates. Window coordinates use the JOGL convention: origin at lower left.
    • drawScreen

      public void drawScreen(String text, int x, int y, TextRendering3D.Style style)
      Draw text directly in screen space. The helper must be inside a begin(GLAutoDrawable) / end() pair.
    • drawWorldOneShot

      public boolean drawWorldOneShot(Panel3D panel3D, com.jogamp.opengl.GLAutoDrawable drawable, com.jogamp.opengl.GL2 gl, String text, float x, float y, float z, int dx, int dy, TextRendering3D.Anchor anchor, TextRendering3D.Style style)
      Convenience one-shot method for drawing a single world-attached label.
    • pushOverlayState

      public static void pushOverlayState(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.GLAutoDrawable drawable)
      Push an OpenGL state suitable for 2D overlay drawing without depth testing.
    • popOverlayState

      public static void popOverlayState(com.jogamp.opengl.GL2 gl)
      Restore state pushed by pushOverlayState(GL2, GLAutoDrawable).