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