• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KGLLib

KGLLib::TextRenderer

KGLLib::TextRenderer Class Reference

#include <textrenderer.h>

List of all members.


Detailed Description

Author:
Benoit Jacob

Enhanced text renderer.

This class renders text inside a QGLWidget. It replaces and extends the functionality of QGLWidget::renderText().

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:

  • disable some OpenGL state bits. For instance, TextRenderer automatically disables fog and lighting during rendering, because it doesn't work correctly with them enabled. There probably are other OpenGL state bits that have to be disabled, so if your program enables some of them, you might have to disable them before rendering text.
  • if you experience poor font quality, meake sure that your GLWidget is using an antialiased font.

Definition at line 96 of file textrenderer.h.


Public Member Functions

void begin (GLWidget *widget)
int draw (const QRect &rect, const QString &string, int flags, const QFont &font=QFont())
int draw (int x, int y, const QString &string, const QFont &font=QFont())
int draw (const Eigen::Vector3d &pos, const QString &string, const QFont &font=QFont())
void end ()
bool isActive ()
 TextRenderer ()
 ~TextRenderer ()

Constructor & Destructor Documentation

KGLLib::TextRenderer::TextRenderer (  ) 

Definition at line 423 of file textrenderer.cpp.

KGLLib::TextRenderer::~TextRenderer (  ) 

Definition at line 429 of file textrenderer.cpp.


Member Function Documentation

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.

Definition at line 450 of file textrenderer.cpp.

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:

  • Qt::AlignLeft
  • Qt::AlignRight
  • Qt::AlignHCenter
  • Qt::AlignTop
  • Qt::AlignBottom
  • Qt::AlignVCenter
  • Qt::AlignCenter
  • Qt::TextSingleLine
  • Qt::TextWordWrap Any newlines contained in the string argument are preserved. Must be called between begin() and end().
    Returns:
    total height of the rendered text (i.e. font's line spacing times the number of drawn lines)

Definition at line 525 of file textrenderer.cpp.

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.

Parameters:
x the x-coordinate
y the y-coordinate
string the QString to render
Returns:
the line spacing in pixels of the text just rendered (0 for an empty string).

Definition at line 504 of file textrenderer.cpp.

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.

Parameters:
pos the position of the text in the scene's coordinate system
string the QString to render
Returns:
the line spacing in pixels of the text just rendered (0 for an empty string).

Definition at line 592 of file textrenderer.cpp.

void KGLLib::TextRenderer::end (  ) 

Call this after drawing text.

This method restores the GL state to what it was when begin() was called.

Definition at line 491 of file textrenderer.cpp.

bool KGLLib::TextRenderer::isActive (  ) 

Definition at line 620 of file textrenderer.cpp.


The documentation for this class was generated from the following files:
  • textrenderer.h
  • textrenderer.cpp

KGLLib

Skip menu "KGLLib"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KGLLib
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal