Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TextNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS PointNode
56 //
57 //=============================================================================
58 
59 #ifndef ACG_TEXTNODE_HH
60 #define ACG_TEXTNODE_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include "BaseNode.hh"
66 #include "TransformNode.hh"
67 #include "DrawModes.hh"
68 #include <ACG/GL/IRenderer.hh>
69 #include <ACG/GL/VertexDeclaration.hh>
70 #include <vector>
71 #include <QFont>
72 #include <QFontMetrics>
73 #include <QImage>
74 #include <QPainter>
75 #include <QGLWidget>
76 
77 //== NAMESPACES ===============================================================
78 
79 namespace ACG {
80 namespace SceneGraph {
81 
82 //== CLASS DEFINITION =========================================================
83 
84 
85 
96 class ACGDLLEXPORT TextNode : public BaseNode
97 {
98 public:
99 
100  enum TextMode {
101  SCREEN_ALIGNED,
103  OBJECT_ALIGNED
104  };
105 
112  TextNode( BaseNode* _parent=0,
113  std::string _name="<TextNode>",
114  TextMode _textMode = SCREEN_ALIGNED,
115  bool _alwaysOnTop = false);
116 
118  ~TextNode();
119 
121  ACG_CLASSNAME(TextNode);
122 
124  DrawModes::DrawMode availableDrawModes() const;
125 
127  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
128 
130  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
131 
133  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
134 
136  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
137 
139  void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat);
140 
143  void setRenderingMode(TextMode _textMode);
144 
146  void setAlwaysOnTop(bool _alwaysOnTop);
147 
149  bool alwaysOnTop();
150 
152  TextMode renderingMode();
153 
155  void setText(std::string _text);
156 
158  void setSize(const double _size);
159 
161  void setPixelSize(const unsigned int _size);
162 
164  void setFont(const QFont& _font);
165 
172  float lastScale() {return lastScale_;};
173 
174 protected:
179  static void updateFont();
180 
181 private:
183  static quint32 nearestPowerOfTwo(quint32 num);
184 
189  void updateVBO();
190 
192  void bindVBO();
193 
195  void unbindVBO();
196 
198  void applyScreenAligned(GLState &_state);
199 
204  static std::map< char, std::pair<unsigned int, unsigned int> > createMap();
205 
206 private:
207 
209  double size_;
210 
212  unsigned pixelSize_;
213 
215  std::string text_;
216 
219 
224  GLuint vbo_;
225 
227  std::vector<GLfloat> vertexBuffer_;
228  size_t oldVboSize_;
229 
232 
235 
238 
241 
244 
247 
250 
253 
255  GLint blendSrc_;
256 
258  GLint blendDest_;
259 
262 
264  float lastScale_;
265 
267  static std::map< char, std::pair<unsigned int, unsigned int> > charToIndex_;
268 
270  static QFont qfont_;
271 
273  static GLuint texture_;
274 
276  static int imageWidth_;
277 
279  static int imageHeight_;
280 
282  static qreal maxFontWidth_;
283 
285  static const int numberOfChars_ = 94;
286 
288  static const unsigned int rows_ = 10;
289 
291  static const unsigned int columns_ = 10;
292 
294  static bool initialised_;
295 
297  static QColor color_;
298 };
299 
300 //=============================================================================
301 } // namespace SceneGraph
302 } // namespace ACG
303 //=============================================================================
304 #endif // ACG_TEXTNODE_HH defined
305 //=============================================================================
static QColor color_
color that is used to draw the characters into the texture in updateFont()
Definition: TextNode.hh:297
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
static int imageWidth_
width of the generated texture
Definition: TextNode.hh:276
bool texture2dEnabled_
stores if GL_TEXTURE_2D was enabled on entering TextNode
Definition: TextNode.hh:234
bool alwaysOnTop_
stores if text should be drawn always on top
Definition: TextNode.hh:243
TextMode textMode_
current display mode of text_ (SCREEN_ALIGNED, SCREEN_ALIGNED_STATIC_SIZE or OBJECT_ALIGNED) ...
Definition: TextNode.hh:218
static int imageHeight_
height of the generated texture
Definition: TextNode.hh:279
bool alphaTest_
stores if the alpha test was enabled
Definition: TextNode.hh:246
bool depthEnabled_
stores if GL_DEPTH_TEST was enabled on entering TextNode
Definition: TextNode.hh:240
unsigned pixelSize_
pixelSize of the text for the SCREEN_ALIGNED_STATIC_SIZE mode
Definition: TextNode.hh:212
bool blendEnabled_
stores if GL_BLEND was enabled on entering TextNode
Definition: TextNode.hh:231
static GLuint texture_
handle for the texture into which characters from qfont_ are painted in updateFont() ...
Definition: TextNode.hh:273
Class to define the vertex input layout.
Definition: MeshNode2T.cc:266
float lastScale_
stores the last scaling factor the text computed to SCREEN_ALIGNED_STATIC_SIZE
Definition: TextNode.hh:264
static bool initialised_
this is used to ensure that the texture is only generated once when necessary
Definition: TextNode.hh:294
static QFont qfont_
font that is used to generate the texture in updateFont()
Definition: TextNode.hh:270
static std::map< char, std::pair< unsigned int, unsigned int > > charToIndex_
maps most readable characters to indices for texture coordinate calculation in updateVBO() ...
Definition: TextNode.hh:267
float alphaTestValue_
stores the alpha value used for alpha test
Definition: TextNode.hh:249
GLint blendSrc_
stores the sfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:255
bool cullFaceEnabled_
stores if GL_CULL_FACE was enabled on entering TextNode
Definition: TextNode.hh:237
ACG::VertexDeclaration vertexDecl_
stores the vertex declaration
Definition: TextNode.hh:261
GLenum alphaTestFunc_
stores alpha test comparison function
Definition: TextNode.hh:252
GLint blendDest_
stores the dfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:258
float lastScale()
returns the scaling factor for screen aligned text the text. returns 0, if textmode is not SCREEN_ALI...
Definition: TextNode.hh:172
double size_
scaling factor by which the quads in vbo_ are scaled
Definition: TextNode.hh:209
std::string text_
text to be displayed on quads in vbo_
Definition: TextNode.hh:215
Text will always stay parallel to screen.
Definition: TextNode.hh:102
static qreal maxFontWidth_
max width of qfont
Definition: TextNode.hh:282
std::vector< GLfloat > vertexBuffer_
buffer of vertex coordinates and texture coordinates of the quads
Definition: TextNode.hh:227