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;
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 
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();
118  updateVBO();
119 }
120 
121 
122 
123 //----------------------------------------------------------------------------
124 
125 
128 {
129  glDeleteBuffers(1, &vbo_);
130 }
131 
132 
133 //----------------------------------------------------------------------------
134 
135 
136 
137 void
139 boundingBox(Vec3d& /*_bbMin*/, Vec3d& /*_bbMax*/)
140 {
141 }
142 
143 
144 //----------------------------------------------------------------------------
145 
146 
150 {
151  return ( DrawModes::POINTS |
154 }
155 
156 
157 //----------------------------------------------------------------------------
158 
159 
160 void
163  textMode_ = _textMode;
164 }
165 
166 
167 
168 //----------------------------------------------------------------------------
169 
170 void
172 setAlwaysOnTop(bool _alwaysOnTop)
173 {
174  alwaysOnTop_ = _alwaysOnTop;
175 }
176 
177 
178 //----------------------------------------------------------------------------
179 
180 bool
183 {
184  return alwaysOnTop_;
185 }
186 
187 
188 //----------------------------------------------------------------------------
189 
190 
194  return textMode_;
195 }
196 
197 
198 
199 //----------------------------------------------------------------------------
200 
201 
202 void
204 setText(std::string _text) {
205  text_ = _text; updateVBO();
206 }
207 
208 
209 
210 //----------------------------------------------------------------------------
211 
212 
213 void
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> >
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
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
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 
294  }
295 }
296 
297 
298 
299 //----------------------------------------------------------------------------
300 
301 
302 void
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
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
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
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
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
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
583 {
584  // init base render object
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 //----------------------------------------------------------------------------
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 
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 //=============================================================================
Namespace providing different geometric functions concerning angles.
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
GLint blendSrc_
stores the sfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:248
static QFont qfont_
font that is used to generate the texture in updateFont()
Definition: TextNode.hh:263
BaseNode * parent()
Get the nodes parent node.
Definition: BaseNode.hh:372
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
bool blendEnabled_
stores if GL_BLEND was enabled on entering TextNode
Definition: TextNode.hh:224
void ambientColor(const Vec4f &_a)
set the ambient color.
~TextNode()
destructor
Definition: TextNode.cc:127
void setText(std::string _text)
sets the string that will be rendered
Definition: TextNode.cc:204
static int imageHeight_
height of the generated texture
Definition: TextNode.hh:272
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1010
static quint32 nearestPowerOfTwo(quint32 num)
returns the nearest greater power of 2 to num
Definition: TextNode.cc:331
float lastScale_
stores the last scaling factor the text computed to SCREEN_ALIGNED_STATIC_SIZE
Definition: TextNode.hh:257
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
std::string name() const
Returns: name of node (needs not be unique)
static const unsigned int columns_
number of columns of characters in the texture
Definition: TextNode.hh:284
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
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
void reset_modelview()
reset modelview matrix (load identity)
Definition: GLState.cc:370
static std::map< char, std::pair< unsigned int, unsigned int > > createMap()
Definition: TextNode.cc:225
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:533
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:61
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
GLMatrixd modelview
Modelview transform.
void specularColor(const Vec4f &_s)
set the specular color
TextMode textMode_
current display mode of text_ (SCREEN_ALIGNED, SCREEN_ALIGNED_STATIC_SIZE or OBJECT_ALIGNED) ...
Definition: TextNode.hh:211
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
void diffuseColor(const Vec4f &_d)
set the diffuse color.
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
static int imageWidth_
width of the generated texture
Definition: TextNode.hh:269
ACG::VertexDeclaration vertexDecl_
stores the vertex declaration
Definition: TextNode.hh:254
static void blendFunc(GLenum _sfactor, GLenum _dfactor)
replaces glBlendFunc, supports locking
TextMode renderingMode()
returns the rendering mode (SCREEN_ALIGNED or OBJECT_ALIGNED)
Definition: TextNode.cc:193
std::string text_
text to be displayed on quads in vbo_
Definition: TextNode.hh:208
static bool initialised_
this is used to ensure that the texture is only generated once when necessary
Definition: TextNode.hh:287
bool depthEnabled_
stores if GL_DEPTH_TEST was enabled on entering TextNode
Definition: TextNode.hh:233
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
void applyScreenAligned(GLState &_state)
modifies _state so that the modelviewmatrix will be screenaligned. remember to call "_state...
Definition: TextNode.cc:643
static QColor color_
color that is used to draw the characters into the texture in updateFont()
Definition: TextNode.hh:290
std::vector< GLfloat > vertexBuffer_
buffer of vertex coordinates and texture coordinates of the quads
Definition: TextNode.hh:220
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Definition: GLState.cc:651
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
static void activeTexture(GLenum _texunit)
replaces glActiveTexture, no locking support
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
Definition: GLState.cc:640
void addElement(const VertexElement *_pElement)
static const unsigned int rows_
number of rows of characters in the texture
Definition: TextNode.hh:281
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
void setRenderingMode(TextMode _textMode)
Definition: TextNode.cc:162
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
void scale(double _s)
scale by (_s, _s, _s)
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
Definition: IRenderer.cc:104
void setAlwaysOnTop(bool _alwaysOnTop)
draw the text always on top
Definition: TextNode.cc:172
static void updateFont()
Definition: TextNode.cc:361
const GLMatrixd & modelview() const
get modelview matrix
Text will always stay parallel to screen.
Definition: TextNode.hh:93
double size_
scaling factor by which the quads in vbo_ are scaled
Definition: TextNode.hh:202
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
Definition: Vector11T.hh:418
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set texture and drawing states
Definition: TextNode.cc:243
static qreal maxFontWidth_
max width of qfont
Definition: TextNode.hh:275
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
ShaderGenDesc shaderDesc
Drawmode and other shader params.
BaseNode * parent()
Get the nodes parent node.
unsigned pixelSize_
pixelSize of the text for the SCREEN_ALIGNED_STATIC_SIZE mode
Definition: TextNode.hh:205
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restore texture and drawing states
Definition: TextNode.cc:275
void push_modelview_matrix()
push modelview matrix
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1026
DrawModes::DrawMode availableDrawModes() const
return available draw modes
Definition: TextNode.cc:149
void scale(double _s)
scale by (_s, _s, _s)
Definition: GLState.hh:750
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw Text
Definition: TextNode.cc:304
Texture to be used.
void bindVBO()
binds vbo_ and sets the necessary OpenGL states
Definition: TextNode.cc:553
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
void scale(double _s)
Add scaling to the current Transformation.
GLint blendDest_
stores the dfactor parameter of glBlendFunc on entering TextNode
Definition: TextNode.hh:251
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
bool alwaysOnTop_
stores if text should be drawn always on top
Definition: TextNode.hh:236
bool cullFaceEnabled_
stores if GL_CULL_FACE was enabled on entering TextNode
Definition: TextNode.hh:230
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
Definition: TextNode.cc:139
TextNode(BaseNode *_parent=0, const std::string &_name="<TextNode>", TextMode _textMode=SCREEN_ALIGNED, bool _alwaysOnTop=false)
Definition: TextNode.cc:91
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
GLenum blendDest
glBlendFunc: GL_SRC_ALPHA, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA ...
void setSize(const double _size)
sets the size by which the quads displaying the text will be scaled
Definition: TextNode.cc:215
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
bool alwaysOnTop()
returns wheter always on top is setted or not
Definition: TextNode.cc:182
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
static GLuint texture_
handle for the texture into which characters from qfont_ are painted in updateFont() ...
Definition: TextNode.hh:266
void unbindVBO()
unbinds vbo_
Definition: TextNode.cc:571
int priority
Priority to allow sorting of objects.
void pop_modelview_matrix()
pop modelview matrix