00001
00002 #ifndef OPENGLWIDGET_H
00003 #define OPENGLWIDGET_H
00004
00005
00006 #include "compiler_options.h"
00007
00008 #include <glew/glew.h>
00009 #include <devil/il.h>
00010
00011 #include <QtOpenGL/QGLWidget>
00012 #include <QtOpenGL/QtOpenGL>
00013 #include <QtGui/QGradientStops>
00014
00015 #include "Volume.h"
00016
00017
00018
00019 class OpenGLWidget : public QGLWidget
00020 {
00021
00022 Q_OBJECT
00023
00024 public:
00028 OpenGLWidget( QWidget *parent=0, QGLWidget* shareWidget = 0 );
00029
00033 ~OpenGLWidget();
00034
00038 bool create3DTexture( Volume *volume );
00039
00043 void release();
00044
00048 void paintGL();
00049
00053 void keyEvent( int key );
00054
00058 void mouseMoveEvent( QMouseEvent *e );
00059
00063 void mousePressEvent( QMouseEvent *e );
00064
00068 void mouseReleaseEvent( QMouseEvent *e );
00069
00073 void setLightValue ( LIGHT_MODEL model, float value );
00074
00075
00076 public slots:
00080 void GenerateGradientTexture( const QGradientStops &);
00081
00085 void setRenderMode( RENDER_MODE renderMode );
00086
00087
00088 protected:
00089
00093 void initializeGL();
00094
00098 void resizeGL( int width, int height );
00099
00100
00101 private:
00102
00106 void initGlew();
00107
00111 void initDevIL();
00112
00116 const int GetNextPowerOfTwo(const int iNumber);
00117
00121 void paintXAxis();
00122
00126 void paintYAxis();
00127
00131 void paintZAxis();
00132
00136 void renderView();
00137
00141 bool loadShader();
00142
00146 void unloadShader();
00147
00151 char* readShaderFile( char* shaderFile );
00152
00156 void drawBoundingCube( float x, float y, float z );
00157
00161 void drawBackSideCube();
00162
00166 void drawQuad();
00167
00171 void doRaycasting();
00172
00176 bool createBuffers();
00177
00181 void deleteBuffers();
00182
00186 void renderFrontSideBuffer();
00187
00191 void renderBackSideBuffer();
00192
00196 void testRenderedToBuffer();
00197
00201 void drawCube();
00202
00206 void createInvRotMatrix();
00207
00211 float toRad( float grad );
00212
00213
00217 void printProgramInfoLog(GLuint obj);
00218
00222 void printShaderInfoLog(GLuint obj);
00223
00227 int printOglError(char *file, int line);
00228
00229
00230 public:
00234 float m_AxisValue;
00235
00239 int m_Axis;
00240
00244 float m_rayStepSize;
00245
00246
00247 private:
00251 static unsigned int m_textureHandle3d;
00252
00256 static unsigned int m_textureHandle1d;
00257
00261 static bool m_textureCreated;
00262
00266 static bool m_librariesInitialised;
00267
00271 QColor m_clearColor;
00272
00276 float m_textureCoord;
00277
00281 static int m_dimX, m_dimY, m_dimZ;
00282
00286 static float m_xRot, m_yRot, m_zRot;
00287
00291 static int m_viewWidth, m_viewHeight, m_view3DWidth, m_view3DHeight;
00292
00296 static int m_showView;
00297
00301 GLuint m_fsFbo, m_fsRenderTexture, m_fsRenderBuffer;
00302
00306 GLuint m_bsFbo, m_bsRenderTexture, m_bsRenderBuffer;
00307
00311 GLuint m_vertexShader, m_fragmentShader, m_shaderProgram;
00312
00316 GLint m_frontSide, m_backSide, m_volume, m_tf, m_stepSize;
00317
00321 static int m_lastXPosition, m_lastYPosition;
00322
00326 bool m_mbPressed;
00327
00331 int m_renderMode;
00332
00336 float m_ka, m_kd, m_kg, m_ks;
00337
00341 Matrix m_invRotMatrix;
00342 };
00343
00344 #endif