TextNode.hh 6.92 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
Jan Möbius's avatar
Jan Möbius committed
38
39
40
41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58




//=============================================================================
//
//  CLASS PointNode
//
//=============================================================================

#ifndef ACG_TEXTNODE_HH
#define ACG_TEXTNODE_HH


//== INCLUDES =================================================================

#include "BaseNode.hh"
59
#include "TransformNode.hh"
Jan Möbius's avatar
 
Jan Möbius committed
60
61
#include "DrawModes.hh"
#include <vector>
62
63
64
65
66
#include <QFont>
#include <QFontMetrics>
#include <QImage>
#include <QPainter>
#include <QGLWidget>
Jan Möbius's avatar
 
Jan Möbius committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

//== NAMESPACES ===============================================================

namespace ACG {
namespace SceneGraph {

//== CLASS DEFINITION =========================================================



/** \class TextNode TextNode.hh <ACG/Scenegraph/TextNode.hh>

    TextNode renders Text.

**/

class ACGDLLEXPORT TextNode : public BaseNode
{
public:

  enum TextMode {
    SCREEN_ALIGNED, /// Text will always stay parallel to screen
    OBJECT_ALIGNED  /// Text will be transformed and projected by Modelview and projection matrix
  };

  /** default constructor
   * @param _parent Define the parent Node this node gets attached to
   * @param _fontfile Font File ( should include full path )
   * @param _name Name of this Node
   * @param _textMode Define the text rendering style ( see TextNode::TextMode )
   */
  TextNode( std::string       _fontFile,
            BaseNode*         _parent=0,
	         std::string  _name="<TextNode>",
            TextMode     _textMode = SCREEN_ALIGNED)
            : BaseNode(_parent, _name),
103
              size_(1),
Jan Möbius's avatar
 
Jan Möbius committed
104
              fontFile_(_fontFile),
105
106
107
108
109
110
111
112
              textMode_(_textMode),
              vbo_(0),
              vertexBuffer_(0),
              blendEnabled_(false),
              texture2dEnabled_(false),
              cullFaceEnabled_(false),
              blendSrc_(0),
              blendDest_(0)
Jan Möbius's avatar
 
Jan Möbius committed
113
  {
114
115
    UpdateFont();
    updateVBO();
Jan Möbius's avatar
 
Jan Möbius committed
116
117
118
119
120
121
122
123
124
  }

  /// destructor
  ~TextNode();

  /// static name of this class
  ACG_CLASSNAME(TextNode);

  /// return available draw modes
Jan Möbius's avatar
Jan Möbius committed
125
  DrawModes::DrawMode  availableDrawModes() const;
Jan Möbius's avatar
 
Jan Möbius committed
126
127

  /// update bounding box
128
  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
Jan Möbius's avatar
 
Jan Möbius committed
129
130

  /// draw Text
131
  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
Jan Möbius's avatar
 
Jan Möbius committed
132

133
134
135
136
137
138
  /// set texture and drawing states
  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);

  /// restore texture and drawing states
  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);

Jan Möbius's avatar
 
Jan Möbius committed
139
140
141
142
143
144
145
  /** Set the rendering mode ( see TextNode::TextMode )
   */

  void setRenderingMode(TextMode _textMode) { textMode_ = _textMode; };

  TextMode renderingMode() { return textMode_; };

146
147
	/// sets the text that will be rendered
  void setText(std::string _text) {text_ = _text; updateVBO();};
Jan Möbius's avatar
 
Jan Möbius committed
148

149
150
151
152
153
	/// sets the scaling size of the TextNode
  void setSize(unsigned int _size) {size_ = _size; updateVBO();};

	/// sets the font to be used
  void setFont(const QFont& _font);
Jan Möbius's avatar
 
Jan Möbius committed
154
155

protected:
156
  static void UpdateFont();
Jan Möbius's avatar
 
Jan Möbius committed
157
158

private:
159
160
161
162
163
  static uint32_t nearestPowerOfTwo(uint32_t num);
  void updateVBO();
  void bindVBO();
  void unbindVBO();
  static std::map<char, unsigned int> createMap();
Jan Möbius's avatar
 
Jan Möbius committed
164

165
private:
Jan Möbius's avatar
 
Jan Möbius committed
166
167
168
169
170
171
172
173
  unsigned int size_;

  std::string text_;

  std::string fontFile_;

  TextMode textMode_;

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  GLuint vbo_;

  std::vector<GLfloat> vertexBuffer_;

  bool blendEnabled_;

  bool texture2dEnabled_;

  bool cullFaceEnabled_;

  GLint blendSrc_;

  GLint blendDest_;

  static std::map<char, unsigned int> charToIndex_;

  static QFont qfont_;

  static GLuint texture_;

  static int imageWidth_;

  static const int numberOfChars_ = 94;

  static bool initialised_;

  static QColor color_;
};
Jan Möbius's avatar
 
Jan Möbius committed
202
203
204
205
206
207
208

//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#endif // ACG_TEXTNODE_HH defined
//=============================================================================