Developer Documentation

TextNode.cc
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
47 //=============================================================================
48 //
49 // CLASS TextNode - IMPLEMENTATION
50 //
51 //=============================================================================
52
53
54
55 //== INCLUDES =================================================================
56
57 #include <ACG/GL/acg_glew.hh>
58
59 #include "TextNode.hh"
60 #include "../Utils/ImageConversion.hh"
61
62
63 //== NAMESPACES ===============================================================
64
65 namespace ACG {
66 namespace SceneGraph {
67
68
69 //== IMPLEMENTATION ==========================================================
70
71 // static members
72 #ifdef WIN32
73 // fonts in windows are drawn wider
74 QFont TextNode::qfont_ = QFont("Helvetica", 20);
75 #else
76 QFont TextNode::qfont_ = QFont("Helvetica", 30);
77 #endif
78 GLuint TextNode::texture_ = 0;
79 int TextNode::imageWidth_ = 0;
80 int TextNode::imageHeight_ = 0;
81 qreal TextNode::maxFontWidth_ = 0.0;
82 bool TextNode::initialised_ = false;
83 std::map< char, std::pair<unsigned int, unsigned int> > TextNode::charToIndex_ = TextNode::createMap();
84 QColor TextNode::color_ = QColor(255, 0, 0);
85
86
87 //----------------------------------------------------------------------------
88
89
90 TextNode::
91 TextNode( BaseNode* _parent,
92 const std::string& _name,
93 TextMode _textMode,
94 bool _alwaysOnTop)
95 : BaseNode(_parent, _name),
96 size_(1.0),
97 pixelSize_(12),
98 textMode_(_textMode),
99 vbo_(0),
100 vertexBuffer_(0),
101 oldVboSize_(0),
102 blendEnabled_(false),
103 texture2dEnabled_(false),
104 cullFaceEnabled_(false),
105 depthEnabled_(false),
106 alwaysOnTop_(_alwaysOnTop),
107 alphaTest_(false),
108 alphaTestValue_(0.5f),
109 alphaTestFunc_(GL_GREATER),
110 blendSrc_(0),
111 blendDest_(0),
112 lastScale_(0.f)
113
114 {
115 updateFont();
116 vertexDecl_.addElement(GL_FLOAT, 3, ACG::VERTEX_USAGE_POSITION);
117 vertexDecl_.addElement(GL_FLOAT, 2, ACG::VERTEX_USAGE_TEXCOORD);
118 updateVBO();
119 }
120
121
122
123 //----------------------------------------------------------------------------
124
125
126 TextNode::
127 ~TextNode()
128 {
129 glDeleteBuffers(1, &vbo_);
130 }
131
132
133 //----------------------------------------------------------------------------
134
135
136
137 void
138 TextNode::
139 boundingBox(Vec3d& /*_bbMin*/, Vec3d& /*_bbMax*/)
140 {
141 }
142
143
144 //----------------------------------------------------------------------------
145
146
147 DrawModes::DrawMode
148 TextNode::
149 availableDrawModes() const
150 {
151 return ( DrawModes::POINTS |
152 DrawModes::POINTS_SHADED |
153 DrawModes::POINTS_COLORED );
154 }
155
156
157 //----------------------------------------------------------------------------
158
159
160 void
161 TextNode::
162 setRenderingMode(TextMode _textMode) {
163 textMode_ = _textMode;
164 }
165
166
167
168 //----------------------------------------------------------------------------
169
170 void
171 TextNode::
172 setAlwaysOnTop(bool _alwaysOnTop)
173 {
174 alwaysOnTop_ = _alwaysOnTop;
175 }
176
177
178 //----------------------------------------------------------------------------
179
180 bool
181 TextNode::
182 alwaysOnTop()
183 {
184 return alwaysOnTop_;
185 }
186
187
188 //----------------------------------------------------------------------------
189
190
191 TextNode::TextMode
192 TextNode::
193 renderingMode() {
194 return textMode_;
195 }
196
197
198
199 //----------------------------------------------------------------------------
200
201
202 void
203 TextNode::
204 setText(std::string _text) {
205 text_ = _text; updateVBO();
206 }
207
208
209
210 //----------------------------------------------------------------------------
211
212
213 void
214 TextNode::
215 setSize(const double _size) {
216 size_ = _size; updateVBO();
217 }
218
219
220 //----------------------------------------------------------------------------
221
222
223 std::map< char, std::pair<unsigned int, unsigned int> >
224 TextNode::
225 createMap() {
226 std::map< char, std::pair<unsigned int, unsigned int> > m;
227 unsigned char c = ' ';
228 for (unsigned int i = 0; i < rows_; ++i) {
229 for (unsigned int j = 0; j < columns_; ++j, ++c) {
230 m[c] = std::make_pair(j, i);
231 }
232 }
233
234 return m;
235 }
236
237
238 //----------------------------------------------------------------------------
239
240
241 void
242 TextNode::
243 enter(GLState& _state, const DrawModes::DrawMode& _drawmode) {
244 if(_state.compatibilityProfile())
245 enterCompat(_state,_drawmode);
246 else
247 {
248 if (text_.empty())
249 return;
250
251 // store current gl state
252 cullFaceEnabled_ = glIsEnabled(GL_CULL_FACE);
253 blendEnabled_ = glIsEnabled(GL_BLEND);
254 depthEnabled_ = glIsEnabled(GL_DEPTH_TEST);
255
256 glGetIntegerv(GL_BLEND_SRC, &blendSrc_);
257 glGetIntegerv(GL_BLEND_DST, &blendDest_);
258
259 // set texture and drawing states
260 ACG::GLState::disable(GL_CULL_FACE);
261 ACG::GLState::enable(GL_BLEND);
262 ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
263 if (alwaysOnTop_)
264 ACG::GLState::disable(GL_DEPTH_TEST);
265 }
266 }
267
268
269
270 //----------------------------------------------------------------------------
271
272
273 void
274 TextNode::
275 leave(GLState& _state, const DrawModes::DrawMode& _drawmode) {
276 if(_state.compatibilityProfile())
277 leaveCompat(_state, _drawmode);
278 else
279 {
280 if (text_.empty())
281 return;
282
283 // restore the GLState as it was when entering TextNode
284 if (cullFaceEnabled_)
285 ACG::GLState::enable(GL_CULL_FACE);
286 if (!blendEnabled_)
287 ACG::GLState::disable(GL_BLEND);
288 if (depthEnabled_)
289 ACG::GLState::enable(GL_DEPTH_TEST);
290 else
291 ACG::GLState::disable(GL_DEPTH_TEST);
292
293 ACG::GLState::blendFunc(blendSrc_, blendDest_);
294 }
295 }
296
297
298
299 //----------------------------------------------------------------------------
300
301
302 void
303 TextNode::
304 draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
305 {
306 if (!text_.empty()) {
307 bindVBO();
308
309 // do not rotate the quads in this case
310 if (textMode_ == SCREEN_ALIGNED || textMode_ == SCREEN_ALIGNED_STATIC_SIZE)
311 applyScreenAligned(_state);
312
313
314 _state.push_modelview_matrix();
315 _state.scale(size_);
316 glDrawArrays(GL_TRIANGLES, 0, int(text_.size() * 6) );
317 _state.pop_modelview_matrix();
318
319 if (textMode_ == SCREEN_ALIGNED || textMode_ == SCREEN_ALIGNED_STATIC_SIZE) {
320 _state.pop_modelview_matrix();
321 }
322 unbindVBO();
323 }
324 }
325
326
327 //----------------------------------------------------------------------------
328
329
330 quint32
331 TextNode::nearestPowerOfTwo(quint32 num) {
332 quint32 n = num > 0 ? num - 1 : 0;
333
334 n |= n >> 1;
335 n |= n >> 2;
336 n |= n >> 4;
337 n |= n >> 8;
338 n |= n >> 16;
339 n++;
340
341 return n;
342 }
343
344
345 //----------------------------------------------------------------------------
346
347
348 void
349 TextNode::setFont(const QFont& _font) {
350 qfont_ = QFont(_font);
351 initialised_ = false;
352 updateFont();
353 updateVBO();
354 }
355
356
357 //----------------------------------------------------------------------------
358
359 void
360 TextNode::
361 updateFont() {
362
363 // do not generate a new texture for every TextNode unless necessary
364 if (initialised_)
365 return;
366
367 // since metric.maxWidth() returns 0 for Mac we calculate it here
368 QFontMetricsF metric(qfont_);
369 for (char c = ' '; c < '~'; ++c) {
370 qreal width = metric.width(c) + std::abs(metric.leftBearing(c)) + std::abs(metric.rightBearing(c));
371 if (width > maxFontWidth_)
372 maxFontWidth_ = width;
373 }
374
375 qreal height = metric.height();
376 // ensure that the height of the texture is a power of 2
377 int heightPow2 = nearestPowerOfTwo(height);
378 // ensure that the width of the texture is a power of 2
379 int widthPow2 = nearestPowerOfTwo(maxFontWidth_);
380 imageWidth_ = widthPow2 * columns_;
381 imageHeight_ = heightPow2 * rows_;
382
383 QImage finalImage(imageWidth_, imageHeight_, QImage::Format_ARGB32);
384 finalImage.fill(Qt::transparent);
385 QPainter painter;
386 painter.begin(&finalImage);
387 painter.setRenderHints(QPainter::HighQualityAntialiasing
388 | QPainter::TextAntialiasing);
389 painter.setFont(qfont_);
390 painter.setPen(color_);
391
392 // characters are drawn aligned to the left into the QImage finalImage
393 for (char c = ' '; c < '~'; ++c) {
394 std::pair<unsigned int, unsigned int> coords = charToIndex_[c];
395 painter.drawText(coords.first*widthPow2, imageHeight_ - (coords.second+1)*heightPow2, widthPow2, heightPow2, Qt::AlignLeft | Qt::AlignBottom, QString(c));
396 }
397 painter.end();
398
399 // convert finalImage to an OpenGL friendly format
400 finalImage = ACG::Util::convertToGLFormat(finalImage);
401
402 // generate a new texture from finalImage
403 if (!texture_)
404 glGenTextures(1, &texture_);
405
406 ACG::GLState::bindTexture(GL_TEXTURE_2D, texture_);
407 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
408 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
409 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
410 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
411 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, finalImage.width(), finalImage.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, finalImage.bits());
412 glGenerateMipmap(GL_TEXTURE_2D);
413 ACG::GLState::bindTexture(GL_TEXTURE_2D, 0);
414
415 initialised_ = true;
416 }
417
418
419 //----------------------------------------------------------------------------
420
421
422 void
423 TextNode::
424 updateVBO() {
425 if (text_.size() == 0)
426 return;
427
428 vertexBuffer_.clear();
429
430 // generate a quad for each character next to each other
431 // *--*--*----*-*
432 // | | | | |
433 // | | | | |
434 // *--*--*----*-*
435 QFontMetricsF metric(qfont_);
436 qreal avgWidth = metric.averageCharWidth();
437 const int height = nearestPowerOfTwo(metric.height());
438 float lastCharRight = 0.0f;
439 for (unsigned int i = 0; i < text_.size(); ++i) {
440
441 // left and right vertex coordinates
442 float width = metric.width(text_[i]) / maxFontWidth_;
443 float left, right;
444
445 if (i == 0)
446 left = 0.0f;
447 else
448 left = lastCharRight;
449
450 right = (left + width);
451 lastCharRight = right;
452
453 // left and right texture coordinates
454 qreal leftBearing = std::abs(metric.leftBearing(text_[i]));
455 qreal rightBearing = std::abs(metric.rightBearing(text_[i]));
456 qreal metricWidth = metric.width(text_[i]);
457
458 #ifdef WIN32
459 metricWidth += leftBearing + rightBearing;
460 #endif
461
462 const float widthTx = (float) metricWidth / (float) imageWidth_;
463 const float heightTx = (float) height/ (float) imageHeight_;
464 // get the starting position of the character in the texture
465 // note that the characters are drawn aligned to the bottom left in in the texture
466 const float leftTx = ((float) charToIndex_[text_[i]].first ) / (float) columns_;
467 const float rightTx = leftTx + widthTx;
468 const float bottomTx = charToIndex_[text_[i]].second / (float) rows_;
469 const float topTx = bottomTx + heightTx;
470
471 // bottom left
472 vertexBuffer_.push_back(left);
473 vertexBuffer_.push_back(0.0f);
474 vertexBuffer_.push_back(0.0f);
475
476 // texture coordinates
477 vertexBuffer_.push_back(leftTx);
478 vertexBuffer_.push_back(bottomTx);
479
480 // top left
481 vertexBuffer_.push_back(left);
482 vertexBuffer_.push_back(avgWidth*0.15);
483 vertexBuffer_.push_back(0.0f);
484
485 // texture coordinates
486 vertexBuffer_.push_back(leftTx);
487 vertexBuffer_.push_back(topTx);
488
489 // top right
490 vertexBuffer_.push_back(right);
491 vertexBuffer_.push_back(avgWidth*0.15);
492 vertexBuffer_.push_back(0.0f);
493
494 // texture coordinates
495 vertexBuffer_.push_back(rightTx);
496 vertexBuffer_.push_back(topTx);
497
498 // bottom left
499 vertexBuffer_.push_back(left);
500 vertexBuffer_.push_back(0.0f);
501 vertexBuffer_.push_back(0.0f);
502
503 // texture coordinates
504 vertexBuffer_.push_back(leftTx);
505 vertexBuffer_.push_back(bottomTx);
506
507 // top right
508 vertexBuffer_.push_back(right);
509 vertexBuffer_.push_back(avgWidth*0.15);
510 vertexBuffer_.push_back(0.0f);
511
512 // texture coordinates
513 vertexBuffer_.push_back(rightTx);
514 vertexBuffer_.push_back(topTx);
515
516 // bottom right
517 vertexBuffer_.push_back(right);
518 vertexBuffer_.push_back(0.0f);
519 vertexBuffer_.push_back(0.0f);
520
521 // texture coordinates
522 vertexBuffer_.push_back(rightTx);
523 vertexBuffer_.push_back(bottomTx);
524 }
525
526 if (!vbo_)
527 glGenBuffers(1, &vbo_);
528
529 ACG::GLState::bindBuffer(GL_ARRAY_BUFFER, vbo_);
530
531 if (oldVboSize_ != vertexBuffer_.size())
532 {
533 glBufferData( GL_ARRAY_BUFFER_ARB, vertexBuffer_.size() * sizeof(GLfloat), 0, GL_DYNAMIC_DRAW_ARB );
534 oldVboSize_ = vertexBuffer_.size();
535 }
536
537 // get pointer to VBO memory
538 GLfloat *data = reinterpret_cast<GLfloat*>(glMapBuffer( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB ));
539
540 std::copy(vertexBuffer_.begin(), vertexBuffer_.end(), data);
541
542 glUnmapBuffer(GL_ARRAY_BUFFER_ARB);
543
544 ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
545 }
546
547
548 //----------------------------------------------------------------------------
549
550
551 void
552 TextNode::
553 bindVBO() {
554 ACG::GLState::bindBuffer(GL_ARRAY_BUFFER, vbo_);
555 ACG::GLState::vertexPointer(3, GL_FLOAT, 5*sizeof(GLfloat), 0);
556 ACG::GLState::enableClientState(GL_VERTEX_ARRAY);
557
558 ACG::GLState::activeTexture(GL_TEXTURE0);
559 ACG::GLState::texcoordPointer(2, GL_FLOAT, 5*sizeof(GLfloat), reinterpret_cast<void*>(3*sizeof(GLfloat)));
560 ACG::GLState::enableClientState(GL_TEXTURE_COORD_ARRAY);
561
562 ACG::GLState::bindTexture(GL_TEXTURE_2D, texture_);
563 }
564
565
566 //----------------------------------------------------------------------------
567
568
569 void
570 TextNode::
571 unbindVBO() {
572 ACG::GLState::bindTexture(GL_TEXTURE_2D, 0);
573 ACG::GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
574 ACG::GLState::disableClientState(GL_VERTEX_ARRAY);
575 ACG::GLState::disableClientState(GL_TEXTURE_COORD_ARRAY);
576 }
577
578 //----------------------------------------------------------------------------
579
580 void
581 TextNode::
582 getRenderObjects(ACG::IRenderer* _renderer, ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat)
583 {
584 // init base render object
585 ACG::RenderObject ro;
586
587 ro.initFromState(&_state);
588
589 ro.debugName = std::string("TextNode: ")+name();
590
591 // do not rotate the quads in this case
592 if (textMode_ == SCREEN_ALIGNED || textMode_ == SCREEN_ALIGNED_STATIC_SIZE)
593 applyScreenAligned(_state);
594
595 _state.push_modelview_matrix();
596 _state.scale(size_);
597 ro.modelview = _state.modelview();
598 _state.pop_modelview_matrix();
599
600 if (textMode_ == SCREEN_ALIGNED || textMode_ == SCREEN_ALIGNED_STATIC_SIZE)
601 {
602 _state.pop_modelview_matrix();
603 }
604
605 ro.culling = false;
606 ro.blending = true;
607 ro.alpha = 0.f;
608
609 ro.blendSrc = GL_SRC_ALPHA;
610 ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
611
612 if (alwaysOnTop_)
613 ro.priority = 1;//draw after scene meshes
614
615 // Set the buffers for rendering
616 ro.vertexBuffer = vbo_;
617 ro.vertexDecl = &vertexDecl_;
618
619 // Set Texture
620 RenderObject::Texture texture;
621 texture.id = texture_;
622 texture.type = GL_TEXTURE_2D;
623 texture.shadow = false;
624 ro.addTexture(texture);
625
626 // Set shading
627 ro.shaderDesc.vertexColors = false;
628 ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
629
630 ACG::SceneGraph::Material localMaterial;
631
632 localMaterial.baseColor(ACG::Vec4f(0.0, 0.0, 0.0, 0.0 ));
633 localMaterial.ambientColor(ACG::Vec4f(0.0, 0.0, 0.0, 0.0 ));
634 localMaterial.diffuseColor(ACG::Vec4f(0.0, 0.0, 0.0, 0.0 ));
635 localMaterial.specularColor(ACG::Vec4f(0.0, 0.0, 0.0, 0.0 ));
636 ro.setMaterial(&localMaterial);
637
638 ro.glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(text_.size()) * 6);
639 _renderer->addRenderObject(&ro);
640 }
641
642 //----------------------------------------------------------------------------
643 void TextNode::applyScreenAligned(GLState &_state)
644 {
645 _state.push_modelview_matrix();
646
647 // try to get the scale factor from the parent TransformNode if it exists
648 BaseNode* pParent = parent();
649 double scale = 1.0;
650 while (pParent) {
651 TransformNode* pTrans = dynamic_cast<TransformNode*>(pParent);
652 if (pTrans) {
653 scale = pTrans->scale()(0,0);
654 break;
655 }
656 pParent = pParent->parent();
657 }
658
659 // get the translation
660 Vec3d projected = _state.project(Vec3d(0.0, 0.0, 0.0));
661 _state.reset_modelview();
662 Vec3d unprojected = _state.unproject(projected);
663
664 _state.translate(unprojected);
665
666 if (textMode_ == SCREEN_ALIGNED_STATIC_SIZE)
667 {
668 ACG::Vec3d nullProj = _state.project(Vec3d(0.0,0.0,0.0));
669 ACG::Vec3d nullUnproj = _state.unproject(nullProj);
670 ACG::Vec3d heightUnproj = _state.unproject(nullProj+ACG::Vec3d(0.0,pixelSize_,0.0));
671 scale *= heightUnproj.length();
672 lastScale_ = scale;
673 }
674
675 _state.scale(scale);
676 }
677 //----------------------------------------------------------------------------
678 void TextNode::setPixelSize(const unsigned int _size)
679 {
680 pixelSize_ = _size;
681 }
682
683 //=============================================================================
684 } // namespace SceneGraph
685 } // namespace ACG
686 //=============================================================================
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::RenderObject::addTexture
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
Definition: RenderObject.hh:326
ACG::SceneGraph::ACG::GLState
Definition: MeshNode2T_impl.hh:213
ACG::SceneGraph::TextNode::blendSrc_
GLint blendSrc_
stores the sfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:248
ACG::SceneGraph::TextNode::vbo_
GLuint vbo_
Definition: TextNode.hh:217
ACG::SceneGraph::TextNode::qfont_
static QFont qfont_
font that is used to generate the texture in updateFont()
Definition: TextNode.hh:263
ACG::SceneGraph::BaseNode::parent
BaseNode * parent()
Get the nodes parent node.
Definition: BaseNode.hh:372
ACG::SceneGraph::DrawModes::POINTS_SHADED
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
ACG::SceneGraph::TextNode::blendEnabled_
bool blendEnabled_
stores if GL_BLEND was enabled on entering TextNode
Definition: TextNode.hh:224
ACG::SceneGraph::Material::ambientColor
void ambientColor(const Vec4f &_a)
set the ambient color.
Definition: MaterialNode.hh:175
ACG::SceneGraph::TextNode::~TextNode
~TextNode()
destructor
Definition: TextNode.cc:127
ACG::SceneGraph::TextNode::setText
void setText(std::string _text)
sets the string that will be rendered
Definition: TextNode.cc:204
ACG::SceneGraph::TextNode::imageHeight_
static int imageHeight_
height of the generated texture
Definition: TextNode.hh:272
ACG::SceneGraph::DrawModes::POINTS_COLORED
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
ACG::GLState::push_modelview_matrix
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1010
ACG::SceneGraph::TextNode::nearestPowerOfTwo
static quint32 nearestPowerOfTwo(quint32 num)
returns the nearest greater power of 2 to num
Definition: TextNode.cc:331
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::ACG::GLState::enable
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T_impl.hh:415
ACG::SceneGraph::TextNode::columns_
static const unsigned int columns_
number of columns of characters in the texture
Definition: TextNode.hh:284
ACG::SceneGraph::TextNode::setPixelSize
void setPixelSize(const unsigned int _size)
sets the pixelsize of the text (only available for the SCREEN_ALIGNED_STATIC_SIZE mode and only works...
Definition: TextNode.cc:678
ACG::SceneGraph::ACG::GLState::bindBuffer
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
ACG::GLState::reset_modelview
void reset_modelview()
reset modelview matrix (load identity)
Definition: GLState.cc:370
ACG::SceneGraph::TextNode::createMap
static std::map< char, std::pair< unsigned int, unsigned int > > createMap()
Definition: TextNode.cc:225
ACG::GLState::translate
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:533
ACG::RenderObject::initFromState
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:61
ACG::SceneGraph::ACG::GLState::bindBufferARB
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
Definition: MeshNode2T_impl.hh:573
ACG::RenderObject::modelview
GLMatrixd modelview
Modelview transform.
Definition: RenderObject.hh:138
ACG::SceneGraph::Material::specularColor
void specularColor(const Vec4f &_s)
set the specular color
Definition: MaterialNode.hh:185
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::ACG::GLState::disable
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
ACG::SceneGraph::Material::diffuseColor
void diffuseColor(const Vec4f &_d)
set the diffuse color.
Definition: MaterialNode.hh:180
ACG::RenderObject
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
ACG::SceneGraph::TextNode::imageWidth_
static int imageWidth_
width of the generated texture
Definition: TextNode.hh:269
ACG::SceneGraph::TextNode::vertexDecl_
ACG::VertexDeclaration vertexDecl_
stores the vertex declaration
Definition: TextNode.hh:254
ACG::SceneGraph::ACG::GLState::blendFunc
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
Definition: MeshNode2T_impl.hh:307
ACG::GLState
Definition: GLState.hh:213
ACG::SceneGraph::TextNode::renderingMode
TextMode renderingMode()
returns the rendering mode (SCREEN_ALIGNED or OBJECT_ALIGNED)
Definition: TextNode.cc:193
ACG::SceneGraph::TextNode::text_
std::string text_
text to be displayed on quads in vbo_
Definition: TextNode.hh:208
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::TextNode::depthEnabled_
bool depthEnabled_
stores if GL_DEPTH_TEST was enabled on entering TextNode
Definition: TextNode.hh:233
ACG::SceneGraph::ACG::GLState::vertexPointer
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
ACG::SceneGraph::TextNode::applyScreenAligned
void applyScreenAligned(GLState &_state)
modifies _state so that the modelviewmatrix will be screenaligned. remember to call "_state...
Definition: TextNode.cc:643
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::vertexBuffer_
std::vector< GLfloat > vertexBuffer_
buffer of vertex coordinates and texture coordinates of the quads
Definition: TextNode.hh:220
ACG::GLState::unproject
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Definition: GLState.cc:651
ACG::SceneGraph::Material::baseColor
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
Definition: MaterialNode.hh:165
ACG::SceneGraph::ACG::GLState::activeTexture
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
ACG::SceneGraph::ACG::GLState::disableClientState
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
ACG::GLState::project
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
Definition: GLState.cc:640
ACG::VertexDeclaration::addElement
void addElement(const VertexElement *_pElement)
Definition: VertexDeclaration.cc:115
ACG::SceneGraph::TextNode::rows_
static const unsigned int rows_
number of rows of characters in the texture
Definition: TextNode.hh:281
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
ACG::SceneGraph::TextNode::setRenderingMode
void setRenderingMode(TextMode _textMode)
Definition: TextNode.cc:162
ACG::RenderObject::vertexBuffer
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
Definition: RenderObject.hh:162
ACG::SceneGraph::TextNode::TextMode
TextMode
Definition: TextNode.hh:91
ACG::SceneGraph::ACG::GLState::enableClientState
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
ACG::SceneGraph::ACG::GLState::bindTexture
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
ACG::SceneGraph::ACG::GLState::scale
void scale(double _s)
scale by (_s, _s, _s)
Definition: MeshNode2T_impl.hh:750
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:288
ACG::IRenderer::addRenderObject
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
Definition: IRenderer.cc:104
ACG::SceneGraph::Material
Definition: MaterialNode.hh:79
ACG::SceneGraph::TextNode::setAlwaysOnTop
void setAlwaysOnTop(bool _alwaysOnTop)
draw the text always on top
Definition: TextNode.cc:172
ACG::SceneGraph::TextNode::updateFont
static void updateFont()
Definition: TextNode.cc:361
ACG::SceneGraph::ACG::GLState::modelview
const GLMatrixd & modelview() const
get modelview matrix
Definition: MeshNode2T_impl.hh:791
ACG::SceneGraph::TextNode::SCREEN_ALIGNED_STATIC_SIZE
Text will always stay parallel to screen.
Definition: TextNode.hh:93
ACG::SceneGraph::TextNode::size_
double size_
scaling factor by which the quads in vbo_ are scaled
Definition: TextNode.hh:202
OpenMesh::VectorT::length
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
Definition: Vector11T.hh:418
ACG::SceneGraph::TextNode::enter
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set texture and drawing states
Definition: TextNode.cc:243
ACG::SceneGraph::TextNode::maxFontWidth_
static qreal maxFontWidth_
max width of qfont
Definition: TextNode.hh:275
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::TextNode::getRenderObjects
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
Definition: TextNode.cc:582
ACG::RenderObject::shaderDesc
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Definition: RenderObject.hh:225
ACG::SceneGraph::ACG::SceneGraph::BaseNode::parent
BaseNode * parent()
Get the nodes parent node.
Definition: MeshNode2T_impl.hh:372
ACG::SceneGraph::TextNode::pixelSize_
unsigned pixelSize_
pixelSize of the text for the SCREEN_ALIGNED_STATIC_SIZE mode
Definition: TextNode.hh:205
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:104
ACG::SceneGraph::TextNode::leave
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restore texture and drawing states
Definition: TextNode.cc:275
ACG::SceneGraph::ACG::GLState::push_modelview_matrix
void push_modelview_matrix()
push modelview matrix
ACG::GLState::pop_modelview_matrix
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1026
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::TextNode::availableDrawModes
DrawModes::DrawMode availableDrawModes() const
return available draw modes
Definition: TextNode.cc:149
ACG::GLState::scale
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:750
ACG::SceneGraph::TextNode::draw
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw Text
Definition: TextNode.cc:304
ACG::RenderObject::Texture
Texture to be used.
Definition: RenderObject.hh:313
ACG::SceneGraph::TextNode::bindVBO
void bindVBO()
binds vbo_ and sets the necessary OpenGL states
Definition: TextNode.cc:553
ACG::SceneGraph::TextNode::setFont
void setFont(const QFont &_font)
sets the font to be used for generating a texture with most characters of the chosen font ...
Definition: TextNode.cc:349
ACG::SceneGraph::TransformNode::scale
void scale(double _s)
Add scaling to the current Transformation.
Definition: TransformNode.hh:145
ACG::SceneGraph::TextNode::blendDest_
GLint blendDest_
stores the dfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:251
ACG::IRenderer
Definition: IRenderer.hh:78
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::SceneGraph::TextNode::alwaysOnTop_
bool alwaysOnTop_
stores if text should be drawn always on top
Definition: TextNode.hh:236
ACG::SceneGraph::TextNode::cullFaceEnabled_
bool cullFaceEnabled_
stores if GL_CULL_FACE was enabled on entering TextNode
Definition: TextNode.hh:230
ACG::SceneGraph::TextNode::updateVBO
void updateVBO()
Definition: TextNode.cc:424
ACG::SceneGraph::TextNode::boundingBox
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
Definition: TextNode.cc:139
ACG::SceneGraph::TextNode::TextNode
TextNode(BaseNode *_parent=0, const std::string &_name="<TextNode>", TextMode _textMode=SCREEN_ALIGNED, bool _alwaysOnTop=false)
Definition: TextNode.cc:91
ACG::SceneGraph::ACG::GLState::texcoordPointer
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
ACG::VERTEX_USAGE_POSITION
"inPosition"
Definition: VertexDeclaration.hh:65
ACG::RenderObject::blendDest
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
Definition: RenderObject.hh:247
ACG::SceneGraph::TextNode::setSize
void setSize(const double _size)
sets the size by which the quads displaying the text will be scaled
Definition: TextNode.cc:215
ACG::RenderObject::vertexDecl
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
Definition: RenderObject.hh:208
ACG::SceneGraph::TextNode::alwaysOnTop
bool alwaysOnTop()
returns wheter always on top is setted or not
Definition: TextNode.cc:182
ACG::SceneGraph::DrawModes::POINTS
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
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::TransformNode
Definition: TransformNode.hh:89
ACG::SceneGraph::TextNode::unbindVBO
void unbindVBO()
unbinds vbo_
Definition: TextNode.cc:571
ACG::RenderObject::priority
int priority
Priority to allow sorting of objects.
Definition: RenderObject.hh:116
ACG::VERTEX_USAGE_TEXCOORD
"inTexCoord"
Definition: VertexDeclaration.hh:67
ACG::SceneGraph::ACG::GLState::pop_modelview_matrix
void pop_modelview_matrix()
pop modelview matrix