Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ACG::SceneGraph::TextNode Class Reference

#include <ACG/Scenegraph/TextNode.hh>

Inheritance diagram for ACG::SceneGraph::TextNode:
ACG::SceneGraph::ACG::SceneGraph::BaseNode

Public Types

enum  TextMode { SCREEN_ALIGNED, SCREEN_ALIGNED_STATIC_SIZE, OBJECT_ALIGNED }
 
- Public Types inherited from ACG::SceneGraph::ACG::SceneGraph::BaseNode
enum  StatusMode { Active = 0x1, HideNode = 0x2, HideChildren = 0x4, HideSubtree = 0x8 }
 Status modi. More...
 
enum  TraverseMode { NodeFirst = 0x1, ChildrenFirst = 0x2, SecondPass = 0x4 }
 Node traverse types. More...
 
typedef std::list< BaseNode * >
::const_iterator 
ConstChildIter
 allows to iterate over children
 
typedef std::list< BaseNode * >
::iterator 
ChildIter
 allows to iterate over children
 
typedef std::list< BaseNode * >
::const_reverse_iterator 
ConstChildRIter
 allows to reverse iterate over children
 
typedef std::list< BaseNode * >
::reverse_iterator 
ChildRIter
 allows to reverse iterate over children
 
enum  PASSES {
  NOPASS = 0, ALLPASSES = 1 << 0, PASS_1 = 1 << 1, PASS_2 = 1 << 2,
  PASS_3 = 1 << 3, PASS_4 = 1 << 4, PASS_5 = 1 << 5, PASS_6 = 1 << 6,
  PASS_7 = 1 << 7, PASS_8 = 1 << 8
}
 This enum should be used to enable rendering of a node in different.
 
typedef unsigned int MultipassBitMask
 Multipass pass bit mask type.
 

Public Member Functions

 TextNode (BaseNode *_parent=0, std::string _name="<TextNode>", TextMode _textMode=SCREEN_ALIGNED, bool _alwaysOnTop=false)
 
 ~TextNode ()
 destructor
 
 ACG_CLASSNAME (TextNode)
 static name of this class
 
DrawModes::DrawMode availableDrawModes () const
 return available draw modes
 
void boundingBox (Vec3d &_bbMin, Vec3d &_bbMax)
 update bounding box
 
void draw (GLState &_state, const DrawModes::DrawMode &_drawMode)
 draw Text
 
void enter (GLState &_state, const DrawModes::DrawMode &_drawmode)
 set texture and drawing states
 
void leave (GLState &_state, const DrawModes::DrawMode &_drawmode)
 restore texture and drawing states
 
