arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

BasicQGL.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     8-29-02
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2001 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 // BasicQGL.h: interface for the BasicQGL class.
00018 //
00019 //////////////////////////////////////////////////////////////////////
00020 
00021 //////////////////////////////////////////////////////////////////////
00022 /// This class serves mostly as a demonstration of QT gl rendering, 
00023 ///    but it is also usefull as a base class if you don't want
00024 ///    to implement all of the required functions from scratch.
00025 
00026 #pragma warning(disable:4786) //disable stl identifier too long warnings
00027 #pragma warning(disable:4530) //disable iostream unwind semantics warning 
00028 
00029 #if !defined(AFX_BASICQGL_H__B4067E20_999B_49AA_95E2_9DDD340AC225__INCLUDED_)
00030 #define AFX_BASICQGL_H__B4067E20_999B_49AA_95E2_9DDD340AC225__INCLUDED_
00031 
00032 #if _MSC_VER > 1000
00033 #pragma once
00034 #endif // _MSC_VER > 1000
00035 
00036 #include <qgl.h>
00037 #include <signalGutz.h>
00038 #include <eventGutz.h>
00039 #include <graphicsGutz.h>
00040 #include <commandQt/commandQt.h>
00041 #include <perf/Timer.h>
00042 
00043 #include <iostream>
00044 
00045 //////////////////////////////////////////////////////////////////////
00046 //////////////////////////////////////////////////////////////////////
00047 /// Basic QGL class
00048 //////////////////////////////////////////////////////////////////////
00049 //////////////////////////////////////////////////////////////////////
00050 
00051 class BasicQGL : public QGLWidget  
00052 {
00053    Q_OBJECT
00054 public:
00055    BasicQGL(QWidget *parent=0, const char *name=0 );
00056    virtual ~BasicQGL();
00057 
00058    virtual void update() { updateGL(); }
00059 
00060    //////////////////////////////////////////////////////
00061    ///@name Camera/Manip Set/Get
00062    ///@{
00063    virtual gutz::CameraSP  getCamera() const          { return _cam; }
00064    virtual void            setCamera(gutz::CameraSP c){ _cam = c; update(); }
00065    virtual gutz::ManipSP   getManip() const           { return _manip; }
00066    virtual void            setManip(gutz::ManipSP m)  { _manip = m; update(); }
00067    ///@}
00068    //////////////////////////////////////////////////////
00069 
00070    ////////////////////////////////////////
00071    ///@name Performance Timer on/off
00072    ///@{
00073    void         perfTimerOn(bool onoff)    { _timeOn = onoff; _time.start();}
00074    bool         perfTimerOn() const        { return _timeOn;}
00075    ///@}
00076    ////////////////////////////////////////
00077 
00078    ////////////////////////////////////////
00079    ///@name Redraw Timer (event callback timer)
00080    ///@{
00081 
00082    /// Stop (all) timers
00083    virtual void endTimer()             { killTimers(); }
00084    /// Start the render timer, updates every ms_time miliseconds
00085    virtual void setTimer(int ms_time)  { startTimer(ms_time); }
00086 
00087    ///@}
00088    /////////////////////////////////////////
00089 
00090    //////////////////////////////////////////////////////
00091    // A quick and dirty command "callback" for keys
00092    // You can subclass from the next line:
00093    //  class myKeyCmd : public BasicQGL::KeyCmdType ...
00094    //  all you need is a "void exec()" function.
00095    typedef KeyCmdQt<BasicQGL>           KeyCmdType;
00096    typedef gutz::SmartPtr< KeyCmdType > KeyCmdSPType;
00097    void setKeyCmd(char key, KeyCmdType *cmd) 
00098         {_keyMap[key] = KeyCmdSPType(cmd);}
00099 
00100    
00101    ////////////////////////////////////////////////////////
00102    ///@name Framebuffer Readback/Write & size:
00103    ///@{
00104 
00105    //// Get the Render Surface size (Frame buffer)
00106    gutz::vec2ui getScreenDims() const { return _cam->getScreen(); }
00107 
00108    /// pre intialized data buffer, with size elements, desired format
00109    /// for read, false = success, true = failure
00110    bool readFrameBuffer(void *dataPtr, int size, 
00111                         GLenum format = GL_RGBA, 
00112                         GLenum type   = GL_UNSIGNED_BYTE);
00113 
00114    bool writeFrameBuffer(void *dataPtr, int x, int y, 
00115                          GLenum format = GL_RGBA,
00116                          GLenum type   = GL_UNSIGNED_BYTE);
00117    ///@}
00118    ////////////////////////////////////////////////////////
00119 
00120    ////////////////////////////////////////////////////////
00121    ///@name gutz::Signals
00122    ///@{
00123    
00124    /// signal: drawDone(), called after the draw event completes.
00125    gutz::Signal<> drawDone;
00126 
00127    ///@}
00128    ////////////////////////////////////////////////////////
00129    
00130 
00131  signals:
00132    /// These are about to be depricated... moving to gutz::Signal
00133    void                  cameraChanged(gutz::CameraSP c);
00134    /// These are about to be depricated... moving to gutz::Signal
00135    void                  manipChanged(gutz::ManipSP m);
00136    /// These are about to be depricated... moving to gutz::Signal
00137    /// signal called after complete raw
00138    void                  drawFinished();
00139 
00140 protected:
00141 
00142    //////////////////////////////////////////////////////
00143    //Mouse "Callbacks"
00144    virtual void mouseMoveEvent( QMouseEvent * e);
00145    virtual void mousePressEvent( QMouseEvent * e);
00146    virtual void mouseReleaseEvent ( QMouseEvent * e );
00147    virtual void mouseDoubleClickEvent ( QMouseEvent * e );
00148 
00149    //////////////////////////////////////////////////////
00150    //Key board "Callbacks"
00151    virtual void keyPressEvent ( QKeyEvent * e );
00152    virtual void keyReleaseEvent ( QKeyEvent * e );
00153    virtual void handleKeyCmd( QKeyEvent *e );
00154 
00155    //////////////////////////////////////////////////////
00156    //Basic GL setup and rendering "callbacks"
00157    virtual void initializeGL ();
00158    virtual void resizeGL ( int width, int height );
00159    virtual void paintGL () {draw();}
00160 
00161    virtual void timerEvent( QTimerEvent * ) 
00162    { 
00163      if(!_mouseDown)
00164      {
00165          _cam->tumble(1);
00166          _manip->tumble(1);
00167          update(); 
00168      }
00169    }
00170 
00171 protected:
00172 
00173    //////////////////////////////////////////////////////
00174    /// overide this draw function
00175    virtual void draw();
00176 
00177    //////////////////////////////////
00178    /// init Camera and Manip
00179    virtual void initManipulators();
00180 
00181    gutz::CameraSP _cam;
00182    gutz::ManipSP  _manip;
00183 
00184    bool _mouseDown;  //< needed for tumbling
00185 
00186    //////////////////////////////////
00187    /// A quick and dirty keyboard
00188    /// command/callback helper :)
00189    typedef std::map<char, KeyCmdSPType , ltchar> KeyMapType;
00190    KeyMapType  _keyMap;
00191 
00192    Timer  _time;   ///< performance timer
00193    bool   _timeOn; ///< performance timer on?
00194 
00195 private:
00196    gutz::MouseEventSP      _curMouse;
00197    gutz::MouseMoveEventSP  _curMove;
00198 };
00199 
00200 #endif // !defined(AFX_BASICQGL_H__B4067E20_999B_49AA_95E2_9DDD340AC225__INCLUDED_)

Send questions, comments, and bug reports to:
jmk