|
KGLLib
|
Enhanced text renderer. More...
#include <textrenderer.h>
Classes | |
| class | Private |
Public Member Functions | |
| void | begin (GLWidget *widget) |
| void | end () |
| int | draw (const Eigen::Vector3d &pos, const QString &string, const QFont &font=QFont()) |
| int | draw (int x, int y, const QString &string, const QFont &font=QFont()) |
| int | draw (const QRect &rect, const QString &string, int flags, const QFont &font=QFont()) |
| bool | isActive () |
Enhanced text renderer.
Its advantages over the renderText() in Qt 4.2.3 are that it is much faster both at render-time and at startup, consumes less memory, and does outlined text. Its drawback is that its Unicode-safeness is not perfect as superpositions of unicode characters aren't handled.
Every QFont can be used, every character encodings supported by Qt can be used.
To draw plain 2D text on top of the scene, do:
textRenderer.begin(); textRenderer.draw( x1, y1, string1 ); textRenderer.draw( x2, y2, string2 ); textRenderer.draw( x3, y2, string3 ); textRenderer.end();
To draw text as a transparent object inside the scene, do:
textRenderer.begin(); textRenderer.draw( pos1, string1 ); textRenderer.draw( pos2, string2 ); textRenderer.draw( pos3, string3 ); textRenderer.end();
In order to set the text color, please call glColor3f or glColor4f before calling draw(). Of course you can also call qglColor or Color::apply(). You can achieve semitransparent text at no additional cost by choosing a semitransparent color.
Please make sure that no relevant OpenGL state change occurs between begin() and end(), except the state changes performed by the TextRenderer itself. In other words, please avoid calling glSomething() between begin() and end(), except if you are sure that this call won't result in a conflicting state change. Of course calling glColor*() is allowed.
If you experience rendering problems, you can try the following:
| void KGLLib::TextRenderer::begin | ( | GLWidget * | widget | ) |
Call this before drawing any text. This method saves the GL state and changes it to prepare for text rendering.
References KGLLib::TextRenderer::Private::glwidget.
Referenced by KGLLib::GLWidget::paintGL().
| int KGLLib::TextRenderer::draw | ( | int | x, |
| int | y, | ||
| const QString & | string, | ||
| const QFont & | font = QFont() |
||
| ) |
Draw a single line of 2D text at the position (x,y) in window coordinates. Must be called between begin() and end(). (0,0) is the top-left corner.
| x | the x-coordinate |
| y | the y-coordinate |
| string | the QString to render |
References KGLLib::TextRenderer::Private::glwidget.
| int KGLLib::TextRenderer::draw | ( | const QRect & | rect, |
| const QString & | string, | ||
| int | flags, | ||
| const QFont & | font = QFont() |
||
| ) |
Draws 2D text within the given rectangle. The text will be positioned and layed out according to flags which is a bitwise OR of the following flags:
string argument are preserved. Must be called between begin() and end(). References draw().
| int KGLLib::TextRenderer::draw | ( | const Eigen::Vector3d & | pos, |
| const QString & | string, | ||
| const QFont & | font = QFont() |
||
| ) |
Draw text inside the 3D scene. Must be called between begin() and end(). The text is centered (both horizontally and vertically) around the specified position.
| pos | the position of the text in the scene's coordinate system |
| string | the QString to render |
References KGLLib::TextRenderer::Private::glwidget.
Referenced by draw(), and KGLLib::GLWidget::paintGL().
| void KGLLib::TextRenderer::end | ( | ) |
Call this after drawing text. This method restores the GL state to what it was when begin() was called.
References KGLLib::TextRenderer::Private::glwidget.
Referenced by KGLLib::GLWidget::paintGL().
1.7.4