SimpleNGL 1.0
include/GLWindow.h
Go to the documentation of this file.
00001 #ifndef __GL_WINDOW_H__
00002 #define __GL_WINDOW_H__
00003 
00004 #include "ngl/Camera.h"
00005 #include "ngl/TransformStack.h"
00006 #include "ngl/Obj.h"
00007 #include "Timer.h"
00008 #include "Grid.h"
00009 #include "SurfaceSphericalDeformer.h"
00010 
00011 #include "NoiseDeformer.h"
00012 
00013 // must be included after our stuff becuase GLEW needs to be first
00014 #include <QtOpenGL>
00015 
00016 struct OPTIONS
00017 {
00018     int width;
00019     int height;
00020     bool ispc;
00021     bool chunked;
00022 };
00023 
00030 class GLWindow : public QGLWidget
00031 {
00032 Q_OBJECT
00033 public :
00034 
00037   GLWindow(
00038            QWidget *_parent
00039           );
00040 
00041 ~GLWindow(){
00042       delete m_grid;
00043       m_timer.endCycle("App");
00044   }
00045 
00048 void processKeyPress(QKeyEvent *_event);
00049 
00050 inline void registerConsole( QTextEdit *c )
00051 {
00052     m_console = c;
00053 }
00054 
00055 public slots:
00056 
00057   inline void setDeformer(int _v){m_terrain = _v; std::cout << _v <<std::endl; reset();}
00058 
00059   inline void setnextWidth(int _w){m_options.width = _w; }
00060   inline void setnextHeight(int _h){m_options.height = _h; }
00061 
00062   inline void setOrig(bool _v){m_orig = _v;updateGL();}
00063 
00064   inline void setMode(int _v){m_options.ispc = _v; std::cout << _v <<std::endl; reset();}
00065   inline void setChunked(int _v){m_options.chunked= _v;std::cout << _v <<std::endl; reset();}
00066 
00067   inline void setMag(double _v){m_noiseDeformer.setMag((float)_v); updateGrid();}
00068 
00069   inline void setSphereX(double _v){m_spherDeformer.pos().x = (float)_v; updateGrid();}
00070   inline void setSphereY(double _v){m_spherDeformer.pos().y = (float)_v; updateGrid();}
00071   inline void setSphereZ(double _v){m_spherDeformer.pos().z = (float)_v; updateGrid();}
00072 
00073   inline void setSphereRad(double _v){m_spherDeformer.rad() = (float)_v; updateGrid();}
00074 
00075   void reset();
00076 
00077   void updateGrid();
00078 
00079   inline void printIspcRadial(){log(m_timer.getRecord("ispc_radial"));}
00080   inline void printIspcNoise(){log(m_timer.getRecord("ispc_noise"));}
00081   inline void printSerialRadial(){log(m_timer.getRecord("serial_radial"));}
00082   inline void printSerialNoise(){log(m_timer.getRecord("serial_noise"));}
00083 
00084 protected:
00085 
00086 
00087   inline void log( const std::string &_msg)
00088   {
00089       QString tmp = QString::fromStdString(_msg);
00090       m_console->append(tmp);
00091   }
00092 
00098   void genShader(const std::string &_name, const std::string &_VSname, const std::string &_FSname, const std::vector<std::string> &_attributes);
00099 
00101   void initializeGL();
00102 
00104   void resizeGL(const int _w,const int _h);
00105 
00107   void paintGL();
00108 
00110   ngl::TransformStack m_transformStack;
00111 
00112 private:
00115   void mouseMoveEvent(
00116       QMouseEvent * _event
00117       );
00118 
00122   void mousePressEvent(
00123       QMouseEvent *_event
00124       );
00125 
00129   void mouseReleaseEvent(
00130       QMouseEvent *_event
00131       );
00132 
00136   void wheelEvent(
00137       QWheelEvent *_event
00138       );
00139 
00140   bool m_orig, m_terrain;
00141 
00142   float m_width,m_height;
00143 
00145   int m_spinXFace;
00147   int m_spinYFace;
00149   bool m_rotate;
00151   int m_origX;
00153   int m_origY;
00154 
00156   void setupShaders();
00157 
00158   GLuint m_pointVao;
00159 
00160   QTextEdit *m_console;
00161 
00163   ngl::Camera m_cam;
00164   Imath::V3f m_zoomPos;
00165 
00166   Timer m_timer;
00167 
00168   Grid *m_grid;
00169   SurfaceSphericalDeformer m_spherDeformer;
00170 
00171   OPTIONS m_options;
00172 
00173   NoiseDeformer m_noiseDeformer;
00174 
00175 };
00176 
00177 #endif
00178 
 All Classes Namespaces Files Functions Variables Defines