OpenGLCanvas.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  OpenGLCanvas
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Provides an OpenGL rendering view
00009    <!-------------------------------------------------------------------->**/
00010 
00011 #ifndef OPENGL_CANVAS_H_
00012 #define OPENGL_CANVAS_H_
00013 
00014 #include <QGLWidget>
00015 #include <Qt/QtOpenGL>
00016 #include <GL/glut.h>
00017 
00018 #include "Canvas.h"
00019 
00020 // setDrawMode constants
00021 enum DRAW_MODE {
00022    MODE_WIREFRAME = 0, 
00023    MODE_SOLID = 1
00024 };
00025 
00026 class OpenGLCanvas : public QGLWidget, public Canvas {
00027    
00028    Q_OBJECT
00029    
00030    public:
00031       ///@name Constructors
00032       //@{-----------------------------------------------------------------
00033       
00034       /**
00035        * @param defaultInteractionListeners if true will enable the basic, 
00036        *        built-in, Maya-style user interactions via CTRL + mouse
00037        */
00038       OpenGLCanvas(bool defaultInteractionListeners, 
00039                    Gui *gui = NULL, 
00040                    unsigned width  = DEFAULT_WIDTH, 
00041                    unsigned height = DEFAULT_HEIGHT);
00042       
00043       /**
00044        * @brief
00045        *    Constructs an OpenGLCanvas with default interaction listeners 
00046        * (Maya-style camera interactions)
00047        */
00048       OpenGLCanvas(Gui *gui = NULL, 
00049                    unsigned width  = DEFAULT_WIDTH, 
00050                    unsigned height = DEFAULT_HEIGHT);
00051       
00052       virtual ~OpenGLCanvas();
00053       
00054       //@}-----------------------------------------------------------------
00055       ///@name Saving
00056       //@{-----------------------------------------------------------------
00057       
00058       /**
00059        * Attempts to saver this canvas' image to the specified file
00060        * @returns whether or not the save was successful
00061        */
00062       bool save(const char *fileName);
00063       
00064       //@}-----------------------------------------------------------------
00065       ///@name OpenGL light utility methods (lights specified by integer id)
00066       //@{-----------------------------------------------------------------
00067       
00068       /// Turns the light on
00069       void lightOn(int light);
00070       /// Turns the light off
00071       void lightOff(int light);
00072       /// Specifies the position of the light
00073       /// @note Assumes current matrixMode is GL_MODELVIEW
00074       void lightPos(int light, float x, float y, float z);
00075       /// Specifies the color of the light
00076       void lightColor(int light, float r, float g, float b);
00077       /// Specifies the function of the light
00078       void lightFunc(int light, float a, float b, float c);
00079       
00080       //@}-----------------------------------------------------------------
00081       
00082       virtual void init();
00083       
00084       virtual bool supportsOpenGL() const;
00085       
00086       virtual QWidget *getQWidget() {
00087          return this;
00088       }
00089       
00090    public slots:
00091       ///@name Main usage interface
00092       //@{-----------------------------------------------------------------
00093       
00094       void setDrawMode(int style);
00095       virtual void redraw();
00096       
00097       //@}-----------------------------------------------------------------
00098       
00099    protected:
00100       ///@name Overridden from QWidget
00101       //@{-----------------------------------------------------------------
00102       
00103       virtual void mousePressEvent(QMouseEvent *);
00104       virtual void mouseReleaseEvent(QMouseEvent *);
00105       virtual void mouseMoveEvent(QMouseEvent *);
00106       
00107       virtual void keyPressEvent(QKeyEvent *event);
00108       virtual void keyReleaseEvent(QKeyEvent *event);
00109       
00110       virtual QSize sizeHint() const;
00111       virtual QSize minimumSize() const;
00112       virtual QSize maximumSize() const;
00113       
00114       virtual void initializeGL();
00115       virtual void paintEvent(QPaintEvent *e);
00116       void resizeGL(int width, int height);
00117       
00118       //@}-----------------------------------------------------------------
00119       
00120    protected:
00121       int m_drawMode;
00122       
00123    private:
00124       void _init(bool defaultInteractionListeners);
00125       void _setupQWidget();
00126 };
00127 
00128 #endif // OPENGL_CANVAS_H_
00129 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6