KGLLib
Public Slots | Public Member Functions | Protected Member Functions
KGLLib::GLWidget Class Reference

Easy to use GL widget, based on QGLWidget. More...

#include <glwidget.h>

Inheritance diagram for KGLLib::GLWidget:
KGLLib::HdrGLWidget

List of all members.

Public Slots

void toggleShowFps ()
void toggleWireframeMode ()

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW GLWidget (QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0)
 GLWidget (QGLContext *context, QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0)
 GLWidget (const QGLFormat &format, QWidget *parent=0, const QGLWidget *shareWidget=0, Qt::WindowFlags f=0)
KGLLib::Cameracamera () const
KGLLib::FPSCounterfpsCounter () const
KGLLib::TextRenderertextRenderer () const
bool glInitialized () const

Protected Member Functions

virtual void initializeGL ()
virtual void initializeGL (Renderer *r)
virtual void resizeGL (int width, int height)
virtual void paintGL ()
virtual void render ()
void setClearColor (const Eigen::Vector4f &c)
void setAutomaticClear (bool clear)
Eigen::Vector4f clearColor () const
bool automaticClear () const
void setErrorText (const QString &text)
QString errorText () const
bool shortcutsEnabled () const
virtual void setShortcutsEnabled (bool enabled)

Detailed Description

Easy to use GL widget, based on QGLWidget.

GLWidget is a QGLWidget subclass which is integrated with the rest of the KGLLib and implements some of the common functionality used by many GL applications.

If you are already using QGLWidget then switching to GLWidget is very easy. All you need to do is changing class name to GLWidget and doing your OpenGL rendering in render() method instead of paintGL().


Member Function Documentation

KGLLib::Camera* KGLLib::GLWidget::camera ( ) const [inline]
Returns:
pointer to the Camera object. This is available after initializeGL() has been called.

Referenced by initializeGL(), paintGL(), and resizeGL().

QString KGLLib::GLWidget::errorText ( ) const [inline, protected]
Returns:
current error text
See also:
setErrorText()
KGLLib::FPSCounter* KGLLib::GLWidget::fpsCounter ( ) const [inline]
Returns:
pointer to the FPSCounter object. This is available after initializeGL() has been called.

Referenced by paintGL().

bool KGLLib::GLWidget::glInitialized ( ) const [inline]
Returns:
whether initializeGL() has been called
void KGLLib::GLWidget::initializeGL ( Renderer r) [protected, virtual]
void KGLLib::GLWidget::initializeGL ( ) [protected, virtual]

Initializes OpenGL. Base implementation:

  • calls KGLLib::init() to initialize KGLLib
  • creates camera and fpsCounter objects
  • sets OpenGL clear color to clearColor
  • initializes camera to look from (0, 0, 5) at (0, 0, 0) with depth range [1, 100]
  • enables depth testing (if depth buffer is used)
  • sets OpenGL shade model to GL_SMOOTH
  • sets primary color to white

Reimplemented in KGLLib::HdrGLWidget.

void KGLLib::GLWidget::paintGL ( ) [protected, virtual]

Called when the widget needs to be painted. Base implementation:

  • updates fpsCounter
  • clears color and possibly depth buffer is automaticClear is true
  • applies camera

Note that applications are preferred to use render() instead. If you do your OpenGL rendering in this method then some functionality provided by this class will not work (e.g. fps display).

References KGLLib::Camera::applyView(), KGLLib::TextRenderer::begin(), camera(), KGLLib::TextRenderer::draw(), KGLLib::TextRenderer::end(), fpsCounter(), KGLLib::FPSCounter::nextFrame(), render(), setClearColor(), and textRenderer().

void KGLLib::GLWidget::render ( ) [protected, virtual]

Called from paintGL() when the widget needs to be painted. This is the method that you should reimplement to do your rendering. Base implementation does nothing, so you needn't call it from your implementation.

Reimplemented in KGLLib::HdrGLWidget.

Referenced by paintGL().

void KGLLib::GLWidget::resizeGL ( int  width,
int  height 
) [protected, virtual]

Called when the widget is resized. Base implementation:

  • sets up a new viewport, covering the entire widget
  • updates camera's aspect and applies the camera

Reimplemented in KGLLib::HdrGLWidget.

References KGLLib::Camera::applyPerspective(), KGLLib::Camera::applyViewport(), camera(), KGLLib::Camera::setAspect(), and KGLLib::Camera::setViewport().

void KGLLib::GLWidget::setAutomaticClear ( bool  clear) [protected]

Specifies whether OpenGL buffers should be automatically cleared in the beginning of paintGL.

void KGLLib::GLWidget::setClearColor ( const Eigen::Vector4f &  c) [protected]

Set's OpenGL's clear color to c. Default is black. TODO: maybe rename to setBackgroundColor?

Referenced by initializeGL(), and paintGL().

void KGLLib::GLWidget::setErrorText ( const QString &  text) [protected]

Sets error text for this widget.

If the error text is set, then it is displayed centered in the widget and render() method isn't called.

It is handy to use when something goes wrong in your application's initialization phase (e.g. data files cannot be found) and you want to abort but let the user know what happened.

void KGLLib::GLWidget::setShortcutsEnabled ( bool  enabled) [protected, virtual]

GLWidget provides some keyboard shortcuts to ease application development. For example Meta+F toggles FPS (frames per second) display and Meta+W toggles wireframe rendering.

If you don't want those shortcuts to be available, you can disable them using this method.

Shortcuts are enabled by default.

bool KGLLib::GLWidget::shortcutsEnabled ( ) const [inline, protected]
Returns:
whether KGLLib keyboard shortcuts are enabled.
See also:
setShortcutsEnabled()
KGLLib::TextRenderer * KGLLib::GLWidget::textRenderer ( ) const
Returns:
TextRenderer object

Referenced by paintGL().


The documentation for this class was generated from the following files: