Module gl1
Package de.grogra.gl

Class TextRenderer3D

java.lang.Object
de.grogra.gl.TextRenderer3D

public class TextRenderer3D extends Object
This class renders a TrueType Font into OpenGL
Author:
Davide Raccagni, Erik Tollerud
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextRenderer3D(Font font, float depth)
    Intstantiates a new TextRenderer3D initially rendering in the specified font.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Draws the current compiled string, if any.
    void
    call(int index)
    Draws the specified compiled string, if any.
    int
    Creates the specified string as a display list.
    int
    compile(String str, float xOff, float yOff, float zOff, float scaleFactor)
    Creates the specified string as a display list.
    void
    Diposes of the ALL the current compiled shapes, if any.
    void
    dispose(int index)
    Diposes of the specified compiled shapes, if it is in the list.
    void
    draw(String str)
    Renders a string into the specified GL object, starting at the (0,0,0) point in OpenGL coordinates.
    void
    draw(String str, float xOff, float yOff, float zOff, float scaleFactor)
     
    Get the bounding box for the supplied string with the current font, etc.
    getBounds(String str, float scaleFactor)
    Get the bounding box for the supplied string for the current font and specified scale factor.
    boolean
    Gets whether normals are being calculated
    float
    Retrieves the z-depth used for this TextRenderer3D's text rendering.
    float
    Set the flatness to which the glyph's curves will be flattened
    Retrieves the Font currently associated with this TextRenderer3D
    boolean
    Determines if the text is being rendered as filled polygons or wireframes.
    void
    setCalcNormals(boolean normals)
    Sets whether the normals will eb calculated for each face
    void
    setDepth(float depth)
    Determines how long the sides of the rendered text is.
    void
    setFill(boolean fill)
    Sets if the text should be rendered as filled polygons or wireframe.
    void
    setFlatness(float flatness)
    Get the current flatness to which the glyph's curves will be flattened
    void
    setFont(Font font)
    Specifies which font to render with this TextRenderer3D

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TextRenderer3D

      public TextRenderer3D(Font font, float depth) throws NullPointerException
      Intstantiates a new TextRenderer3D initially rendering in the specified font.
      Parameters:
      font - - the initial font for this TextRenderer3D depth - the extruded depth for the font
      Throws:
      NullPointerException - if the supplied font is null
  • Method Details

    • setFont

      public void setFont(Font font) throws NullPointerException
      Specifies which font to render with this TextRenderer3D
      Parameters:
      font - a font to use for rendering *
      Throws:
      NullPointerException - if the supplied font is null
    • getFont

      public Font getFont()
      Retrieves the Font currently associated with this TextRenderer3D
      Returns:
      the Font in which this object renders strings
    • setDepth

      public void setDepth(float depth)
      Determines how long the sides of the rendered text is. In the special case of 0, the rendering is 2D.
      Parameters:
      depth - specifies the z-size of the rendered 3D text. Negative numbers will be set to 0.
    • getDepth

      public float getDepth()
      Retrieves the z-depth used for this TextRenderer3D's text rendering.
      Returns:
      the z-depth of the rendered 3D text.
    • setFill

      public void setFill(boolean fill)
      Sets if the text should be rendered as filled polygons or wireframe.
      Parameters:
      fill - if true, uses filled polygons, if false, renderings are wireframe.
    • isFill

      public boolean isFill()
      Determines if the text is being rendered as filled polygons or wireframes.
      Returns:
      if true, uses filled polygons, if false, renderings are wireframe.
    • getFlatness

      public float getFlatness()
      Set the flatness to which the glyph's curves will be flattened
      Returns:
    • setFlatness

      public void setFlatness(float flatness)
      Get the current flatness to which the glyph's curves will be flattened
    • setCalcNormals

      public void setCalcNormals(boolean normals)
      Sets whether the normals will eb calculated for each face
      Parameters:
      mode - the mode to render in. Default is flat.
    • getCalcNormals

      public boolean getCalcNormals()
      Gets whether normals are being calculated
      Returns:
      the normal technique for this TextRenderer3D.
      See Also:
      • setNormal(javax.media.opengl.GL,float,float,float,float,float,float)
    • draw

      public void draw(String str, float xOff, float yOff, float zOff, float scaleFactor)
    • draw

      public void draw(String str)
      Renders a string into the specified GL object, starting at the (0,0,0) point in OpenGL coordinates.
      Parameters:
      str - the string to render.
      glu - a GLU instance to use for the text rendering (provided to prevent continuous re-instantiation of a GLU object)
      gl - the OpenGL context in which to render the text.
    • compile

      public int compile(String str, float xOff, float yOff, float zOff, float scaleFactor)
      Creates the specified string as a display list. Can subsequently be drawn by calling "call".
      Parameters:
      str -
      xOff -
      yOff -
      zOff -
      scaleFactor -
    • compile

      public int compile(String str)
      Creates the specified string as a display list. Can subsequently be drawn by calling "call".
      Parameters:
      str -
    • call

      public void call()
      Draws the current compiled string, if any.
    • call

      public void call(int index)
      Draws the specified compiled string, if any.
    • dispose

      public void dispose()
      Diposes of the ALL the current compiled shapes, if any.
    • dispose

      public void dispose(int index)
      Diposes of the specified compiled shapes, if it is in the list. If it is the last-compiled, that index is cleared (set to -1)
    • getBounds

      public Rectangle2D getBounds(String str)
      Get the bounding box for the supplied string with the current font, etc.
      Parameters:
      str -
      Returns:
    • getBounds

      public Rectangle2D getBounds(String str, float scaleFactor)
      Get the bounding box for the supplied string for the current font and specified scale factor.
      Parameters:
      str -
      scaleFactor -
      Returns: