Developer Documentation

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 //=============================================================================
45 //
46 // CLASS PointNode
47 //
48 //=============================================================================
49
50 #ifndef ACG_TEXTNODE_HH
51 #define ACG_TEXTNODE_HH
52
53
54 //== INCLUDES =================================================================
55
56 #include "BaseNode.hh"
57 #include "TransformNode.hh"
58 #include "DrawModes.hh"
59 #include <ACG/GL/IRenderer.hh>
60 #include <ACG/GL/VertexDeclaration.hh>
61 #include <vector>
62 #include <QFont>
63 #include <QFontMetrics>
64 #include <QImage>
65 #include <QPainter>
66 #include <QGLWidget>
67
68 //== NAMESPACES ===============================================================
69
70 namespace ACG {
71 namespace SceneGraph {
72
73 //== CLASS DEFINITION =========================================================
74
75
76
87 class ACGDLLEXPORT TextNode : public BaseNode
88 {
89 public:
90
91 enum TextMode {
92 SCREEN_ALIGNED,
93 SCREEN_ALIGNED_STATIC_SIZE,
94 OBJECT_ALIGNED
95 };
96
103 TextNode( BaseNode* _parent=0,
104 const std::string& _name="<TextNode>",
105 TextMode _textMode = SCREEN_ALIGNED,
106 bool _alwaysOnTop = false);
107
109 ~TextNode();
110
112 ACG_CLASSNAME(TextNode);
113
115 DrawModes::DrawMode availableDrawModes() const override;
116
118 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
119
121 void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
122
124 void enter(GLState& _state, const DrawModes::DrawMode& _drawmode) override;
125 void enterCompat(GLState& _state, const DrawModes::DrawMode& _drawmode);
126
128 void leave(GLState& _state, const DrawModes::DrawMode& _drawmode) override;
129 void leaveCompat(GLState& _state, const DrawModes::DrawMode& _drawmode);
130
132 void getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) override;
133
136 void setRenderingMode(TextMode _textMode);
137
139 void setAlwaysOnTop(bool _alwaysOnTop);
140
142 bool alwaysOnTop();
143
145 TextMode renderingMode();
146
148 void setText(std::string _text);
149
151 void setSize(const double _size);
152
154 void setPixelSize(const unsigned int _size);
155
157 void setFont(const QFont& _font);
158
165 float lastScale() {return lastScale_;};
166
167 protected:
172 static void updateFont();
173
174 private:
176 static quint32 nearestPowerOfTwo(quint32 num);
177
182 void updateVBO();
183
185 void bindVBO();
186
188 void unbindVBO();
189
191 void applyScreenAligned(GLState &_state);
192
197 static std::map< char, std::pair<unsigned int, unsigned int> > createMap();
198
199 private:
200
202 double size_;
203
205 unsigned pixelSize_;
206
208 std::string text_;
209
211 TextMode textMode_;
212
217 GLuint vbo_;
218
220 std::vector<GLfloat> vertexBuffer_;
221 size_t oldVboSize_;
222
224 bool blendEnabled_;
225
227 bool texture2dEnabled_;
228
230 bool cullFaceEnabled_;
231
233 bool depthEnabled_;
234
236 bool alwaysOnTop_;
237
239 bool alphaTest_;
240
242 float alphaTestValue_;
243
245 GLenum alphaTestFunc_;
246
248 GLint blendSrc_;
249
251 GLint blendDest_;
252
254 ACG::VertexDeclaration vertexDecl_;
255
257 float lastScale_;
258
260 static std::map< char, std::pair<unsigned int, unsigned int> > charToIndex_;
261
263 static QFont qfont_;
264
266 static GLuint texture_;
267
269 static int imageWidth_;
270
272 static int imageHeight_;
273
275 static qreal maxFontWidth_;
276
278 static const int numberOfChars_ = 94;
279
281 static const unsigned int rows_ = 10;
282
284 static const unsigned int columns_ = 10;
285
287 static bool initialised_;
288
290 static QColor color_;
291 };
292
293 //=============================================================================
294 } // namespace SceneGraph
295 } // namespace ACG
296 //=============================================================================
297 #endif // ACG_TEXTNODE_HH defined
298 //=============================================================================
ACG::SceneGraph::TextNode::depthEnabled_
bool depthEnabled_
stores if GL_DEPTH_TEST was enabled on entering TextNode
Definition: TextNode.hh:233
ACG::SceneGraph::TextNode::qfont_
static QFont qfont_
font that is used to generate the texture in updateFont()
Definition: TextNode.hh:263
ACG::SceneGraph::TextNode::pixelSize_
unsigned pixelSize_
pixelSize of the text for the SCREEN_ALIGNED_STATIC_SIZE mode
Definition: TextNode.hh:205
ACG::SceneGraph::TextNode::texture_
static GLuint texture_
handle for the texture into which characters from qfont_ are painted in updateFont() ...
Definition: TextNode.hh:266
ACG::SceneGraph::TextNode::blendDest_
GLint blendDest_
stores the dfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:251
ACG::SceneGraph::TextNode::charToIndex_
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:260
ACG::GLState
Definition: GLState.hh:213
ACG::SceneGraph::TextNode::maxFontWidth_
static qreal maxFontWidth_
max width of qfont
Definition: TextNode.hh:275
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::SceneGraph::TextNode::initialised_
static bool initialised_
this is used to ensure that the texture is only generated once when necessary
Definition: TextNode.hh:287
ACG::SceneGraph::ACG::GLState
Definition: MeshNode2T_impl.hh:213
ACG::VertexDeclaration
Class to define the vertex input layout.
Definition: VertexDeclaration.hh:268
ACG::SceneGraph::TextNode::alphaTest_
bool alphaTest_
stores if the alpha test was enabled
Definition: TextNode.hh:239
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::TextNode::texture2dEnabled_
bool texture2dEnabled_
stores if GL_TEXTURE_2D was enabled on entering TextNode
Definition: TextNode.hh:227
ACG::SceneGraph::TextNode::SCREEN_ALIGNED_STATIC_SIZE
Text will always stay parallel to screen.
Definition: TextNode.hh:93
ACG::SceneGraph::TextNode::TextMode
TextMode
Definition: TextNode.hh:91
ACG::IRenderer
Definition: IRenderer.hh:78
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::TextNode::size_
double size_
scaling factor by which the quads in vbo_ are scaled
Definition: TextNode.hh:202
ACG::SceneGraph::TextNode::textMode_
TextMode textMode_
current display mode of text_ (SCREEN_ALIGNED, SCREEN_ALIGNED_STATIC_SIZE or OBJECT_ALIGNED) ...
Definition: TextNode.hh:211
ACG::SceneGraph::TextNode::blendEnabled_
bool blendEnabled_
stores if GL_BLEND was enabled on entering TextNode
Definition: TextNode.hh:224
ACG::SceneGraph::TextNode::blendSrc_
GLint blendSrc_
stores the sfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:248
ACG::SceneGraph::TextNode::lastScale_
float lastScale_
stores the last scaling factor the text computed to SCREEN_ALIGNED_STATIC_SIZE
Definition: TextNode.hh:257
ACG::SceneGraph::TextNode::cullFaceEnabled_
bool cullFaceEnabled_
stores if GL_CULL_FACE was enabled on entering TextNode
Definition: TextNode.hh:230
ACG::SceneGraph::TextNode::alphaTestFunc_
GLenum alphaTestFunc_
stores alpha test comparison function
Definition: TextNode.hh:245
ACG::SceneGraph::TextNode::alphaTestValue_
float alphaTestValue_
stores the alpha value used for alpha test
Definition: TextNode.hh:242
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
ACG::SceneGraph::TextNode::lastScale
float lastScale()
returns the scaling factor for screen aligned text the text. returns 0, if textmode is not SCREEN_ALI...
Definition: TextNode.hh:165
ACG::SceneGraph::TextNode::imageWidth_
static int imageWidth_
width of the generated texture
Definition: TextNode.hh:269
ACG::SceneGraph::TextNode::alwaysOnTop_
bool alwaysOnTop_
stores if text should be drawn always on top
Definition: TextNode.hh:236
ACG::SceneGraph::TextNode::vertexBuffer_
std::vector< GLfloat > vertexBuffer_
buffer of vertex coordinates and texture coordinates of the quads
Definition: TextNode.hh:220
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
ACG::SceneGraph::TextNode
Definition: TextNode.hh:87
ACG::SceneGraph::TextNode::vertexDecl_
ACG::VertexDeclaration vertexDecl_
stores the vertex declaration
Definition: TextNode.hh:254
ACG::SceneGraph::TextNode::imageHeight_
static int imageHeight_
height of the generated texture
Definition: TextNode.hh:272
ACG::SceneGraph::Material
Definition: MaterialNode.hh:79
ACG::SceneGraph::TextNode::text_
std::string text_
text to be displayed on quads in vbo_
Definition: TextNode.hh:208
ACG::SceneGraph::TextNode::color_
static QColor color_
color that is used to draw the characters into the texture in updateFont()
Definition: TextNode.hh:290
ACG::SceneGraph::TextNode::vbo_
GLuint vbo_
Definition: TextNode.hh:217