00001 #include "GL2DView.h"
00002
00003 #include <QtGui>
00004 #include <QtOpenGL>
00005
00006 GL2DView::GL2DView() : GLView()
00007 {
00008 xCoord = 0.5;
00009 yCoord = 0.5;
00010 zCoord = 0.5;
00011 }
00012
00013 GL2DView::~GL2DView()
00014 {
00015 }
00016
00017 void GL2DView::initializeGL()
00018 {
00019 GLenum glError;
00020
00021 glError = glGetError();
00022 if(glError != GL_NO_ERROR)
00023 {
00024 qDebug() << "initializeGL2D: an error was still registered: " << (char*)gluErrorString(glError);
00025 }
00026
00027
00028 glShadeModel(GL_SMOOTH);
00029 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00030 glDisable(GL_DEPTH_TEST);
00031 glBindTexture(GL_TEXTURE_3D, volumeDesc->volumeTexture);
00032
00033 glError = glGetError();
00034 if(glError != GL_NO_ERROR)
00035 {
00036 qDebug() << "initializeGL2D error: " << (char*)gluErrorString(glError);
00037 }
00038 }
00039
00040 void GL2DView::uninitializeGL()
00041 {
00042 GLenum glError;
00043
00044 glError = glGetError();
00045 if(glError != GL_NO_ERROR)
00046 {
00047 qDebug() << "uninitializeGL2D: an error was still registered: " << (char*)gluErrorString(glError);
00048 }
00049
00050 glEnable(GL_DEPTH_TEST);
00051
00052 glError = glGetError();
00053 if(glError != GL_NO_ERROR)
00054 {
00055 qDebug() << "uninitializeGL2D error: " << (char*)gluErrorString(glError);
00056 }
00057 }
00058
00059 void GL2DView::paintGL()
00060 {
00061 GLenum glError;
00062
00063 glError = glGetError();
00064 if(glError != GL_NO_ERROR)
00065 {
00066 qDebug() << "paintGL2D: an error was still registered: " << (char*)gluErrorString(glError);
00067 }
00068
00069 glClear(GL_COLOR_BUFFER_BIT);
00070
00071 if(volumeDesc->volumeTexture != 0) {
00072 GLfloat startX, startY;
00073
00074 glEnable(GL_TEXTURE_3D);
00075
00076 startX = -1;
00077 startY = 0;
00078 glBegin(GL_QUADS);
00079 glTexCoord3f(xCoord, 0, 0);
00080 glVertex3f(startX, startY, 0);
00081 glTexCoord3f(xCoord, 1, 0);
00082 glVertex3f(startX + 1, startY, 0);
00083 glTexCoord3f(xCoord, 1, 1);
00084 glVertex3f(startX + 1, startY + 1, 0);
00085 glTexCoord3f(xCoord, 0, 1);
00086 glVertex3f(startX, startY + 1, 0);
00087 glEnd();
00088
00089 startX = 0;
00090 startY = 0;
00091 glBegin(GL_QUADS);
00092 glTexCoord3f(0, yCoord, 0);
00093 glVertex3f(startX, startY, 0);
00094 glTexCoord3f(1, yCoord, 0);
00095 glVertex3f(startX + 1, startY, 0);
00096 glTexCoord3f(1, yCoord, 1);
00097 glVertex3f(startX + 1, startY + 1, 0);
00098 glTexCoord3f(0, yCoord, 1);
00099 glVertex3f(startX, startY + 1, 0);
00100 glEnd();
00101
00102 startX = 0;
00103 startY = -1;
00104 glBegin(GL_QUADS);
00105 glTexCoord3f(0, 0, zCoord);
00106 glVertex3f(startX, startY, 0);
00107 glTexCoord3f(1, 0, zCoord);
00108 glVertex3f(startX + 1, startY, 0);
00109 glTexCoord3f(1, 1, zCoord);
00110 glVertex3f(startX + 1, startY + 1, 0);
00111 glTexCoord3f(0, 1, zCoord);
00112 glVertex3f(startX, startY + 1, 0);
00113 glEnd();
00114
00115 glDisable(GL_TEXTURE_3D);
00116 }
00117
00118 glEnable(GL_BLEND);
00119 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00120 glBegin(GL_LINES);
00121 glColor3f(0.1f, 0.1f, 0.1f);
00122 glVertex3f(-1, 0, 0);
00123 glVertex3f(1, 0, 0);
00124 glVertex3f(0, -1, 0);
00125 glVertex3f(0, 1, 0);
00126 glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
00127 glVertex3f(-1 + yCoord, 1, 0);
00128 glVertex3f(-1 + yCoord, 0, 0);
00129 glVertex3f(xCoord, 1, 0);
00130 glVertex3f(xCoord, -1, 0);
00131 glVertex3f(-1, zCoord, 0);
00132 glVertex3f(1, zCoord, 0);
00133 glVertex3f(0, -1 + yCoord, 0);
00134 glVertex3f(1, -1 + yCoord, 0);
00135 glEnd();
00136 glColor4f(1, 1, 1, 1);
00137 glDisable(GL_BLEND);
00138
00139 glError = glGetError();
00140 if(glError != GL_NO_ERROR)
00141 {
00142 qDebug() << "paintGL2D error: " << (char*)gluErrorString(glError);
00143 }
00144 }
00145
00146 void GL2DView::resizeGL(int width, int height)
00147 {
00148 GLenum glError;
00149
00150 glError = glGetError();
00151 if(glError != GL_NO_ERROR)
00152 {
00153 qDebug() << "resizeGL2D: an error was still registered: " << (char*)gluErrorString(glError);
00154 }
00155 glViewport(0, 0, width, height);
00156
00157 glMatrixMode(GL_PROJECTION);
00158 glLoadIdentity();
00159
00160
00161 glMatrixMode(GL_MODELVIEW);
00162 glLoadIdentity();
00163
00164 glError = glGetError();
00165 if(glError != GL_NO_ERROR)
00166 {
00167 qDebug() << "resizeGL2D error: " << (char*)gluErrorString(glError);
00168 }
00169 }
00170
00171 void GL2DView::mousePressEvent(QMouseEvent *event)
00172 {
00173 mouseEvent(event);
00174 }
00175
00176 void GL2DView::mouseMoveEvent(QMouseEvent *event)
00177 {
00178 if(event->x() >= 0 && event->x() < parent->width() && event->y() >= 0 && event->y() < parent->height())
00179 {
00180 mouseEvent(event);
00181 }
00182 }
00183
00184 void GL2DView::mouseEvent(QMouseEvent *event)
00185 {
00186 if (event->buttons() & Qt::LeftButton) {
00187 if(event->x() < parent->width() / 2) {
00188 if(event->y() < parent->height() / 2) {
00189 yCoord = (float)event->x() / parent->width() * 2;
00190 zCoord = 1.0f - (float)event->y() / parent->height() * 2;
00191 }
00192 } else {
00193 if(event->y() < parent->height() / 2) {
00194 xCoord = (float)event->x() / parent->width() * 2 - 1.0f;
00195 zCoord = 1.0f - (float)event->y() / parent->height() * 2;
00196 } else {
00197 xCoord = (float)event->x() / parent->width() * 2 - 1.0f;
00198 yCoord = 2.0f - (float)event->y() / parent->height() * 2;
00199 }
00200 }
00201 parent->updateGL();
00202 }
00203 }
00204
00205 void GL2DView::wheelEvent(QWheelEvent *event)
00206 {
00207 }