void getRenderObjects (ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
 set RenderObject for Shader pipeline renderer
 
void setRenderingMode (TextMode _textMode)
 
void setAlwaysOnTop (bool _alwaysOnTop)
 draw the text always on top
 
bool alwaysOnTop ()
 returns wheter always on top is setted or not
 
TextMode renderingMode ()
 returns the rendering mode (SCREEN_ALIGNED or OBJECT_ALIGNED)
 
void setText (std::string _text)
 sets the string that will be rendered
 
void setSize (const double _size)
 sets the size by which the quads displaying the text will be scaled
 
void setPixelSize (const unsigned int _size)
 sets the pixelsize of the text (only available for the SCREEN_ALIGNED_STATIC_SIZE mode and only works, if scaling is 1)
 
void setFont (const QFont &_font)
 sets the font to be used for generating a texture with most characters of the chosen font
 
float lastScale ()
 returns the scaling factor for screen aligned text the text. returns 0, if textmode is not SCREEN_ALIGNED_STATIC_SIZE More...
 
- Public Member Functions inherited from ACG::SceneGraph::ACG::SceneGraph::BaseNode
 BaseNode (BaseNode *_parent=0, std::string _name="<unknown>")
 Default constructor.
 
 BaseNode (BaseNode *_parent, BaseNode *_child, std::string _name="<unknown>")
 Put this node between _parent and _child.
 
virtual ~BaseNode ()
 Destructor.
 
void delete_subtree ()
 Delete the whole subtree of this node. More...
 
virtual const std::string & className () const =0
 Return class name (implemented by the ACG_CLASSNAME macro)
 
virtual void enter (GLState &, const DrawModes::DrawMode &)
 
virtual void draw (GLState &, const DrawModes::DrawMode &)
 Draw this node using the draw modes _drawMode. More...
 
virtual void leave (GLState &, const DrawModes::DrawMode &)
 
virtual void enterPick (GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
 
virtual void pick (GLState &, PickTarget)
 
virtual void leavePick (GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode)
 
void enablePicking (bool _enable)
 
bool pickingEnabled ()
 
virtual void mouseEvent (GLState &, QMouseEvent *)
 Handle mouse event (some interaction, e.g. modeling)
 
void setDirty (bool _dirty=true)
 mark node for redrawn
 
bool isDirty () const
 Check if node should be redrawn.
 
ChildIter childrenBegin ()
 Returns: begin-iterator of children.
 
ConstChildIter childrenBegin () const
 Same but cont.
 
ChildIter childrenEnd ()
 Returns: end-iterator of children.
 
ConstChildIter childrenEnd () const
 Same but const.
 
ChildRIter childrenRBegin ()
 Returns: reverse begin-iterator of children.
 
ConstChildRIter childrenRBegin () const
 Same but const.
 
ChildRIter childrenREnd ()
 Returns: reverse end-iterator of children.
 
ConstChildRIter childrenREnd () const
 Same but const.
 
void push_back (BaseNode *_node)
 Insert _node at the end of the list of children.
 
void remove (ChildIter _pos)
 
size_t nChildren () const
 number of children
 
ChildIter find (BaseNode *_node)
 
BaseNodefind (const std::string &_name)
 
BaseNodeparent ()
 Get the nodes parent node.
 
const BaseNodeparent () const
 Get the nodes parent node.
 
void set_parent (BaseNode *_parent)
 Set the parent of this node. More...
 
StatusMode status () const
 Get node's status.
 
void set_status (StatusMode _s)
 Set the status of this node.
 
void hide ()
 Hide Node: set status to HideNode.
 
void show ()
 Show node: set status to Active.
 
bool visible ()
 Is node visible (status == Active)?
 
bool hidden ()
 Is node not visible (status != Active)?
 
std::string name () const
 Returns: name of node (needs not be unique)
 
void name (const std::string &_name)
 rename a node
 
unsigned int id () const
 
DrawModes::DrawMode drawMode () const
 Return the own draw modes of this node.
 
void drawMode (DrawModes::DrawMode _drawMode)
 
unsigned int traverseMode () const
 Return how the node should be traversed.
 
void setTraverseMode (unsigned int _mode)
 Set traverse mode for node.
 
MultipassBitMask multipassStatus () const
 Get the current multipass settings for the nodes status functions. More...
 
void setMultipassStatus (const MultipassBitMask _passStatus)
 Set multipass settings for the nodes status functions. More...
 
void multipassStatusSetActive (const unsigned int _i, bool _active)
 Set multipass status to traverse in a specific pass. More...
 
bool multipassStatusActive (const unsigned int _i) const
 Get multipass status to traverse in a specific pass. More...
 
MultipassBitMask multipassNode () const
 Get the current multipass settings for the node. More...
 
void setMultipassNode (const MultipassBitMask _passNode)
 Set multipass settings for the node. More...
 
void multipassNodeSetActive (const unsigned int _i, bool _active)
 Set Node status to traverse in a specific pass. More...
 
bool multipassNodeActive (const unsigned int _i) const
 Get Node status to traverse in a specific pass. More...
 
void setRenderObjectShaders (const std::string &_vertexShaderFile, const std::string &_geometryShaderFile, const std::string &_fragmentShaderFile, bool _relativePaths=true, DrawModes::DrawModePrimitive _primitiveType=DrawModes::PRIMITIVE_POLYGON)
 Set custom shaders. More...
 
void setRenderObjectShaders (const std::string &_vertexShaderFile, const std::string &_tessControlShaderFile, const std::string &_tessEvalShaderFile, const std::string &_geometryShaderFile, const std::string &_fragmentShaderFile, bool _relativePaths=true, DrawModes::DrawModePrimitive _primitiveType=DrawModes::PRIMITIVE_POLYGON)
 Set custom shaders. More...
 
void setRenderObjectUniformPool (const GLSL::UniformPool *_pool)
 Set uniforms for shader based rendering. More...
 
const GLSL::UniformPoolgetRenderObjectUniformPool ()
 Get uniforms for shader based rendering. More...
 
void setRenderObjectTexture (int _samplerSlot, GLuint _texId, GLenum _texType=GL_TEXTURE_2D)
 Set textures for shader based rendering. More...
 
void setRenderObjectModifier (RenderObjectModifier *_modifier)
 Set modifier for render objects. More...
 
RenderObjectModifiergetRenderObjectModifier ()
 Get render-object modifier. More...
 
void applyRenderObjectSettings (DrawModes::DrawModePrimitive _primitive, RenderObject *_obj) const
 Set shaders, textures and uniforms as provided by user to a render-object. More...
 

Static Protected Member Functions

static void updateFont ()
 

Private Member Functions

void updateVBO ()
 
void bindVBO ()
 binds vbo_ and sets the necessary OpenGL states
 
void unbindVBO ()
 unbinds vbo_
 
void applyScreenAligned (GLState &_state)
 modifies _state so that the modelviewmatrix will be screenaligned. remember to call "_state.pop_modelview_matrix();" twice
 

Static Private Member Functions

static quint32 nearestPowerOfTwo (quint32 num)
 returns the nearest greater power of 2 to num
 
static std::map< char,
std::pair< unsigned int,
unsigned int > > 
createMap ()
 

Private Attributes

double size_
 scaling factor by which the quads in vbo_ are scaled
 
unsigned pixelSize_
 pixelSize of the text for the SCREEN_ALIGNED_STATIC_SIZE mode
 
std::string text_
 text to be displayed on quads in vbo_
 
TextMode textMode_
 current display mode of text_ (SCREEN_ALIGNED, SCREEN_ALIGNED_STATIC_SIZE or OBJECT_ALIGNED)
 
GLuint vbo_
 
std::vector< GLfloat > vertexBuffer_
 buffer of vertex coordinates and texture coordinates of the quads
 
size_t oldVboSize_
 
bool blendEnabled_
 stores if GL_BLEND was enabled on entering TextNode
 
bool texture2dEnabled_
 stores if GL_TEXTURE_2D was enabled on entering TextNode
 
bool cullFaceEnabled_
 stores if GL_CULL_FACE was enabled on entering TextNode
 
bool depthEnabled_
 stores if GL_DEPTH_TEST was enabled on entering TextNode
 
bool alwaysOnTop_
 stores if text should be drawn always on top
 
bool alphaTest_
 stores if the alpha test was enabled
 
float alphaTestValue_
 stores the alpha value used for alpha test
 
GLenum alphaTestFunc_
 stores alpha test comparison function
 
GLint blendSrc_
 stores the sfactor parameter of glBlendFunc on entering TextNode
 
GLint blendDest_
 stores the dfactor parameter of glBlendFunc on entering TextNode
 
ACG::VertexDeclaration vertexDecl_
 stores the vertex declaration
 
float lastScale_
 stores the last scaling factor the text computed to SCREEN_ALIGNED_STATIC_SIZE
 

Static Private Attributes

static std::map< char,
std::pair< unsigned int,
unsigned int > > 
charToIndex_ = TextNode::createMap()
 maps most readable characters to indices for texture coordinate calculation in updateVBO()
 
static QFont qfont_ = QFont("Helvetica", 30)
 font that is used to generate the texture in updateFont()
 
static GLuint texture_ = 0
 handle for the texture into which characters from qfont_ are painted in updateFont()
 
static int imageWidth_ = 0
 width of the generated texture
 
static int imageHeight_ = 0
 height of the generated texture
 
static qreal maxFontWidth_ = 0.0
 max width of qfont
 
static const int numberOfChars_ = 94
 number of characters that are drawn into the texture
 
static const unsigned int rows_ = 10
 number of rows of characters in the texture
 
static const unsigned int columns_ = 10
 number of columns of characters in the texture
 
static bool initialised_ = false
 this is used to ensure that the texture is only generated once when necessary
 
static QColor color_ = QColor(255, 0, 0)
 color that is used to draw the characters into the texture in updateFont()
 

Detailed Description

CoordsysNode renders A coordinate system.

TODO: Den Fall mode_ == POSITION implementieren. 25.11.08

TextNode can be used to display a string on quads in OpenGL. This string can be set with setText(std::string _text). A TextNode can be attached to a parent node by using the function BaseObjectData::addAdditionalNode. The quads can then be set to align to the parent (OBJECT_ALIGNED) via the setRenderingMode(TextMode _textMode) function. Alternatively the quads can be aligned to the screen (SCREEN_ALIGNED). The font that is used to display text on the screen can be set with the setFont(const QFont& _font) function. Finally the quads can be scaled via the setSize(double _size) function.

Definition at line 96 of file TextNode.hh.

Member Enumeration Documentation

Enumerator
SCREEN_ALIGNED_STATIC_SIZE 

Text will always stay parallel to screen.

OBJECT_ALIGNED 

Text will always stay parallel to screen (like SCREEN_ALIGNED) and text has static size, independent of the camera position.

Text will be transformed and projected by Modelview and projection matrix

Definition at line 100 of file TextNode.hh.

Constructor & Destructor Documentation

ACG::SceneGraph::TextNode::TextNode ( BaseNode _parent = 0,
std::string  _name = "<TextNode>",
TextMode  _textMode = SCREEN_ALIGNED,
bool  _alwaysOnTop = false 
)

default constructor

Parameters
_parentDefine the parent Node this node gets attached to
_nameName of this Node
_textModeDefine the text rendering style ( see TextNode::TextMode )
_alwaysOnTopDraw text on top of everything else?

Definition at line 96 of file TextNode.cc.

Member Function Documentation

std::map< char, std::pair< unsigned int, unsigned int > > ACG::SceneGraph::TextNode::createMap ( )
staticprivate

Creates a map charToIndex_ from most characters to an incrementing set of indices. These indices are used to create the texture coordinates in updateVBO().

Definition at line 230 of file TextNode.cc.

float ACG::SceneGraph::TextNode::lastScale ( )
inline

returns the scaling factor for screen aligned text the text. returns 0, if textmode is not SCREEN_ALIGNED_STATIC_SIZE

screen aligned static size text will be scaled up/down in 3d space to achieve the static size in screen space lastScale returns the last scaling factor where the text was multiplied, to compute e.g. a distance which is also static in screen space

Definition at line 172 of file TextNode.hh.

void ACG::SceneGraph::TextNode::setRenderingMode ( TextMode  _textMode)

Set the rendering mode ( see TextNode::TextMode )

Definition at line 167 of file TextNode.cc.

void ACG::SceneGraph::TextNode::updateFont ( )
staticprotected

Generates a texture by drawing most characters into one texture. This texture is then used to draw single characters onto quads

Definition at line 369 of file TextNode.cc.

void ACG::SceneGraph::TextNode::updateVBO ( )
private

generates a quad for each character in text_ and also calculates the texture coordinates for each quad's character

Definition at line 432 of file TextNode.cc.

Member Data Documentation

GLuint ACG::SceneGraph::TextNode::vbo_
private

handle to the vertex buffer object, containing the quads on which the characters in text_ are rendered

Definition at line 224 of file TextNode.hh.


The documentation for this class was generated from the following files: