00001 #include <iostream>
00002 #include <fstream>
00003 #include <stdlib.h>
00004 #include <windows.h>
00005 #include <glew.h>
00006 #include <il.h>
00007 #include <GL/glui.h>
00008 #include <io.h>
00009 #include <fcntl.h>
00010
00011 #include "common.h"
00012 #include "FlowData.h"
00013 #include "Transfer.h"
00014 #include "FlowChannel.h"
00015 #include "Streamlines.h"
00016 using namespace std;
00017
00018 int main_window;
00019 int g_iWidth = 900, g_iHeight = 600;
00020 int controlsWidth = 160;
00021 float xyRatio, winRatio;
00022 int chX,chY,vel,pre,vor;
00023
00024 FlowData* dataset;
00025
00026 void glutClose(int control);
00027 void drawTransferFunction(void);
00028 void drawPoints(void);
00029 void drawStreamlines(std::vector<float*>);
00030 void renderText(float x, float y, void *font, char *string);
00031 int initTextures(std::string);
00032
00033 void theGame(void);
00034 void drawBall(float x, float y, float size);
00035 void drawRacket(float x, float y, float size);
00036 void drawGates(float gap);
00037 void drawBorders(void);
00038
00039 Transfer* tf;
00040 int num;
00041 int counter;
00042 int dividedBy = 200;
00043 int draggingPoint = -1;
00044 float* colorf;
00045 float* grid;
00046 bool active = false;
00047
00048 float shiftRacket=0;
00049 float ballX=.0f, ballY=.0f, ballXSpeed=.0f, ballYSpeed=-0.02f;
00050 float racketX=.0f, racketY=-.75f;
00051 float gateGap=.0f;
00052 float ballSize = .05f;
00053 bool playGame=false;
00054 bool lost = false, won=false;
00055 int racketHit=0;
00056 float streamlineInfluence = 10000.0f;
00057
00058
00059 const int sizeX = 64;
00060 const int sizeY = 64;
00061 float* xyz = new float[sizeX*sizeY*3];
00062
00063 Streamlines* sl;
00064 int streamLineDist = 30;
00065 float streamLineStep = 0.01;
00066 int maxStreamLineSteps = 50;
00067 int drawArrows = 0;
00068 int drawEuler = 0;
00069 int drawRK = 0;
00070 int arrow_distance = 20;
00071 int hurricane = 0;
00072 int adaptPt = 0;
00073 int arrow_size = 10;
00074 bool streamLineEChanged = true;
00075 bool streamLineRKChanged = true;
00076 std::vector<float*> euler;
00077 std::vector<float*> rungeKutta;
00078
00079 GLUI *glui;
00080 GLUI_RadioGroup* group1;
00081 GLUI_Scrollbar* slider;
00082 GLuint vertex;
00083 GLuint fragment;
00084 GLuint p;
00085 GLuint g_newTexture;
00086 GLuint g_uExampleTexture;
00087 GLuint g_PointTexture;
00088 GLuint g_ArrowTexture;
00089 GLuint g_BallTexture;
00090 GLuint velTexture;
00091 GLint doShade;
00092 GLint useData;
00093 GLint plotArrows;
00094 GLint plotBall;
00095 GLint arrowSize;
00096 GLint arrowAngle;
00097 GLint drawHurricane;
00098 GLint adaptPtSize;
00099
00100
00101
00102 void glutIdle(void)
00103 {
00104 if ( glutGetWindow() != main_window )
00105 glutSetWindow(main_window);
00106
00107
00108 glutPostRedisplay();
00109 }
00110
00111
00112 void glutDisplay(void)
00113 {
00114 GLUI_Master.sync_live_all();
00115 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00116
00117 glUniform1iARB(doShade, 0);
00118 glUniform1iARB(plotArrows, 0);
00119
00120 if (g_newTexture)
00121 {
00122 glActiveTexture(GL_TEXTURE1);
00123 glEnable(GL_TEXTURE_1D);
00124 glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, num, 0, GL_RGB, GL_FLOAT,(void*)colorf);
00125 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00126 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00127 glDisable(GL_TEXTURE_1D);
00128 }
00129
00130 float diffx, diffy;
00131 glUniform1iARB(doShade, 1);
00132 if (g_uExampleTexture)
00133 {
00134 glActiveTexture(GL_TEXTURE0);
00135 glEnable(GL_TEXTURE_2D);
00136
00137 if (winRatio > xyRatio)
00138 {
00139 float diff = (float)dataset->getChannel(0)->geom->getDimX()/(float)(g_iWidth-controlsWidth);
00140 glBegin(GL_QUADS);
00141 glTexCoord3f(0.0f,1.0f, 0.0f);
00142 glVertex3f(-1.0f*diff,1.0f,-1.0f);
00143 glTexCoord3f(1.0f,1.0f, 0.0f);
00144 glVertex3f(1.0f*diff,1.0f,-1.0f);
00145 glTexCoord3f(1.0f,0.0f, 1.0f);
00146 glVertex3f(1.0f*diff,-1.0f,-1.0f);
00147 glTexCoord3f(0.0f,0.0f, 1.0f);
00148 glVertex3f(-1.0f*diff,-1.0f,-1.0f);
00149 glEnd();
00150 } else {
00151 float diff = (float)dataset->getChannel(0)->geom->getDimY()/(float)(g_iHeight-100);
00152 glBegin(GL_QUADS);
00153 glTexCoord3f(0.0f,1.0f, 0.0f);
00154 glVertex3f(-1.0f,1.0f*diff,-1.0f);
00155 glTexCoord3f(1.0f,1.0f, 0.0f);
00156 glVertex3f(1.0f,1.0f*diff,-1.0f);
00157 glTexCoord3f(1.0f,0.0f, 1.0f);
00158 glVertex3f(1.0f,-1.0f*diff,-1.0f);
00159 glTexCoord3f(0.0f,0.0f, 1.0f);
00160 glVertex3f(-1.0f,-1.0f*diff,-1.0f);
00161 glEnd();
00162 }
00163 glDisable(GL_TEXTURE_2D);
00164 }
00165
00166 glUniform1iARB(doShade, 0);
00167
00168
00169 if (drawEuler || drawRK)
00170 {
00171 sl = new Streamlines(dataset, streamLineDist, streamLineStep, maxStreamLineSteps, g_iWidth-controlsWidth);
00172 if(drawEuler)
00173 {
00174 glColor4f(1.0f, .0f, .0f, 1.0f );
00175 if (streamLineEChanged) {
00176 euler = sl->getStreamLines(1);
00177 streamLineEChanged = false;
00178 }
00179 drawStreamlines(euler);
00180 }
00181 if (drawRK)
00182 {
00183 glColor4f(.0f, .0f, 1.0f, 1.0f );
00184 if (streamLineRKChanged) {
00185 rungeKutta = sl->getStreamLines(2);
00186 streamLineRKChanged = false;
00187 }
00188 drawStreamlines(rungeKutta);
00189 }
00190 }
00191
00192
00193 if(drawArrows)
00194 {
00195 glUniform1iARB(plotArrows, 1);
00196 glUniform1iARB(arrowSize, arrow_size);
00197 glUniform1iARB(adaptPtSize, adaptPt);
00198
00199 glActiveTexture(GL_TEXTURE2);
00200 glEnable(GL_TEXTURE_2D);
00201 glEnable(GL_BLEND);
00202 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00203
00204 if (g_ArrowTexture)
00205 {
00206 glEnable(GL_POINT_SPRITE);
00207 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
00208 glTexEnvf(GL_POINT_SPRITE_ARB,GL_COORD_REPLACE_ARB, GL_TRUE);
00209 float diffX = (float)dataset->getChannel(0)->geom->getDimX()/(float)(g_iWidth-controlsWidth);
00210
00211 for(int i=1; i < dataset->getChannel(0)->geom->getDimX(); i++)
00212 {
00213 if(i%arrow_distance==0){
00214 for(int j=0; j < dataset->getChannel(0)->geom->getDimY(); j++)
00215 {
00216 if(j%arrow_distance==0)
00217 {
00218 float pointX = (((((float)i/dataset->getChannel(0)->geom->getDimX())*2)-1)*(diffX));
00219 float pointY = ((((float)j/dataset->getChannel(0)->geom->getDimY())*2)-1);
00220 glColor3f(1.0f,0.0f,0.0f);
00221 int angle = j;
00222 glUniform1iARB(arrowAngle, angle);
00223 glBegin(GL_POINTS);
00224 glVertex3f(pointX,pointY,1.0f);
00225 glEnd();
00226 }
00227 }
00228 }
00229 }
00230
00231 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
00232 glDisable(GL_POINT_SPRITE);
00233 }
00234 glDisable(GL_BLEND);
00235 glDisable(GL_TEXTURE_2D);
00236
00237 glUniform1iARB(plotArrows, 0);
00238 }
00239
00240 glClearColor( .9f, .9f, .9f, 1.0f );
00241 drawTransferFunction();
00242
00243 if(playGame)
00244 theGame();
00245 if(lost)
00246 {
00247 glColor3f(1.0f,.0f,1.0f);
00248 renderText(-.1f,.0f,GLUT_BITMAP_TIMES_ROMAN_24,"You lost!");
00249 }
00250 else if(won)
00251 {
00252 glColor3f(1.0f,.0f,1.0f);
00253 renderText(-.1f,.0f,GLUT_BITMAP_TIMES_ROMAN_24,"not bad!");
00254 }
00255
00256 glutSwapBuffers();
00257 }
00258
00259 void glutReshape(int x, int y)
00260 {
00261 int tx, ty, tw, th;
00262 GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
00263 glViewport( tx, ty, tw, th );
00264
00265 glMatrixMode( GL_PROJECTION );
00266 glLoadIdentity();
00267
00268 g_iWidth = x;
00269 g_iHeight = y;
00270
00271 xyRatio= (float)dataset->getChannel(chX)->geom->getDimX()/(float)dataset->getChannel(chX)->geom->getDimY();
00272 printf("xyRatio: %f\n",xyRatio);
00273 winRatio=(float)(g_iWidth-controlsWidth)/((float)g_iHeight-((float)g_iHeight/8));
00274 printf("winRatio: %f\n",winRatio);
00275 }
00276
00277 void glutMouse(int button, int state, int x, int y)
00278 {
00279 float width = (float)g_iWidth-controlsWidth;
00280 float height = (float)g_iHeight;
00281 float xValue = (x-(width/20))/((19*(width/20))-(width/20));
00282 xValue*=num;
00283
00284 if(!active)
00285 {
00286 active!=active;
00287 if(x >= width/20 && x <= 19*(width/20))
00288 {
00289 if(y >= 177.5f*(height/200) && y <= 197.5f*(height/200))
00290 {
00291 bool onPoint=false;
00292
00293 for(unsigned int i=0; i<tf->points.size(); i++)
00294 {
00295
00296 if(xValue > tf->points.at(i)->getX()-8.0f && xValue < tf->points.at(i)->getX()+8.0f)
00297 {
00298
00299 if(y >= 177.5f*(height/200) && y <= 187.5f*(height/200))
00300 {
00301
00302 draggingPoint = i;
00303 onPoint = true;
00304 if(button == 2)
00305 {
00306 Color *c = new Color(0.0f,0.0f,0.0f);
00307 Color::chooseColor(*c);
00308 tf->points.at(draggingPoint)->color->SetNormalizedRed(c->GetNormalizedRed());
00309 tf->points.at(draggingPoint)->color->SetNormalizedGreen(c->GetNormalizedGreen());
00310 tf->points.at(draggingPoint)->color->SetNormalizedBlue(c->GetNormalizedBlue());
00311
00312 }
00313 }
00314 }
00315 }
00316 if(!onPoint)
00317 {
00318
00319
00320 Color *c = new Color(0.0f,0.0f,0.0f);
00321 if(Color::chooseColor(*c))
00322 {
00323 ColorPoint* point = new ColorPoint(xValue,c);
00324 tf->addPoint(point);
00325 }
00326 }
00327 }
00328 }
00329 tf->sortPoints();
00330 colorf = tf->colorInterpolation();
00331 }
00332 else
00333 {
00334 active=!active;
00335 tf->sortPoints();
00336 colorf = tf->colorInterpolation();
00337 draggingPoint = -1;
00338 }
00339 }
00340
00341 void glutMotion (int x, int y)
00342 {
00343 float width = (float)g_iWidth-controlsWidth;
00344 float height = (float)g_iHeight;
00345 float xValue = (x-(width/20))/((19*(width/20))-(width/20));
00346 xValue*=num;
00347
00348 if(draggingPoint != 0 && draggingPoint != tf->points.size()-1 && draggingPoint != -1)
00349 {
00350 if(x < width/20 || x > 19*(width/20) || y < 177.5f*(height/200) || y > 197.5f*(height/200))
00351 {
00352 tf->removePoint(draggingPoint);
00353 draggingPoint=-1;
00354 }
00355 else
00356 {
00357 tf->points.at(draggingPoint)->setX(xValue);
00358 }
00359 }
00360 active=!active;
00361 colorf = tf->colorInterpolation();
00362 }
00363
00364 void glutSpecialKey(int key, int x, int y)
00365 {
00366 if (key == GLUT_KEY_LEFT)
00367 {
00368 shiftRacket -= 0.05f;
00369 }
00370 if (key == GLUT_KEY_RIGHT)
00371 {
00372 shiftRacket += 0.05f;
00373 }
00374 }
00375
00376 void glutKeyboard(unsigned char key, int x, int y)
00377 {
00378
00379 if (key == unsigned char(27))
00380 {
00381 glutClose(1);
00382 }
00383 }
00384
00385 void glutClose(int control)
00386 {
00387
00388 delete dataset;
00389
00390 glDetachObjectARB(p,vertex);
00391 glDetachObjectARB(p,fragment);
00392 glDeleteObjectARB(vertex);
00393 glDeleteObjectARB(fragment);
00394 glDeleteObjectARB(p);
00395
00396 exit(1);
00397 }
00398
00399
00400
00408 void drawTransferFunction()
00409 {
00410 glUniform1iARB(doShade, 0);
00411 glDisable(GL_TEXTURE_1D);
00412 glDisable(GL_TEXTURE_2D);
00413
00414 glBegin(GL_QUADS);
00415 glColor3f(.7f,.7f,.7f);
00416 glVertex3f(-1.0f,-.75f,-1.0f);
00417 glVertex3f(1.0f,-.75f,-1.0f);
00418 glVertex3f(1.0f,-1.0f,-1.0f);
00419 glVertex3f(-1.0f,-1.0f,-1.0f);
00420 glEnd();
00421
00422 glBegin(GL_LINE_LOOP);
00423 glColor3f(.2f,.2f,.2f);
00424 glVertex3f(-.9f,-.775f,-1.0f);
00425 glVertex3f(.9f,-.775f,-1.0f);
00426 glVertex3f(.9f,-.875f,-1.0f);
00427 glVertex3f(-.9f,-.875f,-1.0f);
00428 glEnd();
00429
00430
00431 glColor3f(.0f,.0f,.0f);
00432 renderText(-.95f, -.95f, GLUT_BITMAP_HELVETICA_12, "wenig");
00433 renderText(-.55f, -.95f, GLUT_BITMAP_HELVETICA_12, "wenig/mittel");
00434 renderText(-.05f, -.95f, GLUT_BITMAP_HELVETICA_12, "mittel");
00435 renderText( .4f , -.95f, GLUT_BITMAP_HELVETICA_12, "mittel/viel");
00436 renderText( .85f, -.95f, GLUT_BITMAP_HELVETICA_12, "viel");
00437
00438 drawPoints();
00439 }
00440
00447 void drawPoints()
00448 {
00449 for(unsigned int i = 0; i < (tf->points.size()-1); i++)
00450 {
00451 float x = (tf->points.at(i)->getX()/num);
00452 float xTwo = (tf->points.at(i+1)->getX()/num);
00453 glBegin(GL_POLYGON);
00454 glColor4f(tf->points.at(i)->getColor()->GetNormalizedRed(),tf->points.at(i)->getColor()->GetNormalizedGreen(),tf->points.at(i)->getColor()->GetNormalizedBlue(),0.0f);
00455
00456 glVertex3f(((x*2.0f)-1.0f)*.9f,-.775f,-1.0f);
00457 glVertex3f(((x*2.0f)-1.0f)*.9f,-.874f,-1.0f);
00458 glColor4f(tf->points.at(i+1)->getColor()->GetNormalizedRed(),tf->points.at(i+1)->getColor()->GetNormalizedGreen(),tf->points.at(i+1)->getColor()->GetNormalizedBlue(),0.3f);
00459
00460 glVertex3f(((xTwo*2.0f)-1.0f)*.9f,-.874f,-1.0f);
00461 glVertex3f(((xTwo*2.0f)-1.0f)*.9f,-.775f,-1.0f);
00462 glEnd();
00463 }
00464
00465 glColor3f(0.0f,0.0f,0.0f);
00466 glBegin(GL_LINE_STRIP);
00467 for(unsigned int i=0; i<tf->points.size(); i++)
00468 {
00469 float x = (tf->points.at(i)->getX()/num);
00470 glVertex3f(((x*2.0f)-1.0f)*.9f,-.825f,-1.0f);
00471 }
00472 glEnd();
00473
00474 for(unsigned int i=0; i<tf->points.size(); i++)
00475 {
00476 float x = (tf->points.at(i)->getX()/num);
00477 glColor3f(tf->points.at(i)->getColor()->GetNormalizedRed(), tf->points.at(i)->getColor()->GetNormalizedGreen(), tf->points.at(i)->getColor()->GetNormalizedBlue());
00478 glBegin(GL_QUADS);
00479 glVertex3f(((x*2.0f)-1.0f)*.9f-.02f,-.825f+.02,-1.0f);
00480 glVertex3f(((x*2.0f)-1.0f)*.9f+.02f,-.825f+.02,-1.0f);
00481 glVertex3f(((x*2.0f)-1.0f)*.9f+.02f,-.825f-.02,-1.0f);
00482 glVertex3f(((x*2.0f)-1.0f)*.9f-.02f,-.825f-.02,-1.0f);
00483 glEnd();
00484
00485 glColor3f(1.0f,1.0f,1.0f);
00486 glBegin(GL_LINE_LOOP);
00487 glVertex3f(((x*2.0f)-1.0f)*.9f-.02f,-.825f+.02,-1.0f);
00488 glVertex3f(((x*2.0f)-1.0f)*.9f+.02f,-.825f+.02,-1.0f);
00489 glVertex3f(((x*2.0f)-1.0f)*.9f+.02f,-.825f-.02,-1.0f);
00490 glVertex3f(((x*2.0f)-1.0f)*.9f-.02f,-.825f-.02,-1.0f);
00491 glEnd();
00492 }
00493 }
00494
00503 void renderText(float x, float y, void *font, char *string)
00504 {
00505 char *c;
00506 glRasterPos2f(x,y);
00507 for (c=string; *c != '\0'; c++)
00508 {
00509 glutBitmapCharacter(font, *c);
00510 }
00511 }
00512
00513
00514
00521 void theGame()
00522 {
00523 ballX += ballXSpeed;
00524 ballY += ballYSpeed;
00525 if(ballX >= racketX-0.2f+shiftRacket && ballX <= racketX+0.2f+shiftRacket && ballY <= racketY+0.1f)
00526 {
00527 ballYSpeed *= -1;
00528 racketHit++;
00529 ballXSpeed -= (shiftRacket - ballX)/50.0f;
00530 if(racketHit%10==0)
00531 {
00532 streamlineInfluence /= 10;
00533 printf("next level\n");
00534 }
00535 }
00536 float diff;
00537 if (winRatio > xyRatio)
00538 diff = (float)dataset->getChannel(0)->geom->getDimX()/(float)(g_iWidth-controlsWidth);
00539 else
00540 diff = (float)dataset->getChannel(0)->geom->getDimY()/(float)(g_iHeight-100);
00541
00542
00543 if(ballX <= (-1.0f*diff)+.05f)
00544 {
00545 ballXSpeed *= -1;
00546 ballX = (-1.0f*diff)+.05f;
00547 }
00548 else if(ballX >= (1.0f*diff)-.05f)
00549 {
00550 ballXSpeed *= -1;
00551 ballX = (1.0f*diff)-.05f;
00552 }
00553
00554
00555 if(ballY >= 0.95f)
00556 {
00557 if(ballX > .0f-(gateGap/2.0f) && ballX < .0f+(gateGap/2.0f))
00558 {
00559 if(gateGap < ballSize)
00560 ballYSpeed *= -1;
00561 else
00562 {
00563 printf("u suck!");
00564 playGame = false;
00565 lost = true;
00566 }
00567 }
00568 else
00569 ballYSpeed *= -1;
00570 }
00571 else if(ballY < -.75)
00572 {
00573 printf("u suck!");
00574 playGame = false;
00575 lost = true;
00576 }
00577
00578 ballX -= dataset->getChannel(0)->getValueNormPos((ballX/2.0f)+.5f,(ballY/2.0f)+.5f)/streamlineInfluence;
00579 glClearColor(.0f,.0f,.0f,.0f);
00580 drawBall(ballX,ballY,ballSize);
00581 drawRacket(racketX,racketY,0.4f);
00582 drawGates(gateGap+=0.0001f);
00583 if(gateGap >= (1.0f*diff*2)*0.5f)
00584 {
00585 won = true;
00586 playGame = false;
00587 }
00588 drawBorders();
00589 }
00590
00600 void drawBall(float x, float y, float size)
00601 {
00602 glUniform1iARB(doShade, 0);
00603 glUniform1iARB(plotArrows, 0);
00604 glUniform1iARB(plotBall, 1);
00605 glUniform1iARB(arrowSize, 40);
00606
00607 glEnable(GL_POINT_SPRITE);
00608 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
00609 glEnable(GL_BLEND);
00610 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00611 glTexEnvf(GL_POINT_SPRITE_ARB,GL_COORD_REPLACE_ARB, GL_TRUE);
00612
00613 glBegin(GL_POINTS);
00614 glVertex3f(x,y,-1.0f);
00615 glEnd();
00616
00617 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
00618 glDisable(GL_POINT_SPRITE);
00619
00620 glDisable(GL_BLEND);
00621 glDisable(GL_TEXTURE_2D);
00622
00623 glUniform1iARB(plotBall, 0);
00624 glUniform1iARB(arrowSize, arrow_size);
00625 }
00626
00637 void drawRacket(float x, float y, float size)
00638 {
00639 x += shiftRacket;
00640 glColor3f(1.0f,0.0f,0.0f);
00641 glBegin(GL_QUADS);
00642 glVertex3f(x-(size/2.0f),y+0.05f,-1.0f);
00643 glVertex3f(x+(size/2.0f),y+0.05f,-1.0f);
00644 glVertex3f(x+(size/2.0f),y,-1.0f);
00645 glVertex3f(x-(size/2.0f),y,-1.0f);
00646 glEnd();
00647 }
00648
00656 void drawGates(float gap)
00657 {
00658 float diff;
00659 if (winRatio > xyRatio)
00660 diff = (float)dataset->getChannel(0)->geom->getDimX()/(float)(g_iWidth-controlsWidth);
00661 else
00662 diff = (float)dataset->getChannel(0)->geom->getDimY()/(float)(g_iHeight-100);
00663
00664 glColor3f(1.0f,0.0f,0.0f);
00665 glBegin(GL_QUADS);
00666 glVertex3f(-1.0f*diff,1.0f,-1.0f);
00667 glVertex3f(0.0f-(gap/2.0f),1.0f,-1.0f);
00668 glVertex3f(0.0f-(gap/2.0f),0.95f,-1.0f);
00669 glVertex3f(-1.0f*diff,0.95f,-1.0f);
00670 glEnd();
00671
00672 glColor3f(1.0f,0.0f,0.0f);
00673 glBegin(GL_QUADS);
00674 glVertex3f(0.0f+(gap/2.0f),1.0f,-1.0f);
00675 glVertex3f(1.0f*diff,1.0f,-1.0f);
00676 glVertex3f(1.0f*diff,0.95f,-1.0f);
00677 glVertex3f(0.0f+(gap/2.0f),0.95f,-1.0f);
00678 glEnd();
00679 }
00680
00686 void drawBorders()
00687 {
00688 float diff;
00689 if (winRatio > xyRatio)
00690 diff = (float)dataset->getChannel(0)->geom->getDimX()/(float)(g_iWidth-controlsWidth);
00691 else
00692 diff = (float)dataset->getChannel(0)->geom->getDimY()/(float)(g_iHeight-100);
00693
00694 glColor3f(1.0f,0.0f,0.0f);
00695 glBegin(GL_QUADS);
00696 glVertex3f((-1.0f*diff)-.05f,1.0f,-1.0f);
00697 glVertex3f(-1.0f*diff,1.0f,-1.0f);
00698 glVertex3f(-1.0f*diff,-.75f,-1.0f);
00699 glVertex3f((-1.0f*diff)-.05f,-.75f,-1.0f);
00700 glEnd();
00701
00702 glColor3f(1.0f,0.0f,0.0f);
00703 glBegin(GL_QUADS);
00704 glVertex3f(1.0f*diff,1.0f,-1.0f);
00705 glVertex3f((1.0f*diff)+.05f,1.0f,-1.0f);
00706 glVertex3f((1.0f*diff)+.05f,-.75f,-1.0f);
00707 glVertex3f(1.0f*diff,-.75f,-1.0f);
00708 glEnd();
00709 }
00710
00711
00712
00713
00714
00721 char *textFileRead(char *fn) {
00722
00723 FILE *fp;
00724 char *content = NULL;
00725
00726 int f =0; int count;
00727
00728 f = _open(fn, O_RDONLY);
00729
00730 count = _lseek(f, 0, SEEK_END);
00731
00732 _close(f);
00733
00734 if (fn != NULL) {
00735 fp = fopen(fn,"rt");
00736
00737 if (fp != NULL) {
00738
00739
00740 if (count > 0) {
00741 content = (char *)malloc(sizeof(char) * (count+1));
00742 count = (int)fread(content,sizeof(char),count,fp);
00743 content[count] = '\0';
00744 }
00745 fclose(fp);
00746 }
00747 }
00748 return content;
00749 };
00750
00757 void setShaders() {
00758 char *vShader,*fShader;
00759
00760 vertex = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
00761 fragment = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
00762
00763 vShader = textFileRead("Shader.vert");
00764 fShader = textFileRead("Shader.frag");
00765
00766 const char * vvShader = vShader;
00767 const char * ffShader = fShader;
00768
00769 glShaderSourceARB(vertex, 1, &vvShader,NULL);
00770 glShaderSourceARB(fragment, 1, &ffShader,NULL);
00771
00772 free(vShader);
00773 free(fShader);
00774
00775 glCompileShaderARB(vertex);
00776 glCompileShaderARB(fragment);
00777
00778 GLchar * error = new GLchar[2001];
00779 GLsizei len;
00780 glGetShaderInfoLog(fragment, 2000, &len, error);
00781 std::cout<<"."<<error<<std::endl;
00782
00783 p = glCreateProgramObjectARB();
00784
00785 glAttachObjectARB(p,vertex);
00786 glAttachObjectARB(p,fragment);
00787
00788 glLinkProgramARB(p);
00789 glUseProgramObjectARB(p);
00790
00791 };
00792
00793
00794
00795
00796
00803 void openFile(int control) {
00804
00805
00806
00807 colorf = tf->clearData();
00808 delete tf;
00809
00810 glBindTexture(GL_TEXTURE_1D, NULL);
00811 glBindTexture(GL_TEXTURE_2D, NULL);
00812
00813 glDetachObjectARB(p,vertex);
00814 glDetachObjectARB(p,fragment);
00815 glDeleteObjectARB(vertex);
00816 glDeleteObjectARB(fragment);
00817 glDeleteObjectARB(p);
00818
00819
00820
00821 OPENFILENAME ofn;
00822 char szFile[260];
00823 szFile[0] = '\0';
00824
00825 char szFileTitle[128];
00826 szFileTitle[0] = '\0';
00827
00828
00829 ZeroMemory(&ofn, sizeof(OPENFILENAME));
00830 ofn.lStructSize = sizeof(OPENFILENAME);
00831 ofn.hwndOwner = 0;
00832 ofn.lpstrFile = szFile;
00833 ofn.lpstrFile[0] = '\0';
00834 ofn.nMaxFile = sizeof(szFile);
00835 ofn.lpstrFilter = "Data\0*.GRI\0All\0*.*\0";
00836 ofn.nFilterIndex = 1;
00837 ofn.lpstrFileTitle = szFileTitle;
00838 ofn.nMaxFileTitle = sizeof(szFileTitle);
00839 ofn.lpstrInitialDir = NULL;
00840 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
00841
00842
00843 if (GetOpenFileName(&ofn)==TRUE)
00844 {
00845 GLenum glError = GL_NO_ERROR;
00846
00847 std::string fileName = ofn.lpstrFile;
00848
00849
00850 initTextures(fileName);
00851
00852
00853 }
00854 }
00855
00856
00864 void openColor(int control){
00865 OPENFILENAME ofn;
00866 char szFile[260];
00867 szFile[0] = '\0';
00868
00869 char szFileTitle[128];
00870 szFileTitle[0] = '\0';
00871
00872
00873 ZeroMemory(&ofn, sizeof(OPENFILENAME));
00874 ofn.lStructSize = sizeof(OPENFILENAME);
00875 ofn.hwndOwner = 0;
00876 ofn.lpstrFile = szFile;
00877 ofn.lpstrFile[0] = '\0';
00878 ofn.nMaxFile = sizeof(szFile);
00879 ofn.lpstrFilter = "Points\0*.pts\0All\0*.*\0";
00880 ofn.nFilterIndex = 1;
00881 ofn.lpstrFileTitle = szFileTitle;
00882 ofn.nMaxFileTitle = sizeof(szFileTitle);
00883 ofn.lpstrInitialDir = NULL;
00884 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
00885
00886
00887 if (GetOpenFileName(&ofn)==TRUE)
00888 {
00889 GLenum glError = GL_NO_ERROR;
00890 std::string fileName = ofn.lpstrFile;
00891
00892 ifstream file;
00893 file.open(fileName.c_str());
00894 if (!file){
00895 cout << "Error in openening file";
00896
00897 }
00898 tf->removePoints();
00899 tf->sortPoints();
00900
00901 int x; float r, g, b;
00902 string lineread;
00903 while(std::getline(file, lineread))
00904 {
00905 cout << lineread << "\n";
00906 for(int i =0; i < 4; i++)
00907 {
00908 int index = (int)lineread.find_first_of(',');
00909 string s = string( lineread, 0, index);
00910 char *cstr = new char [s.size()+1];
00911 strcpy (cstr, s.c_str());
00912 float f = (float)atof(cstr);
00913 lineread = string( lineread, index+1, lineread.length());
00914 if(i==0)
00915 x=(int)f;
00916 else if(i==1)
00917 r=f;
00918 else if(i==2)
00919 g=f;
00920 else if(i==3)
00921 b=f;
00922
00923 }
00924 if(x != 0.0 && x != num)
00925 {
00926 Color *c = new Color(r,g,b);
00927 ColorPoint* dp = new ColorPoint(x, c);
00928 tf->addPoint(dp);
00929 }
00930 }
00931 }
00932 }
00933
00934
00942 void saveColor(int control)
00943 {
00944 OPENFILENAME ofn;
00945 char szFileName[MAX_PATH] = "";
00946
00947 ZeroMemory(&ofn, sizeof(ofn));
00948
00949 ofn.lStructSize = sizeof(OPENFILENAME);
00950 ofn.hwndOwner = 0;
00951 ofn.lpstrFilter = "Points\0*.pts\0All\0*.*\0";
00952 ofn.lpstrFile = szFileName;
00953 ofn.nMaxFile = MAX_PATH;
00954 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
00955
00956 if(GetSaveFileName(&ofn))
00957 {
00958 printf("saved!!");
00959 std::string fileName = ofn.lpstrFile;
00960 fileName.append(".pts");
00961
00962 char *cstr = new char [fileName.size()+1];
00963 strcpy(cstr, fileName.c_str());
00964 ofstream myfile (cstr);
00965 if (myfile.is_open())
00966 {
00967 for(unsigned int i = 0; i < tf->points.size(); i++)
00968 {
00969 string str;
00970 char floatStringBuffer[256];
00971 sprintf(floatStringBuffer, "%f,", tf->points.at(i)->getX());
00972 str.append(floatStringBuffer);
00973 sprintf(floatStringBuffer, "%f,", tf->points.at(i)->getColor()->GetNormalizedRed());
00974 str.append(floatStringBuffer);
00975 sprintf(floatStringBuffer, "%f,", tf->points.at(i)->getColor()->GetNormalizedGreen());
00976 str.append(floatStringBuffer);
00977 sprintf(floatStringBuffer, "%f\n", tf->points.at(i)->getColor()->GetNormalizedBlue());
00978 str.append(floatStringBuffer);
00979 myfile << str;
00980 }
00981 myfile.close();
00982 }
00983
00984
00985 }
00986 }
00987
00994 void startGame(int control)
00995 {
00996
00997 if(lost==true)
00998 {
00999 lost=false;
01000 won = false;
01001 shiftRacket=0;
01002 ballX=.0f, ballY=.0f, ballXSpeed=.0f, ballYSpeed=-0.02f;
01003 racketX=.0f, racketY=-.75f;
01004 gateGap=.0f;
01005 ballSize = .05f;
01006 racketHit = 0;
01007 streamlineInfluence = 10000.0f;
01008 playGame=true;
01009 }
01010 else
01011 playGame=true;
01012 }
01013
01021 void colorCoding(int control) {
01022 glUniform1iARB(useData, group1->get_int_val());
01023 slider->update_scroll_parameters();
01024 arrow_size = slider->get_int_val();
01025 }
01026
01034 void drawStreamlines(std::vector<float*> lines)
01035 {
01036 float* line; float PoneX, PoneY, PtwoX, PtwoY;
01037 float diffX = (float)dataset->getChannel(0)->geom->getDimX()/(float)(g_iWidth-controlsWidth);
01038
01039 for (int i = 0; i < lines.size(); i++)
01040 {
01041 line = lines[i];
01042 for (int j = 0; j < maxStreamLineSteps-3; j=j+2)
01043 {
01044 PoneX = line[j]*2-1;
01045 PoneY = line[j+1]*2-1;
01046 PtwoX = line[j+2]*2-1;
01047 PtwoY = line[j+3]*2-1;
01048
01049 if (line[j] != -1 && line[j+1] != -1 && line[j+2] != -1 && line[j+3] != -1)
01050 {
01051 glBegin(GL_LINES);
01052 glVertex3f(PoneX*diffX,-PoneY,1.0f);
01053 glVertex3f(PtwoX*diffX,-PtwoY,1.0f);
01054 glEnd();
01055 }
01056 else
01057 break;
01058 }
01059 }
01060 }
01061
01062
01063
01064
01072 int initTextures(std::string fname)
01073 {
01074
01075 delete dataset;
01076
01077
01078 dataset = new FlowData();
01079
01080
01081
01082 bool result = dataset->loadDataset("D:\\Uni\\Semester 7\\Visualisierung\\LU\\Bsp_2\\FlowVisFramework\\data\\hurricane_p_tc_singletime10",false);
01083
01084 if(dataset->geometry.getIsFlipped())
01085 hurricane = 1;
01086
01087
01088 if (!result) {system("PAUSE"); result = 1;}
01089
01090
01091 chX = dataset->createChannelGeometry(0);
01092 chY = dataset->createChannelGeometry(1);
01093
01094
01095 vel = dataset->createChannelVectorLength(0,1,2);
01096 pre = 3; vor = 4;
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106 GLenum glError = GL_NO_ERROR;
01107
01108
01109 glError = glGetError();
01110
01111
01112
01113 glActiveTexture(GL_TEXTURE1);
01114 glEnable(GL_TEXTURE_1D);
01115 glGenTextures(1, &g_newTexture);
01116 glBindTexture(GL_TEXTURE_1D, g_newTexture);
01117
01118 glError = glGetError();
01119 if (glError != GL_NO_ERROR)
01120 {
01121 std::cerr<<"Error generating texture 1D: "<<gluErrorString(glError)<<std::endl;
01122 }
01123 glDisable(GL_TEXTURE_1D);
01124
01125
01126
01127 float maxVel = dataset->getChannel(vel)->getMax();
01128 float maxPre = dataset->getChannel(pre)->getMax();
01129 float maxVor = dataset->getChannel(vor)->getMax();
01130
01131 float minVel = dataset->getChannel(vel)->getMin();
01132 float minPre = dataset->getChannel(pre)->getMin();
01133 float minVor = dataset->getChannel(vor)->getMin();
01134
01135 float rangeVel = dataset->getChannel(vel)->getRange();
01136 float rangePre = dataset->getChannel(pre)->getRange();
01137 float rangeVor = dataset->getChannel(vor)->getRange();
01138
01139 float max, min, range;
01140 float velRange, velMin;
01141 int pos;
01142
01143 float* tex = new float[sizeX*sizeY*3];
01144
01145 for (int ch = 0; ch < 3; ch++)
01146 {
01147 if (ch == 0)
01148 {
01149 max = maxVel;
01150 min = minVel; range = rangeVel; pos = vel;
01151 velRange=range; velMin=min;
01152 }
01153 else if (ch == 1)
01154 {
01155 max = maxPre;
01156 min = minPre; range = rangePre; pos = pre;
01157 }
01158 else if (ch == 2)
01159 {
01160 max = maxVor;
01161 min = minVor; range = rangeVor; pos = vor;
01162 }
01163
01164 for(int i = 0; i<sizeY; i++) {
01165 for(int j = 0; j<sizeX*3; j+=3) {
01166 float b = ((dataset->getChannel(pos)->getValueNormPos(((float)j)/(sizeX*3.0f),((float)i)/sizeY))-min)/range;
01167 tex[(sizeY-i-1)*sizeX*3+j+ch] = b;
01168 }
01169 }
01170 }
01171
01172
01173 glActiveTexture(GL_TEXTURE0);
01174 glEnable(GL_TEXTURE_2D);
01175 glGenTextures(1, &g_uExampleTexture);
01176 glBindTexture(GL_TEXTURE_2D, g_uExampleTexture);
01177
01178 glError = glGetError();
01179 if (glError != GL_NO_ERROR)
01180 {
01181 std::cerr<<"Error generating texture 2D: "<<gluErrorString(glError)<<std::endl;
01182 }
01183 else if (g_uExampleTexture)
01184 {
01185 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,sizeX,sizeY,0,GL_RGB,GL_FLOAT,(void *)tex);
01186 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
01187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
01188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
01189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
01190
01191 glError = glGetError();
01192 if (glError != GL_NO_ERROR)
01193 {
01194 std::cerr<<"Could not upload texture: "<<gluErrorString(glError)<<std::endl;
01195 }
01196 }
01197 glDisable(GL_TEXTURE_2D);
01198
01199
01200
01201 ILuint arrowImage;
01202 ilGenImages(1, &arrowImage);
01203 ilBindImage(arrowImage);
01204
01205 ilLoadImage("arrow.png");
01206 ILuint Width, Height;
01207 Width = ilGetInteger(IL_IMAGE_WIDTH);
01208 Height = ilGetInteger(IL_IMAGE_HEIGHT);
01209 BYTE* Data = new BYTE[Width*Height*4];
01210 ilCopyPixels(0,0,0,Width,Height,1,IL_RGBA,IL_UNSIGNED_BYTE, Data);
01211
01212 if( arrowImage != NULL )
01213
01214 {
01215 glActiveTexture(GL_TEXTURE2);
01216 glEnable(GL_TEXTURE_2D);
01217
01218 glGenTextures( 1, &g_ArrowTexture );
01219 glBindTexture( GL_TEXTURE_2D, g_ArrowTexture );
01220
01221 glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
01222 glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );
01223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
01224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
01225
01226 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0,
01227 GL_RGBA, GL_UNSIGNED_BYTE, Data );
01228 }
01229
01230
01231 ILuint ballImage;
01232 ilGenImages(1, &ballImage);
01233 ilBindImage(ballImage);
01234
01235 ilLoadImage("ball.png");
01236
01237 Width = ilGetInteger(IL_IMAGE_WIDTH);
01238 Height = ilGetInteger(IL_IMAGE_HEIGHT);
01239 Data = new BYTE[Width*Height*4];
01240 ilCopyPixels(0,0,0,Width,Height,1,IL_RGBA,IL_UNSIGNED_BYTE, Data);
01241
01242 if( ballImage != NULL )
01243
01244 {
01245 glActiveTexture(GL_TEXTURE4);
01246 glEnable(GL_TEXTURE_2D);
01247
01248 glGenTextures( 1, &g_BallTexture );
01249 glBindTexture( GL_TEXTURE_2D, g_BallTexture );
01250
01251 glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
01252 glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );
01253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
01254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
01255
01256 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0,
01257 GL_RGBA, GL_UNSIGNED_BYTE, Data );
01258 }
01259
01260
01261
01262 float* xyz = new float[sizeX*sizeY*3];
01263
01264
01265 glError = glGetError();
01266
01267
01268
01269 glActiveTexture(GL_TEXTURE3);
01270 glEnable(GL_TEXTURE_2D);
01271 glGenTextures(1, &velTexture);
01272 glBindTexture(GL_TEXTURE_2D, velTexture);
01273
01274 glError = glGetError();
01275 if (glError != GL_NO_ERROR)
01276 {
01277 std::cerr<<"Error generating texture 3D: "<<gluErrorString(glError)<<std::endl;
01278 }
01279
01280 for(int i = 0; i<sizeY; i++) {
01281 for(int j = 0; j<sizeX*3; j+=3) {
01282 if(tex[(sizeY-i-1)*sizeX*3+j]!=0)
01283 {
01284 float a = (float)dataset->getChannel(0)->getValueNormPos(((float)j)/(sizeX*3),((float)i)/sizeY)/((tex[(sizeY-i-1)*sizeX*3+j]*velRange)+velMin);
01285 float b = (float)dataset->getChannel(1)->getValueNormPos(((float)j)/(sizeX*3),((float)i)/sizeY)/((tex[(sizeY-i-1)*sizeX*3+j]*velRange)+velMin);
01286
01287 xyz[(sizeY-i-1)*sizeX*3+j] = a;
01288 xyz[(sizeY-i-1)*sizeX*3+j+1] = b;
01289
01290 xyz[(sizeY-i-1)*sizeX*3+j] *= 0.5f;
01291 xyz[(sizeY-i-1)*sizeX*3+j+1] *= 0.5f;
01292
01293 xyz[(sizeY-i-1)*sizeX*3+j] += 0.5f;
01294 xyz[(sizeY-i-1)*sizeX*3+j+1] += 0.5f;
01295 }
01296 else
01297 {
01298 xyz[(sizeY-i-1)*sizeX*3+j] = 0.0f;
01299 xyz[(sizeY-i-1)*sizeX*3+j+1] = 0.0f;
01300 }
01301 }
01302 }
01303
01304 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,sizeX,sizeY,0,GL_RGB,GL_FLOAT,(void *)xyz);
01305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
01306 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
01307
01308 glDisable(GL_TEXTURE_2D);
01309
01310
01311
01312
01313 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
01314
01315 num = dataset->getChannel(vel)->geom->getDimX() * dataset->getChannel(vel)->geom->getDimY() / dividedBy;
01316 tf = new Transfer(num);
01317
01318 colorf = tf->colorInterpolation();
01319
01320
01321 GLint flow_sampler = glGetUniformLocationARB(p, "flow_sampler");
01322 glUniform1iARB(flow_sampler, 0);
01323
01324 GLint transfer_sampler = glGetUniformLocationARB(p, "transfer_sampler");
01325 glUniform1iARB(transfer_sampler, 1);
01326
01327 GLint arrow_sampler = glGetUniformLocationARB(p, "arrow_sampler");
01328 glUniform1iARB(arrow_sampler, 2);
01329
01330 GLint velValue = glGetUniformLocationARB(p, "xyz");
01331 glUniform1iARB(velValue, 3);
01332
01333 GLint ball_sampler = glGetUniformLocationARB(p, "ball_sampler");
01334 glUniform1iARB(ball_sampler, 4);
01335
01336 doShade = glGetUniformLocationARB(p, "shade");
01337 glUniform1iARB(doShade, 0);
01338
01339 useData = glGetUniformLocationARB(p, "data");
01340 glUniform1iARB(doShade, 0);
01341
01342 plotArrows = glGetUniformLocationARB(p, "arrow");
01343 glUniform1iARB(plotArrows, 0);
01344
01345 GLint size = glGetUniformLocationARB(p, "size");
01346 glUniform1iARB(size, 15.0);
01347
01348 arrowAngle = glGetUniformLocationARB(p, "angle");
01349 glUniform1iARB(arrowAngle, 90);
01350
01351 drawHurricane = glGetUniformLocationARB(p, "drawHurricane");
01352 glUniform1iARB(drawHurricane, hurricane);
01353
01354 adaptPtSize = glGetUniformLocationARB(p, "adaptSize");
01355 glUniform1iARB(adaptPtSize, adaptPt);
01356
01357 arrowSize = glGetUniformLocationARB(p, "size");
01358 glUniform1iARB(arrowSize, arrow_size);
01359
01360 plotBall = glGetUniformLocationARB(p, "ball");
01361 glUniform1iARB(plotBall, 0);
01362
01363 return result;
01364 };
01365
01366 int main(int argc, char** argv)
01367 {
01368 printf("Hello student :)\n");
01369
01370
01371
01372 std::cout << "- Initializing GLUT ..." << std::endl;
01373 glutInit (&argc, argv);
01374
01375 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
01376 glutInitWindowSize (g_iWidth,g_iHeight);
01377 glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
01378
01379 main_window = glutCreateWindow("VisLuFramework");
01380 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01381
01382 glViewport(0, 0, g_iWidth, g_iHeight);
01383
01384 glMatrixMode(GL_PROJECTION);
01385 glLoadIdentity();
01386
01387 glMatrixMode(GL_MODELVIEW);
01388 glLoadIdentity();
01389
01390 const unsigned char vpMessage[] = {"Initializing (see console for details) ..."};
01391 const int iMessageWidth = glutBitmapLength(GLUT_BITMAP_HELVETICA_12,vpMessage);
01392 const int iMessageHeight = glutBitmapHeight(GLUT_BITMAP_HELVETICA_12);
01393
01394 glColor4f(1.0f,1.0f,1.0f,1.0f);
01395 glRasterPos2f(-(float(iMessageWidth)/float(g_iWidth)),(float(iMessageHeight)/float(g_iHeight)));
01396 glutBitmapString(GLUT_BITMAP_HELVETICA_12,vpMessage);
01397 glRasterPos2f(0.0f,0.0f);
01398
01399
01400 GLUI_Master.set_glutIdleFunc (glutIdle);
01401 GLUI_Master.set_glutDisplayFunc (glutDisplay);
01402 GLUI_Master.set_glutReshapeFunc (glutReshape);
01403 GLUI_Master.set_glutMouseFunc (glutMouse);
01404 glutMotionFunc (glutMotion);
01405 GLUI_Master.set_glutKeyboardFunc (glutKeyboard);
01406 glutSpecialFunc(glutSpecialKey);
01407
01408 std::cout << "- GLUT initialized." << std::endl << std::endl;
01409
01410
01411 std::cout << "- Initializing GLEW ..." << std::endl;
01412 GLenum err = glewInit();
01413 if (err != GLEW_OK)
01414 {
01415
01416 std::cerr << "Error initializing GLEW: " << glewGetErrorString(err) << std::endl;
01417 return EXIT_FAILURE;
01418 }
01419 std::cout << "- GLEW initialized." << std::endl << std::endl;
01420
01421
01422 std::cout << "- Initializing DevIL ..." << std::endl;
01423 ilInit();
01424 if (ilGetError() != IL_NO_ERROR)
01425 {
01426 std::cerr << "Error initializing DevIL" << std::endl;
01427 return EXIT_FAILURE;
01428 }
01429 ilEnable(IL_ORIGIN_SET);
01430 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
01431 std::cout << "- DevIL initialized." << std::endl << std::endl;
01432
01433
01434
01435
01436 GLUI_Master.set_glutReshapeFunc( glutReshape );
01437 glui = GLUI_Master.create_glui_subwindow(main_window, GLUI_SUBWINDOW_RIGHT);
01438
01439 new GLUI_StaticText(glui, "");
01440 new GLUI_Button( glui, "Open", 0, openFile );
01441 new GLUI_StaticText(glui, "");
01442 new GLUI_Button( glui, "Close", 0, glutClose );
01443
01444 new GLUI_StaticText(glui, "");
01445 new GLUI_StaticText(glui, "");
01446
01447 GLUI_Panel* panel = new GLUI_Panel(glui, "Display data", 1);
01448
01449 new GLUI_StaticText(panel, "");
01450 new GLUI_Checkbox(panel,"Arrow Plot",&drawArrows);
01451 slider = new GLUI_Scrollbar(panel, "Arrow Size", GLUI_SCROLL_HORIZONTAL, GLUI_SCROLL_INT, 1, colorCoding);
01452 slider->set_int_limits(0, 30, GLUI_LIMIT_CLAMP);
01453 slider->set_int_val(arrow_size);
01454 GLUI_Checkbox* cb = new GLUI_Checkbox(panel,"Adapt Size",&adaptPt);
01455 cb->set_alignment(GLUI_ALIGN_RIGHT);
01456
01457 new GLUI_StaticText(panel, "");
01458 new GLUI_Checkbox(panel,"Euler-Streamlines",&drawEuler);
01459 new GLUI_StaticText(panel, "");
01460 new GLUI_Checkbox(panel,"RK-Streamlines",&drawRK);
01461 new GLUI_StaticText(panel, "");
01462 new GLUI_StaticText(panel, "");
01463 new GLUI_Separator(panel);
01464 new GLUI_StaticText(panel, "");
01465
01466 new GLUI_StaticText(panel, "Color coding:");
01467 new GLUI_StaticText(panel, "");
01468
01469 group1 = new GLUI_RadioGroup(panel,0,1,colorCoding);
01470 new GLUI_RadioButton( group1, "Velocity" );
01471 new GLUI_RadioButton( group1, "Pressure" );
01472 new GLUI_RadioButton( group1, "Vorticity" );
01473
01474 new GLUI_StaticText(panel, "");
01475
01476 new GLUI_Button(panel, "Open Color", 0, openColor );
01477 new GLUI_Button(panel, "Save Color", 0, saveColor );
01478
01479 new GLUI_StaticText(panel, "");
01480
01481 new GLUI_Button(glui, "Start Game", 0, startGame );
01482
01483 glui->set_main_gfx_window( main_window);
01484
01485
01486
01487
01488 glActiveTexture(GL_TEXTURE1);
01489 glEnable(GL_TEXTURE_1D);
01490 glGenTextures(1, &g_newTexture);
01491
01492
01493 glActiveTexture(GL_TEXTURE0);
01494 glEnable(GL_TEXTURE_2D);
01495 glGenTextures(1, &g_uExampleTexture);
01496
01497
01498 setShaders();
01499
01500 std::string fname = "c_block";
01501 int result = initTextures(fname);
01502
01503
01504 glutMainLoop();
01505
01506
01507 std::cout << "- Main loop terminated." << std::endl << std::endl;
01508
01509 return result;
01510 }