Viewer
A plugin-based viewer for learning Computer Graphics and OpenGL
BasicPlugin Class Reference

#include <basicplugin.h>

List of all members.

Public Member Functions

 BasicPlugin ()
virtual ~BasicPlugin ()
virtual void onPluginLoad ()
virtual void onObjectAdd ()
virtual void preFrame ()
virtual void postFrame ()
virtual void keyPressEvent (QKeyEvent *)
virtual void keyReleaseEvent (QKeyEvent *)
virtual void mouseMoveEvent (QMouseEvent *)
virtual void mousePressEvent (QMouseEvent *)
virtual void mouseReleaseEvent (QMouseEvent *)
virtual void wheelEvent (QWheelEvent *)
virtual bool paintGL ()
virtual bool drawScene ()
Scenescene ()
Cameracamera ()
BasicPlugindrawPlugin ()
GLWidgetglwidget ()
void setWidget (GLWidget *glwidget)
void setDrawPlugin (BasicPlugin *drawPlugin)

Detailed Description

/class BasicPlugin /brief The BasicPlugin class is the base class for all plugins.

All plugins you will have to implement must derive from this class.

All methods have a default implementation (do nothing), so each plugin can override only those methods needed to provide the intended functionality.

An Effect Plugin might override preFrame() and postFrame() methods to modify the OpenGL state before and after the scene is rendered (for example, to load shaders or to enable alphablending) and to draw additional content (for example, the frame rate).

A Draw Plugin might override the drawScene() method, which is in charge of drawing all the objects forming the scene by issuing OpenGL rendering commands.

An Action Plugin might override user input methods such as keyPressEvent(), mouseMoveEvent() to allow for some interaction: camera control, object selection...

A Render Plugin should override paintGL(). The main purpose is to implement techniques requiring multiple rendering passes, for example, shadow mapping.


Constructor & Destructor Documentation

Constructs a basic plugin.

virtual BasicPlugin::~BasicPlugin ( ) [inline, virtual]

Destroys the plugin.


Member Function Documentation

Camera* BasicPlugin::camera ( ) [inline]

Returns a pointer to the Camera.

Returns a pointer to a plugin implementing drawScene(). If no such a plugin has been loaded, returns null.

virtual bool BasicPlugin::drawScene ( ) [inline, virtual]

This method is intended to be involked by any plugin willing to draw the scene. For example, a plugin overriding paintGL(). If you override drawScene(), you must always return true so that the application knows the scene has been drawn successfully. The GLWidget class keeps track of the plugin overriding this method. Using legacy code, a minimal implementation could be:

        bool MyPluginExample::drawScene()
        {
            for (unsigned int i=0; i<scene()->objects().size(); ++i) 
            {
                const Object& obj = scene()->objects()[i];
                for (unsigned int c=0; c<obj.faces().size(); c++)
                {
                    const Face& face = obj.faces()[c];
                    glBegin(GL_POLYGON);
                    glNormal3f(face.normal().x(), face.normal().y(), face.normal().z());
                    for(int v=0; v<face.numVertices(); v++)
                    { 
                        const Point& p = obj.vertices()[face.vertexIndex(v)].coord();
                        glVertex3f(p.x(), p.y(), p.z());
                    }
                    glEnd();
                }
            }
            return true; 
        }

Returns a pointer to the GLWidget.

virtual void BasicPlugin::keyPressEvent ( QKeyEvent *  ) [inline, virtual]

See the QGLWidget reference.

virtual void BasicPlugin::keyReleaseEvent ( QKeyEvent *  ) [inline, virtual]

See the QGLWidget reference.

virtual void BasicPlugin::mouseMoveEvent ( QMouseEvent *  ) [inline, virtual]

See the QGLWidget reference.

virtual void BasicPlugin::mousePressEvent ( QMouseEvent *  ) [inline, virtual]

See the QGLWidget reference.

virtual void BasicPlugin::mouseReleaseEvent ( QMouseEvent *  ) [inline, virtual]

See the QGLWidget reference.

virtual void BasicPlugin::onObjectAdd ( ) [inline, virtual]

This method is called everytime a new object is added to the scene. This allows your plugin to execute some code everytime the scene has changed.

virtual void BasicPlugin::onPluginLoad ( ) [inline, virtual]

This method is called right after the plugin has been loaded by the application. A valid OpenGL context allways exists when this method is invoked. This method usually has code for initializing the plugin: compile shaders, load textures, setup timers... The scene might contain some objects but it could also be empty.

virtual bool BasicPlugin::paintGL ( void  ) [inline, virtual]

This method is invoked by GLWidget::paintGL(). It is responsible of painting everything whenever the widget needs to be painted. A minimal implementation should call glClear and then invoke the drawScene() method of the current Draw Plugin :

        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        if (drawPlugin()) drawPlugin()->drawScene();
        return true;

If you override paintGL(), you must always return true so that the application knows it has been repainted successfully.

virtual void BasicPlugin::postFrame ( ) [inline, virtual]

This method is called in GLWidget::paintGL() after drawing the scene. This allows your plugin to execute some code to be executed right after the scene is rendered. A typical use would be to unbind a shader, or drawing additional primitives (for example, the frame rate or a wireframe box around the selected object).

virtual void BasicPlugin::preFrame ( ) [inline, virtual]

This method is called in GLWidget::paintGL() before drawing the scene. This allows your plugin to execute some code to be executed right before the scene is rendered. A typical use would be to bind a shader affecting the whole scene. Notice that glClear() is likely to be called after all preFrame() methods have been executed, so you should not draw anything here. For drawing additional primitives override the postFrame() method instead.

Scene* BasicPlugin::scene ( ) [inline]

Returns a pointer to the Scene.

virtual void BasicPlugin::wheelEvent ( QWheelEvent *  ) [inline, virtual]

See the QGLWidget reference.


The documentation for this class was generated from the following file:
 All Classes Functions