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