Package edu.cnu.mdi.mdi3D.panel
Class TextRendering3D
java.lang.Object
edu.cnu.mdi.mdi3D.panel.TextRendering3D
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAnchor point used to place text relative to its projected pixel position.static final classImmutable drawing style for one text pass. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbegin(com.jogamp.opengl.GLAutoDrawable drawable) Begin a batched text rendering pass.voiddispose()Release the underlying JOGL text renderer.booleandrawProjected(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.voiddrawScreen(String text, int x, int y, TextRendering3D.Style style) Draw text directly in screen space.booleandrawWorld(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.booleandrawWorldOneShot(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.voidend()End the current batched text rendering pass.static voidpopOverlayState(com.jogamp.opengl.GL2 gl) Restore state pushed bypushOverlayState(GL2, GLAutoDrawable).static voidpushOverlayState(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.GLAutoDrawable drawable) Push an OpenGL state suitable for 2D overlay drawing without depth testing.
-
Constructor Details
-
TextRendering3D
Create a text-rendering helper for a font.- Parameters:
font- font to use; ifnull, 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. Callend()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 claritygl- current GL2 context while the 3D model-view/projection state is activetext- text to draw; blank ornulltext is ignoredx- world x coordinatey- world y coordinatez- world z coordinatedx- pixel offset applied after projection, positive rightdy- pixel offset applied after projection, positive upanchor- text anchor; ifnull,TextRendering3D.Anchor.LEFTis usedstyle- drawing style; ifnull,TextRendering3D.Style.label()is used- Returns:
trueif the label was drawn;falseif 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
Draw text directly in screen space. The helper must be inside abegin(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 bypushOverlayState(GL2, GLAutoDrawable).
-