sdr 0.7

net.cscott.sdr.anim
Class TextureText

java.lang.Object
  extended by com.jme.scene.SceneElement
      extended by com.jme.scene.Spatial
          extended by com.jme.scene.Node
              extended by net.cscott.sdr.anim.TextureText
All Implemented Interfaces:
com.jme.util.export.Savable, Serializable

public class TextureText
extends com.jme.scene.Node

TextureText renders text to a textured quad. This allows great flexibility in choice of font & size, albeit by burning texture memory. TextureText stripes the text across a square texture to (hopefully) optimally use the texels, allowing the use of very small texture sizes. In my experiments, a 64x64 texture yields only-slightly-fuzzy text for a 400-pixel-wide string. The origin of the TextureText Node is at the specified justification point of the text string, allowing easier placement.

Version:
$Id: TextureText.java,v 1.9 2006-11-22 20:56:55 cananian Exp $
Author:
C. Scott Ananian
See Also:
Serialized Form

Nested Class Summary
static class TextureText.JustifyX
          An enumeration of horizontal justification options.
static class TextureText.JustifyY
          An enumeration of vertical justification options.
 
Field Summary
 
Fields inherited from class com.jme.scene.Node
children
 
Fields inherited from class com.jme.scene.Spatial
geometricalControllers, localRotation, localScale, localTranslation, parent, worldRotation, worldScale, worldTranslation
 
Fields inherited from class com.jme.scene.SceneElement
COMPOSITE_MESH, CULL_ALWAYS, CULL_DYNAMIC, CULL_INHERIT, CULL_NEVER, cullMode, frustrumIntersects, GEOMBATCH, GEOMETRY, isCollidable, lightCombineMode, LOCKED_BOUNDS, LOCKED_BRANCH, LOCKED_MESH_DATA, LOCKED_NONE, LOCKED_SHADOWS, LOCKED_TRANSFORMS, lockedMode, name, NM_GL_NORMALIZE_IF_SCALED, NM_GL_NORMALIZE_PROVIDED, NM_INHERIT, NM_OFF, NM_USE_PROVIDED, NODE, normalsMode, QUADBATCH, queueDistance, renderQueueMode, renderStateList, SHARED_MESH, SHAREDBATCH, SKY_BOX, TERRAIN_BLOCK, TERRAIN_PAGE, textureCombineMode, TRIANGLEBATCH, TRIMESH, worldBound, zOrder
 
Constructor Summary
TextureText(String nodeName, Font font, int textureSize)
          Create a TextureText with the given node name (required to be unique in the scene graph) which will display using the given Font and use the given amount of texture memory.
 
Method Summary
 float getHeight()
          Return the actual height of this textured text object.
 float getWidth()
          Return the actual width of this textured text object.
static void main(String[] args)
          Simple test harness to exercise the features of this class.
 void setAlign(TextureText.JustifyX alignX, TextureText.JustifyY alignY)
          Set the desired alignment of this text node.
 void setColor(com.jme.renderer.ColorRGBA color)
          Set the foreground color in which to display the text.
 void setMaxSize(float maxWidth, float maxHeight)
          Set the maximum width/height of this node.
 void setText(String text)
          Set the text to display.
 
Methods inherited from class com.jme.scene.Node
applyRenderState, attachChild, attachChildAt, batchChange, detachAllChildren, detachChild, detachChildAt, detachChildNamed, draw, findCollisions, findPick, getChild, getChild, getChildIndex, getChildren, getQuantity, getTriangleCount, getType, getVertexCount, hasChild, hasCollision, lockBounds, lockMeshes, lockShadows, lockTransforms, read, setModelBound, swapChildren, unlockBounds, unlockMeshes, unlockShadows, unlockTransforms, updateModelBound, updateWorldBound, updateWorldData, write
 
Methods inherited from class com.jme.scene.Spatial
addController, calculateCollisions, calculatePick, getController, getControllers, getCullMode, getLightCombineMode, getLocalRotation, getLocalScale, getLocalTranslation, getNormalsMode, getParent, getRenderQueueMode, getTextureCombineMode, getUserData, getWorldRotation, getWorldScale, getWorldTranslation, localToWorld, lookAt, onDraw, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeController, removeFromParent, removeUserData, rotateUpTo, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setLocalTranslation, setParent, setUserData, setZOrder, updateGeometricState, updateWorldRotation, updateWorldScale, updateWorldTranslation, updateWorldVectors, worldToLocal
 
Methods inherited from class com.jme.scene.SceneElement
clearRenderState, getClassTag, getLastFrustumIntersection, getLocalCullMode, getLocalLightCombineMode, getLocalNormalsMode, getLocalRenderQueueMode, getLocalTextureCombineMode, getLocks, getName, getRenderState, getWorldBound, getZOrder, isCollidable, lock, lock, lockBranch, lockMeshes, setCullMode, setIsCollidable, setLastFrustumIntersection, setLightCombineMode, setLocks, setLocks, setName, setNormalsMode, setRenderQueueMode, setRenderState, setTextureCombineMode, setZOrder, toString, unlock, unlock, unlockBranch, unlockMeshes, updateRenderState, updateRenderState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jme.util.export.Savable
getClassTag
 

Constructor Detail

TextureText

public TextureText(String nodeName,
                   Font font,
                   int textureSize)
Create a TextureText with the given node name (required to be unique in the scene graph) which will display using the given Font and use the given amount of texture memory. For a 64 texel by 64 texel texture, textureSize should be 64.

Method Detail

setAlign

public void setAlign(TextureText.JustifyX alignX,
                     TextureText.JustifyY alignY)
Set the desired alignment of this text node. The node's local origin will be at the specified alignment point of the text.


setMaxSize

public void setMaxSize(float maxWidth,
                       float maxHeight)
Set the maximum width/height of this node. The generated text is guaranteed not to exceed this size.


setText

public void setText(String text)
Set the text to display. This method is thread-safe, but rather expensive. As long as you're not updating the text here in every frame, you should be alright.


setColor

public void setColor(com.jme.renderer.ColorRGBA color)
Set the foreground color in which to display the text. The text always has a transparent background.


getHeight

public float getHeight()
Return the actual height of this textured text object.


getWidth

public float getWidth()
Return the actual width of this textured text object.


main

public static void main(String[] args)
                 throws Exception
Simple test harness to exercise the features of this class. Note that the texture size used below (64x64) is intentionally a little low for the size of the text object (400 pixels wide), so that we can see how the texture filtering works. You'll get much better quality if you increase the texture size to 128x128 in the TextureText constructor.

Throws:
Exception

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian