00001 #ifndef GLWIDGET_H 00002 #define GLWIDGET_H 00003 00004 #include <QtOpenGL/QGLWidget> 00005 #include <QTimer> 00006 #include <GL/gl.h> 00007 00008 class CellSpace; 00009 00010 class GLwidget : public QGLWidget 00011 { 00012 Q_OBJECT 00013 protected: 00014 void initializeGL(); 00015 void paintGL(); 00016 void resizeGL(int w, int h); 00017 public: 00018 GLwidget(const QGLFormat &format, QWidget *parent = 0, CellSpace *space = NULL); 00019 ~GLwidget(); 00020 void loadTexture(int w, int h, unsigned char *texture_data); 00021 QSize sizeHint()const{ return QSize(300, 300); } 00022 void mouseMoveEvent(QMouseEvent *event); 00023 void mousePressEvent(QMouseEvent *event); 00024 void wheelEvent(QWheelEvent *event); 00025 void startSimulation(); 00026 void stopSimulation(); 00027 CellSpace* getSpace(){ return space; } 00028 public slots: 00029 void runSimulation(); 00030 private: 00031 GLuint tex; 00032 static bool initialized; 00033 float zoom; 00034 float pos_x,pos_y; 00035 int w,h; 00036 int tex_w,tex_h; 00037 int mouse_x,mouse_y; 00038 QTimer timer; 00039 CellSpace *space; 00040 }; 00041 00042 #endif // GLWIDGET_H