00001 #pragma once
00002
00003 #include "FlowData.h"
00004 #include "TransferFunktion.h"
00005 #include "GameLevel.h"
00006 #include "Timer.h"
00007
00008 #include <windows.h>
00009 #include <iostream>
00010 #include <stdlib.h>
00011 #include <io.h>
00012 #include <glew.h>
00013 #include <openglut.h>
00014 #include <GL/glui.h>
00015 #include <il.h>
00016
00017
00019
00021
00022 HWND g_hWindow;
00023 int g_iWindow;
00024 int g_iWidth = 768, g_iHeight = 768;
00025
00026 float g_x0 = 0.0f, g_y0 = 0.0f;
00027 float g_fRatio = 1.0f, g_xyRatio = 1.0f;
00028 float g_fPicWidth, g_fPicHeight;
00029 GLint shOriginf2;
00030 GLint shSizef2;
00031
00032 const int rangeX = 516;
00033 const int rangeY = 516;
00034
00035 double dTime;
00036
00037
00038 #define MAXADDCHANNELS 3
00039 int chX;
00040 int chY;
00041 int vel;
00042 int numAddChannels = -1;
00043 int g_iChannel = 0;
00044 GLuint g_uVelocityTex, g_uValueTex;
00045 GLUI_Listbox* channelList;
00046 GLint shChannel;
00047
00048
00049 GLint pH;
00050 GLint shUseTF;
00051 GLint shDrawArrows;
00052 GLint shArrowSize;
00053 GLint shArrowScaling;
00054 int g_iArrowScaling;
00055 int g_iArrows;
00056 char * vertexShader;
00057 char * fragmentShader;
00058
00059
00060 float * lut[1+MAXADDCHANNELS];
00061 TransferFunktion * tf[1+MAXADDCHANNELS];
00062 TransferFunktionPunkt * tfp=NULL;
00063 unsigned int g_uTFTex = 1;
00064
00065
00066 GLuint g_uArrowTex;
00067 int g_iArrowDist = 20;
00068 int g_iArrowSize = 10;
00069
00070
00071 FlowData* dataset;
00072 GLuint g_uStreamlineFBO[2];
00073 GLuint g_uStreamlineTex[4];
00074 GLenum att_point[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
00075 int read_tex = 0;
00076 int write_tex = 1;
00077 GLint shSLIterator;
00078 GLint shSLStepsize;
00079 GLint shSLxPix;
00080 GLint shSLyPix;
00081 GLint shPicRatio;
00082 GLint shIntegration;
00083 float* SLtex;
00084 float* SLtex2;
00085
00086 GLuint texture;
00087
00088 float * streamlineSeeds;
00089 float * streamlineSeedsRK;
00090 int g_iSeeds;
00091 int g_iSteps;
00092 float g_iStepsize;
00093 int g_iWeightedSL = 1;
00094
00095 FlowChannel *Xchan;
00096 FlowChannel *Ychan;
00097 FlowChannel *Xvelos;
00098 FlowChannel *Yvelos;
00099
00100 int g_iEuler=1;
00101 int g_iRungeKutta=1;
00102 int g_iGamePause=1;
00103
00104 enum GLUICONTROL{
00105 GLUI_SYNC = 0,
00106 GLUI_EXIT,
00107 GLUI_PIC,
00108 STREAMLINEMOD
00109 };
00110
00111
00112 GameLevel * level=NULL;
00113
00114 GLuint g_uBallTex;
00115 GLuint g_uWallTex;
00116 GLuint g_uRacketTex;
00117 GLuint g_uBrickTex;
00118 GLuint g_uOverTex;
00119 GLuint g_uWinTex;
00120
00121
00122 void glutIdle(void)
00123 {
00124
00125 if ( glutGetWindow() != g_iWindow )
00126 glutSetWindow(g_iWindow);
00127
00128
00129 glutPostRedisplay();
00130 }
00131
00132 void drawChannel() {
00133 glUniform1i(shChannel, g_iChannel);
00134 glUniform1i(shUseTF, true);
00135
00136 glBegin(GL_QUADS);
00137 glTexCoord2f( 0.0f, 0.0f); glVertex3f( g_x0, g_y0, 0.0f);
00138 glTexCoord2f( 0.0f, 1.0f); glVertex3f( g_x0, (float)g_iHeight-75-g_y0, 0.0f);
00139 glTexCoord2f( 1.0f, 1.0f); glVertex3f( (float)g_iWidth-g_x0, (float)g_iHeight-75-g_y0, 0.0f);
00140 glTexCoord2f( 1.0f, 0.0f); glVertex3f( (float)g_iWidth-g_x0, g_y0, 0.0f);
00141 glEnd();
00142
00143 glUniform1i(shUseTF, false);
00144 }
00145
00146 void drawArrows() {
00147 glUniform1i(shDrawArrows, true);
00148 glUniform1i(shArrowSize, g_iArrowSize);
00149 glUniform1i(shArrowScaling, g_iArrowScaling);
00150
00151 glEnable(GL_BLEND);
00152 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00153 glEnable(GL_POINT_SPRITE);
00154 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
00155 glActiveTexture(GL_TEXTURE3);
00156 glBindTexture( GL_TEXTURE_2D, g_uArrowTex);
00157 glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
00158
00159 int numX = (int) ceil(g_fPicWidth/(float)g_iArrowDist);
00160 int numY = (int) ceil(g_fPicHeight/(float)g_iArrowDist);
00161
00162 glBegin(GL_POINTS);
00163 for (int i = 0; i<numY; i++)
00164 for (int j = 0; j<numX; j++) {
00165
00166 glVertex3f( g_x0+j*g_iArrowDist+g_iArrowDist/2, g_y0+i*g_iArrowDist+g_iArrowDist/2, 0.0f);
00167 }
00168 glEnd();
00169
00170 glDisable(GL_BLEND);
00171 glDisable(GL_POINT_SPRITE);
00172 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
00173
00174 glUniform1i(shDrawArrows, false);
00175 }
00176
00177 void drawStreamlineTex(int iter) {
00178 int sizeX = (int)(g_fPicWidth);
00179 int sizeY = (int)g_fPicHeight;
00180
00181 glActiveTexture(GL_TEXTURE4);
00182
00183 glBindTexture( GL_TEXTURE_2D, g_uStreamlineTex[2] );
00184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00186 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_FLOAT, 0);
00187
00188 glBindTexture( GL_TEXTURE_2D, g_uStreamlineTex[3] );
00189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00191 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_FLOAT, 0);
00192
00193 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_uStreamlineFBO[1]);
00194 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_uStreamlineTex[2], 0);
00195 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, g_uStreamlineTex[3], 0);
00196
00197 glMatrixMode(GL_PROJECTION);
00198 glPushMatrix();
00199 glLoadIdentity();
00200 gluOrtho2D (0, 1, 1, 0);
00201
00202 glViewport( 0, 0, sizeX, sizeY);
00203
00204 glUniform1i(shSLIterator, -1);
00205
00206 glEnable (GL_LINE_SMOOTH);
00207 glEnable (GL_BLEND);
00208 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00209 glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
00210 glLineWidth (2.5);
00211
00212
00213 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_uStreamlineFBO[1]);
00214 if (iter==0) {
00215 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
00216
00217 glClearColor(0.0,1.0,0.0,0.0);
00218 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00219 for(int j=0;j<g_iSeeds*2;j++)
00220 {
00221 glBegin(GL_LINE_STRIP);
00222
00223 for(int i=0; i<g_iSteps+1; i++)
00224 {
00225 if (SLtex[j*(g_iSteps+1)*3+i*3+2]==1.0f) break;
00226 float col= ((float)i/g_iSteps)/2+0.5;
00227 if(j>=g_iSeeds)
00228 {
00229 col =(1.0-(float)i/g_iSteps)/2;
00230 }
00231 glColor4f(0.0f,1.0f,0.0f,col+0.2f);
00232 float x=SLtex[j*(g_iSteps+1)*3+i*3];
00233 float y=SLtex[j*(g_iSteps+1)*3+i*3+1];
00234 if(y<0.0f || y>1.0f || x<0.0f || x>1.0f) break;
00235 glVertex2f(x,y);
00236 }
00237
00238 glEnd();
00239 }
00240 } else {
00241 glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
00242
00243 glClearColor(1.0,0.0,0.0,0.0);
00244 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00245 for(int j=0;j<g_iSeeds*2;j++)
00246 {
00247 glBegin(GL_LINE_STRIP);
00248
00249 for(int i=0; i<g_iSteps+1; i++)
00250 {
00251 if (SLtex2[j*(g_iSteps+1)*3+i*3+2]==1.0f) break;
00252 float col= ((float)i/g_iSteps)/2+0.5;
00253 if(j>=g_iSeeds)
00254 {
00255 col =(1.0-(float)i/g_iSteps)/2;
00256 }
00257 glColor4f(1.0f,0.0f,0.0f,col+0.2f);
00258 float x=SLtex2[j*(g_iSteps+1)*3+i*3];
00259 float y=SLtex2[j*(g_iSteps+1)*3+i*3+1];
00260 if(y<0.0f || y>1.0f || x<0.0f || x>1.0f) break;
00261 glVertex2f(x,y);
00262 }
00263
00264 glEnd();
00265 }
00266 }
00267
00268 glDisable (GL_LINE_SMOOTH);
00269 glDisable (GL_BLEND);
00270
00271 glPopMatrix();
00272
00273 int tx,ty,tw,th;
00274 GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
00275 glViewport( tx, ty, tw, th );
00276
00277 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00278 }
00279
00280 void updateStreamlines() {
00281 delete[] SLtex;
00282 SLtex = new float[(g_iSteps+1) * g_iSeeds * 3 * 2];
00283 for (int i=0; i<(g_iSteps+1) * g_iSeeds * 3 * 2; i++) {
00284 SLtex[i] = 0.0f;
00285 }
00286 delete[] SLtex2;
00287 SLtex2 = new float[(g_iSteps+1) * g_iSeeds * 3 * 2];
00288 for (int i=0; i<(g_iSteps+1) * g_iSeeds * 3 * 2; i++) {
00289 SLtex2[i] = 0.0f;
00290 }
00291
00292 srand(1);
00293
00294 if (g_iWeightedSL) {
00295 for (int i = 0; i<g_iSeeds; i++) {
00296 float x= ((float)i)/(g_iSeeds);
00297 float y= ((float)i)/(g_iSeeds);
00298 float xprc= Xchan->getValue(x);
00299 float yprc= Ychan->getValue(y);
00300
00301 xprc=Xchan->normalizeValue(xprc);
00302 yprc=Ychan->normalizeValue(yprc);
00303
00304 SLtex[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3] = SLtex[i*(g_iSteps+1)*3] =
00305 SLtex2[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3] = SLtex2[i*(g_iSteps+1)*3] =
00306 xprc+((float)rand()/RAND_MAX-0.5)/10;
00307 SLtex[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+1] = SLtex[i*(g_iSteps+1)*3+1] =
00308 SLtex2[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+1] = SLtex2[i*(g_iSteps+1)*3+1] =
00309 yprc+((float)rand()/RAND_MAX-0.5)/10;
00310 SLtex[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+2] = SLtex[i*(g_iSteps+1)*3+2] =
00311 SLtex2[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+2] = SLtex2[i*(g_iSteps+1)*3+2] =
00312 0.0f;
00313 }
00314 } else {
00315 int numX = (int) sqrt((float)g_iSeeds*g_xyRatio);
00316 int numY = g_iSeeds/numX;
00317 int diff = g_iSeeds - numX*numY;
00318
00319 for (int j = 0; j<numY; j++)
00320 for (int i = 0; i<numX; i++) {
00321 SLtex[(g_iSteps+1)*g_iSeeds*3 + j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3] =
00322 SLtex[j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3] =
00323 SLtex2[(g_iSteps+1)*g_iSeeds*3 + j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3] =
00324 SLtex2[j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3] =
00325 1/numX/2+(float)i/(float)numX+((float)rand()/RAND_MAX-0.5f)/numX;
00326 SLtex[(g_iSteps+1)*g_iSeeds*3 + j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+1] =
00327 SLtex[j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+1] =
00328 SLtex2[(g_iSteps+1)*g_iSeeds*3 + j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+1] =
00329 SLtex2[j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+1] =
00330 1/numY/2+(float)j/(float)numY+((float)rand()/RAND_MAX-0.5f)/numY;
00331 SLtex[(g_iSteps+1)*g_iSeeds*3 + j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+2] =
00332 SLtex[j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+2] =
00333 SLtex2[(g_iSteps+1)*g_iSeeds*3 + j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+2] =
00334 SLtex2[j*numX*(g_iSteps+1)*3+i*(g_iSteps+1)*3+2] =
00335 0.0f;
00336 }
00337 for (int i = g_iSeeds-diff; i < g_iSeeds; i++) {
00338 SLtex[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3] =
00339 SLtex[i*(g_iSteps+1)*3] =
00340 SLtex2[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3] =
00341 SLtex2[i*(g_iSteps+1)*3] =
00342 1.0f;
00343 SLtex[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+1] =
00344 SLtex[i*(g_iSteps+1)*3+1] =
00345 SLtex2[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+1] =
00346 SLtex2[i*(g_iSteps+1)*3+1] =
00347 1.0f;
00348 SLtex[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+2] =
00349 SLtex[i*(g_iSteps+1)*3+2] =
00350 SLtex2[(g_iSteps+1)*g_iSeeds*3 + i*(g_iSteps+1)*3+2] =
00351 SLtex2[i*(g_iSteps+1)*3+2] =
00352 1.0f;
00353 }
00354 }
00355
00356 glActiveTexture(GL_TEXTURE4);
00357
00358 glBindTexture( GL_TEXTURE_2D, g_uStreamlineTex[0] );
00359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00361 glTexImage2D(GL_TEXTURE_2D, 0, 0x8815, g_iSteps+1, g_iSeeds*2, 0, GL_RGB, GL_FLOAT, (void*) SLtex);
00362
00363 glBindTexture( GL_TEXTURE_2D, g_uStreamlineTex[1] );
00364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00366 glTexImage2D(GL_TEXTURE_2D, 0, 0x8815, g_iSteps+1, g_iSeeds*2, 0, GL_RGB, GL_FLOAT, 0);
00367
00368 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_uStreamlineFBO[0]);
00369 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, att_point[read_tex], GL_TEXTURE_2D, g_uStreamlineTex[read_tex], 0);
00370 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, att_point[write_tex], GL_TEXTURE_2D, g_uStreamlineTex[write_tex], 0);
00371
00372 glUniform1f(shSLStepsize, g_iStepsize);
00373 glUniform1f(shSLxPix, (float)g_iSteps+1.0f);
00374 glUniform1f(shSLyPix, (float)g_iSeeds*2);
00375 glUniform1f(shPicRatio, g_xyRatio);
00376
00377 glMatrixMode(GL_PROJECTION);
00378 glPushMatrix();
00379 glLoadIdentity();
00380 gluOrtho2D (0, 1, 1, 0);
00381
00382 glViewport( 0, 0, g_iSteps+1, g_iSeeds*2 );
00383
00384
00385 glUniform1i(shIntegration, 0);
00386
00387 for(int i = 0; i < g_iSteps+2; i++)
00388 {
00389 glDrawBuffer(att_point[write_tex]);
00390
00391 glActiveTexture(GL_TEXTURE4);
00392 glBindTexture(GL_TEXTURE_2D, g_uStreamlineTex[read_tex]);
00393 glUniform1i(shSLIterator, i);
00394 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00395
00396 glBegin(GL_QUADS);
00397 glTexCoord2f( 0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
00398 glTexCoord2f( 0.0f, 1.0f); glVertex3f( 0.0f, 1.0f, 0.0f);
00399 glTexCoord2f( 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
00400 glTexCoord2f( 1.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f);
00401 glEnd();
00402
00403
00404 if(read_tex)
00405 {
00406 read_tex = 0;
00407 write_tex = 1;
00408 }
00409 else
00410 {
00411 read_tex = 1;
00412 write_tex = 0;
00413 }
00414 }
00415
00416 glBindTexture(GL_TEXTURE_2D, g_uStreamlineTex[read_tex]);
00417
00418 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, SLtex);
00419
00420 drawStreamlineTex(0);
00421
00422
00423 read_tex = 0;
00424 write_tex = 1;
00425
00426 glPopMatrix();
00427
00428 int tx,ty,tw,th;
00429 GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
00430 glViewport( tx, ty, tw, th );
00431
00432 glUniform1i(shSLIterator, -1);
00433 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00434
00435 glActiveTexture(GL_TEXTURE4);
00436
00437 glBindTexture( GL_TEXTURE_2D, g_uStreamlineTex[0] );
00438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00440 glTexImage2D(GL_TEXTURE_2D, 0, 0x8815, g_iSteps+1, g_iSeeds*2, 0, GL_RGB, GL_FLOAT, (void*) SLtex2);
00441
00442 glBindTexture( GL_TEXTURE_2D, g_uStreamlineTex[1] );
00443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00445 glTexImage2D(GL_TEXTURE_2D, 0, 0x8815, g_iSteps+1, g_iSeeds*2, 0, GL_RGB, GL_FLOAT, 0);
00446
00447 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_uStreamlineFBO[0]);
00448 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, att_point[read_tex], GL_TEXTURE_2D, g_uStreamlineTex[read_tex], 0);
00449 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, att_point[write_tex], GL_TEXTURE_2D, g_uStreamlineTex[write_tex], 0);
00450
00451 glUniform1f(shSLStepsize, g_iStepsize);
00452 glUniform1f(shSLxPix, (float)g_iSteps+1.0f);
00453 glUniform1f(shSLyPix, (float)g_iSeeds*2);
00454 glUniform1f(shPicRatio, g_xyRatio);
00455
00456 glMatrixMode(GL_PROJECTION);
00457 glPushMatrix();
00458 glLoadIdentity();
00459 gluOrtho2D (0, 1, 1, 0);
00460
00461 glViewport( 0, 0, g_iSteps+1, g_iSeeds*2 );
00462
00463
00464 glUniform1i(shIntegration, 1);
00465
00466 for(int i = 0; i < g_iSteps+2; i++)
00467 {
00468 glDrawBuffer(att_point[write_tex]);
00469
00470 glActiveTexture(GL_TEXTURE4);
00471 glBindTexture(GL_TEXTURE_2D, g_uStreamlineTex[read_tex]);
00472 glUniform1i(shSLIterator, i);
00473 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00474
00475 glBegin(GL_QUADS);
00476 glTexCoord2f( 0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
00477 glTexCoord2f( 0.0f, 1.0f); glVertex3f( 0.0f, 1.0f, 0.0f);
00478 glTexCoord2f( 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
00479 glTexCoord2f( 1.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f);
00480 glEnd();
00481
00482
00483 if(read_tex)
00484 {
00485 read_tex = 0;
00486 write_tex = 1;
00487 }
00488 else
00489 {
00490 read_tex = 1;
00491 write_tex = 0;
00492 }
00493 }
00494
00495 glBindTexture(GL_TEXTURE_2D, g_uStreamlineTex[read_tex]);
00496
00497 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, SLtex2);
00498
00499 drawStreamlineTex(1);
00500
00501 read_tex = 0;
00502 write_tex = 1;
00503
00504 glPopMatrix();
00505
00506 GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
00507 glViewport( tx, ty, tw, th );
00508
00509 glUniform1i(shSLIterator, -1);
00510 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00511 }
00512
00513 void drawStreamlines() {
00514 if(g_iEuler)
00515 {
00516 glUniform1i(shSLIterator, -2);
00517 glEnable(GL_BLEND);
00518 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00519 glActiveTexture(GL_TEXTURE4);
00520 glBindTexture(GL_TEXTURE_2D, g_uStreamlineTex[2]);
00521 glBegin(GL_QUADS);
00522 glTexCoord2f( 0.0f, 1.0f); glVertex3f( g_x0, g_y0, 0.0f);
00523 glTexCoord2f( 0.0f, 0.0f); glVertex3f( g_x0, (float)g_iHeight-75-g_y0, 0.0f);
00524 glTexCoord2f( 1.0f, 0.0f); glVertex3f( (float)g_iWidth-g_x0, (float)g_iHeight-75-g_y0, 0.0f);
00525 glTexCoord2f( 1.0f, 1.0f); glVertex3f( (float)g_iWidth-g_x0, g_y0, 0.0f);
00526 glEnd();
00527
00528 glUniform1i(shSLIterator, -1);
00529 glDisable(GL_BLEND);
00530 }
00531 if(g_iRungeKutta)
00532 {
00533 glUniform1i(shSLIterator, -2);
00534 glEnable(GL_BLEND);
00535 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00536 glActiveTexture(GL_TEXTURE4);
00537 glBindTexture(GL_TEXTURE_2D, g_uStreamlineTex[3]);
00538 glBegin(GL_QUADS);
00539 glTexCoord2f( 0.0f, 1.0f); glVertex3f( g_x0, g_y0, 0.0f);
00540 glTexCoord2f( 0.0f, 0.0f); glVertex3f( g_x0, (float)g_iHeight-75-g_y0, 0.0f);
00541 glTexCoord2f( 1.0f, 0.0f); glVertex3f( (float)g_iWidth-g_x0, (float)g_iHeight-75-g_y0, 0.0f);
00542 glTexCoord2f( 1.0f, 1.0f); glVertex3f( (float)g_iWidth-g_x0, g_y0, 0.0f);
00543 glEnd();
00544
00545 glUniform1i(shSLIterator, -1);
00546 glDisable(GL_BLEND);
00547 }
00548 }
00549
00550 void updateTransferFunction() {
00551 lut[g_iChannel]=tf[g_iChannel]->getTransferFunktionLookUP(lut[g_iChannel]);
00552
00553 glEnable(GL_TEXTURE_1D);
00554 glActiveTexture(GL_TEXTURE2);
00555 glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,4096,0,GL_RGBA,GL_FLOAT,(void *)lut[g_iChannel]);
00556 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00557 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00558 }
00559
00560
00561
00562
00563 void glutDisplay(void)
00564 {
00565 static Timer timTimer;
00566 glClearColor( 200.0f/255.0f, 200.0f/255.0f, 200.0f/255.0f, 1.0f );
00567 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00568 glUniform1i(shSLIterator, -1);
00569
00570
00571 if (numAddChannels >= 0) {
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 updateTransferFunction();
00585
00586 drawChannel();
00587
00588 drawStreamlines();
00589
00590 if (g_iArrows)
00591 drawArrows();
00592
00593
00594
00595 glBegin(GL_QUADS);
00596 glColor4f( 200.0f/255.0f, 200.0f/255.0f, 200.0f/255.0f, 1.0f );
00597 glVertex3f((float)g_iWidth-g_x0,0.0f, 1.0f);
00598 glVertex3f((float)g_iWidth, 0.0f, 1.0f);
00599 glVertex3f((float)g_iWidth, (float)g_iHeight, 1.0f);
00600 glVertex3f((float)g_iWidth-g_x0,(float)g_iHeight, 1.0f);
00601 glVertex3f((float)0.0f, 0.0f, 1.0f);
00602 glVertex3f((float)g_x0, 0.0f, 1.0f);
00603 glVertex3f((float)g_x0, (float)g_iHeight, 1.0f);
00604 glVertex3f((float)0.0f, (float)g_iHeight, 1.0f);
00605 glVertex3f((float)0.0f, 0.0f, 1.0f);
00606 glVertex3f((float)g_iWidth, 0.0f, 1.0f);
00607 glVertex3f((float)g_iWidth, g_y0, 1.0f);
00608 glVertex3f((float)0.0f, g_y0, 1.0f);
00609 glVertex3f((float)0.0f, (float)g_iHeight-75-g_y0, 1.0f);
00610 glVertex3f((float)g_iWidth, (float)g_iHeight-75-g_y0, 1.0f);
00611 glVertex3f((float)g_iWidth, (float)g_iHeight, 1.0f);
00612 glVertex3f((float)0.0f, (float)g_iHeight, 1.0f);
00613 glEnd();
00614
00615
00616 glCallList(tf[g_iChannel]->genderateRenderListBack());
00617 glCallList(tf[g_iChannel]->genderateRenderListFront());
00618
00619
00620 glColor3f(0.0f,0.0f,0.0f);
00621 char vpMessage[16];
00622 int iMessageHeight = glutBitmapHeight(GLUT_BITMAP_HELVETICA_12);
00623 sprintf_s(vpMessage, sizeof(vpMessage), "min");
00624 glRasterPos2f( 10.0f, (float)g_iHeight-9);
00625 glutBitmapString(GLUT_BITMAP_HELVETICA_12,(const unsigned char*)vpMessage);
00626
00627 if (g_iChannel == 0)
00628 sprintf_s(vpMessage, sizeof(vpMessage), "Velocity");
00629 else
00630 sprintf_s(vpMessage, sizeof(vpMessage), "Channel %d", g_iChannel+1);
00631 glRasterPos2f( (float)g_iWidth/2.0-22, (float)g_iHeight-9);
00632 glutBitmapString(GLUT_BITMAP_HELVETICA_12,(const unsigned char*)vpMessage);
00633
00634 sprintf_s(vpMessage, sizeof(vpMessage), "max");
00635 glRasterPos2f( (float)g_iWidth-35, (float)g_iHeight-9);
00636 glutBitmapString(GLUT_BITMAP_HELVETICA_12,(const unsigned char*)vpMessage);
00637 }
00638
00639
00640 if(level)
00641 {
00642 glUseProgram(0);
00643 glActiveTexture(GL_TEXTURE0);
00644 level->setPause(g_iGamePause);
00645 level->clacNextBallPos();
00646 level->drawLevel(g_x0, g_y0, g_iWidth-2.0f*g_x0, g_iHeight-2.0*g_y0-75);
00647 glUseProgram(pH);
00648
00649 }
00650 glBindTexture( GL_TEXTURE_2D, g_uVelocityTex );
00651
00652 glutSwapBuffers();
00653
00654
00655 const double dTimePerFrame = double(timTimer);
00656 dTime+=dTimePerFrame;
00657 const double dFramesPerSecond = dTimePerFrame > 0.0 ? 1.0 / dTimePerFrame : 0.0;
00658 timTimer.start();
00659 printf("- %06.2f frames/second \r",dFramesPerSecond);
00660 if(level) {
00661 level->setFPS(dFramesPerSecond);
00662 if ((int)dTime%10==0) level->speedUp();
00663 }
00664 }
00665
00666
00667 void glutReshape(int width, int height)
00668 {
00669 int tx, ty, tw, th;
00670 GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
00671 glViewport( tx, ty, tw, th );
00672
00673 g_iWidth = tw;
00674 g_iHeight = th;
00675 g_fRatio = (float)tw/((float)th-75);
00676
00677 if (g_fRatio > g_xyRatio)
00678 {
00679 g_fPicHeight = (float)g_iHeight-75.0;
00680 g_fPicWidth = g_xyRatio*g_fPicHeight;
00681 g_x0 = (g_iWidth-g_fPicWidth)/2;
00682 g_y0 = 0.0f;
00683 } else {
00684 g_fPicWidth = (float)g_iWidth;
00685 g_fPicHeight = g_fPicWidth/g_xyRatio;
00686 g_x0 = 0.0f;
00687 g_y0 = ((g_iHeight-75)-g_fPicHeight)/2;
00688 }
00689
00690 glUniform2f(shOriginf2, g_x0, g_y0);
00691 glUniform2f(shSizef2, g_fPicWidth, g_fPicHeight);
00692
00693 glMatrixMode(GL_PROJECTION);
00694 glLoadIdentity();
00695 gluOrtho2D (0, g_iWidth, g_iHeight, 0);
00696
00697 glMatrixMode(GL_MODELVIEW);
00698 glLoadIdentity();
00699
00700 for (int i = 0; i <=numAddChannels; i++) {
00701 tf[i]->reshape(tw,75);
00702 tf[i]->setPosition(0,th-70);
00703 }
00704
00705 if (numAddChannels >= 0 && SLtex) {
00706 drawStreamlineTex(0);
00707 drawStreamlineTex(1);
00708 }
00709
00710 glutPostRedisplay();
00711 }
00712
00713
00714 void glutMouse(int button, int state, int x, int y)
00715 {
00716 if(level && !level->getPause())
00717 {
00718 if(button==0 && state==1) {
00719 level->fireBall();
00720 dTime = 0;
00721 } else if(button==2)
00722 level->setAktiveTraktorRacket(state==0);
00723 }
00724
00725 if(button==0 && numAddChannels >= 0) {
00726 if(state==0) {
00727 tfp=tf[g_iChannel]->getPunkt(x,y, false);
00728 if(tfp==NULL) {
00729 tfp=tf[g_iChannel]->addPunkt(x,y);
00730 }
00731 } else {
00732 tfp=NULL;
00733 }
00734 } else if(button==2 && numAddChannels >= 0) {
00735 if(state==0) {
00736 tfp=tf[g_iChannel]->getPunkt(x,y, true);
00737 if(tfp==NULL) {
00738 tfp=tf[g_iChannel]->addPunkt(x,y);
00739 }
00740 } else {
00741 tf[g_iChannel]->setColor(x,y);
00742 tfp=NULL;
00743 }
00744 }
00745 }
00746
00747
00748 void glutMouseWheel(int w, int d, int x, int y)
00749 {
00750
00751 }
00752
00753
00754 void glutMotion(int x, int y)
00755 {
00756 if(level)
00757 {
00758 level->setRacketXPos((float)x/g_iWidth);
00759 }
00760
00761 if(tfp !=NULL)
00762 {
00763 tfp=tf[g_iChannel]->updatePunkt(tfp,x,y);
00764 }
00765 }
00766
00767
00768 void glutKeyboard(unsigned char key, int x, int y)
00769 {
00770 key = tolower(key);
00771 switch (key) {
00772 case 's':
00773 break;
00774 case 'r':
00775 if(level)level->restart();
00776 break;
00777 case 'p':
00778 if(level)
00779 {
00780 g_iGamePause=!g_iGamePause;
00781 level->setPause(g_iGamePause);
00782 GLUI_Master.sync_live_all();
00783 }
00784 break;
00785 case VK_ESCAPE:
00786 glutDestroyWindow(g_iWindow);
00787 break;
00788 }
00789 }
00790
00791
00792 void glutClose()
00793 {
00794 GLUI_Master.close_all();
00795
00796
00797 }
00798
00799 void recalcStreamData()
00800 {
00801 delete streamlineSeeds;
00802 streamlineSeeds = new float[g_iSeeds*g_iSteps*2];
00803
00804 delete streamlineSeedsRK;
00805 streamlineSeedsRK = new float[g_iSeeds*g_iSteps*2];
00806
00807 for(int j=0; j<g_iSeeds*2;j+=2)
00808 {
00809 float x= ((float)j)/(g_iSeeds*2);
00810 float y= ((float)j)/(g_iSeeds*2);
00811 float xprc= Xchan->getValue(x);
00812 float yprc= Ychan->getValue(y);
00813
00814 xprc=Xchan->normalizeValue(xprc);
00815 yprc=Ychan->normalizeValue(yprc);
00816
00817 streamlineSeeds[j] = xprc;
00818 streamlineSeeds[j+1]= yprc;
00819
00820 streamlineSeedsRK[j] = xprc;
00821 streamlineSeedsRK[j+1] = yprc;
00822 }
00823
00824 for(int i=1;i<g_iSteps;i++)
00825 {
00826 for(int j=0;j<g_iSeeds*2;j+=2)
00827 {
00828 float x=streamlineSeeds[(i-1)*g_iSeeds*2+j];
00829 float y=streamlineSeeds[(i-1)*g_iSeeds*2+j+1];
00830
00831 if( x<=0|| x>=1 ||y<=0||y>=1)
00832 {
00833 streamlineSeeds[i*g_iSeeds*2+j]=-1;
00834 streamlineSeeds[i*g_iSeeds*2+j+1]=-1;
00835 }
00836 else
00837 {
00838 streamlineSeeds[i*g_iSeeds*2+j] =streamlineSeeds[(i-1)*g_iSeeds*2+j]+g_iStepsize*Xvelos->getValueNormPos(x,y);
00839 streamlineSeeds[i*g_iSeeds*2+j+1] =streamlineSeeds[(i-1)*g_iSeeds*2+j+1]+g_iStepsize*Yvelos->getValueNormPos(x,y);
00840 }
00841 }
00842 }
00843
00844 for(int i=1;i<g_iSteps;i++)
00845 {
00846 for(int j=0;j<g_iSeeds*2;j+=2)
00847 {
00848 float x=streamlineSeedsRK[(i-1)*g_iSeeds*2+j];
00849 float y=streamlineSeedsRK[(i-1)*g_iSeeds*2+j+1];
00850
00851 if( x<=0|| x>=1 ||y<=0||y>=1)
00852 {
00853 streamlineSeedsRK[i*g_iSeeds*2+j]=-1;
00854 streamlineSeedsRK[i*g_iSeeds*2+j+1]=-1;
00855 }
00856 else
00857 {
00858 float Zx= streamlineSeedsRK[(i-1)*g_iSeeds*2+j] + g_iStepsize*Xvelos->getValueNormPos(x,y)/2;
00859 float Zy= streamlineSeedsRK[(i-1)*g_iSeeds*2+j+1]+ g_iStepsize*Yvelos->getValueNormPos(x,y)/2;
00860
00861 if( Zx<=0|| Zx>=1 ||Zy<=0||Zy>=1)
00862 {
00863 streamlineSeedsRK[i*g_iSeeds*2+j]=-1;
00864 streamlineSeedsRK[i*g_iSeeds*2+j+1]=-1;
00865 }
00866 else
00867 {
00868 streamlineSeedsRK[i*g_iSeeds*2+j] = streamlineSeedsRK[(i-1)*g_iSeeds*2+j] + g_iStepsize*Xvelos->getValueNormPos(Zx,Zy);
00869 streamlineSeedsRK[i*g_iSeeds*2+j+1]= streamlineSeedsRK[(i-1)*g_iSeeds*2+j+1]+ g_iStepsize*Yvelos->getValueNormPos(Zx,Zy);
00870 }
00871 }
00872 }
00873 }
00874 }
00875
00876 void recalcStreamData2()
00877 {
00878 int numX = (int) ceil(g_fPicWidth/(float)g_iArrowDist);
00879 int numY = (int) ceil(g_fPicHeight/(float)g_iArrowDist);
00880
00881 delete streamlineSeeds;
00882 streamlineSeeds = new float[numX*numY*g_iSteps*2+10*numX*numY];
00883
00884 delete streamlineSeedsRK;
00885 streamlineSeedsRK = new float[numX*numY*g_iSteps*2+10*numX*numY];
00886
00887 for (int j = 0; j<numY; j++)
00888 for (int i = 0; i<numX; i++) {
00889 streamlineSeeds[j*numX*2+i*2]=(i*g_iArrowDist+((float)rand()/RAND_MAX-0.5f)*g_iArrowDist)/g_fPicWidth;
00890 streamlineSeeds[j*numX*2+i*2+1]=(j*g_iArrowDist+((float)rand()/RAND_MAX-0.5f)*g_iArrowDist)/g_fPicHeight;
00891
00892 streamlineSeedsRK[j*numX*2+i*2]=(i*g_iArrowDist+((float)rand()/RAND_MAX-0.5f)*g_iArrowDist)/g_fPicWidth;
00893 streamlineSeedsRK[j*numX*2+i*2+1]=(j*g_iArrowDist+((float)rand()/RAND_MAX-0.5f)*g_iArrowDist)/g_fPicHeight;
00894 }
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914 for(int i=1;i<g_iSteps;i++)
00915 {
00916 for(int j=0;j<numX*numY*2;j+=2)
00917 {
00918 float x=streamlineSeeds[(i-1)*numX*numY*2+j];
00919 float y=streamlineSeeds[(i-1)*numX*numY*2+j+1];
00920
00921 if( x<=0|| x>=1 ||y<=0||y>=1)
00922 {
00923 streamlineSeeds[i*numX*numY*2+j]=-1;
00924 streamlineSeeds[i*numX*numY*2+j+1]=-1;
00925 }
00926 else
00927 {
00928 streamlineSeeds[i*numX*numY*2+j] =streamlineSeeds[(i-1)*numX*numY*2+j]+g_iStepsize*Xvelos->getValueNormPos(x,y)/dataset->getChannel(7)->getValueNormPos(x,y)/g_xyRatio;
00929 streamlineSeeds[i*numX*numY*2+j+1] =streamlineSeeds[(i-1)*numX*numY*2+j+1]+g_iStepsize*Yvelos->getValueNormPos(x,y)/dataset->getChannel(7)->getValueNormPos(x,y);
00930 }
00931 }
00932 }
00933
00934 for(int i=1;i<g_iSteps;i++)
00935 {
00936 for(int j=0;j<numX*numY*2;j+=2)
00937 {
00938 float x=streamlineSeedsRK[(i-1)*numX*numY*2+j];
00939 float y=streamlineSeedsRK[(i-1)*numX*numY*2+j+1];
00940
00941 if( x<=0|| x>=1 ||y<=0||y>=1)
00942 {
00943 streamlineSeedsRK[i*numX*numY*2+j]=-1;
00944 streamlineSeedsRK[i*numX*numY*2+j+1]=-1;
00945 }
00946 else
00947 {
00948 float Zx= streamlineSeedsRK[(i-1)*numX*numY*2+j] + g_iStepsize*Xvelos->getValueNormPos(x,y)/dataset->getChannel(7)->getValueNormPos(x,y)/g_xyRatio/2;
00949 float Zy= streamlineSeedsRK[(i-1)*numX*numY*2+j+1]+ g_iStepsize*Yvelos->getValueNormPos(x,y)/dataset->getChannel(7)->getValueNormPos(x,y)/2;
00950
00951 if( Zx<=0|| Zx>=1 ||Zy<=0||Zy>=1)
00952 {
00953 streamlineSeedsRK[i*numX*numY*2+j]=-1;
00954 streamlineSeedsRK[i*numX*numY*2+j+1]=-1;
00955 }
00956 else
00957 {
00958 streamlineSeedsRK[i*numX*numY*2+j] = streamlineSeedsRK[(i-1)*numX*numY*2+j] + g_iStepsize*Xvelos->getValueNormPos(Zx,Zy)/dataset->getChannel(7)->getValueNormPos(x,y)/g_xyRatio;
00959 streamlineSeedsRK[i*numX*numY*2+j+1]= streamlineSeedsRK[(i-1)*numX*numY*2+j+1]+ g_iStepsize*Yvelos->getValueNormPos(Zx,Zy)/dataset->getChannel(7)->getValueNormPos(x,y);
00960 }
00961 }
00962 }
00963 }
00964 }
00965
00966 void GLUIcontrol( int control ) {
00967 switch (control) {
00968 case 0:
00969 GLUI_Master.sync_live_all();
00970 break;
00971 case 1:
00972 glutDestroyWindow(g_iWindow);
00973 break;
00974 case 2:
00975 {
00976 unsigned int uImage = 0;
00977 std::vector<unsigned char> vecImage;
00978
00979 char vcFilename[1024];
00980
00981
00982 for (int i=0;i<9999;i++)
00983 {
00984 sprintf_s(vcFilename,1024,"FlowVis%04d.png",i);
00985
00986
00987 if( (_access(vcFilename,0)) == -1 )
00988 break;
00989 }
00990
00991 std::cout << "- Saving screenshot to '" << vcFilename << "' ..." << std::endl;
00992
00993 vecImage.resize(g_iWidth*g_iHeight*4);
00994
00995
00996 glPushAttrib(GL_PIXEL_MODE_BIT);
00997 glReadBuffer(GL_FRONT);
00998 GLenum glError = glGetError();
00999 glReadPixels(0,-g_iHeight+g_iHeight,g_iWidth,g_iHeight,GL_RGBA,GL_UNSIGNED_BYTE,(void*) &(vecImage.front()) );
01000 glError = glGetError();
01001 glPopAttrib();
01002
01003 if (glError != GL_NO_ERROR)
01004 {
01005 std::cerr<<"Unable to read frame buffer "<<gluErrorString(glError)<<std::endl;
01006 }
01007 else
01008 {
01009 ilGenImages(1, &uImage);
01010
01011 if (ilGetError() != IL_NO_ERROR)
01012 {
01013 std::cerr<<"Unable to create image"<<std::endl;
01014 }
01015 else
01016 {
01017 ilBindImage(uImage);
01018
01019 if (ilGetError() != IL_NO_ERROR)
01020 {
01021 std::cerr<<"Unable to bind image"<<std::endl;
01022 }
01023 else
01024 {
01025 ilTexImage(g_iWidth,g_iHeight,1,4,IL_RGBA,IL_UNSIGNED_BYTE,(void*) &(vecImage.front()) );
01026
01027 if (ilGetError() != IL_NO_ERROR)
01028 {
01029 std::cerr<<"Unable to store image"<<std::endl;
01030 }
01031 else
01032 {
01033
01034 ilSaveImage(vcFilename);
01035
01036 if (ilGetError() != IL_NO_ERROR)
01037 {
01038 std::cerr<<"Unable to save image"<<std::endl;
01039 }
01040 else
01041 {
01042 std::cout << "- Screenshot saved." << std::endl;
01043 }
01044 }
01045 }
01046 }
01047 }
01048 if (uImage)
01049 {
01050 ilBindImage(0);
01051 ilDeleteImages(1,&uImage);
01052 }
01053 break;
01054 }
01055 case 3:
01056 if (numAddChannels >= 0)
01057 updateStreamlines();
01058 GLUI_Master.sync_live_all();
01059 break;
01060 default:
01061 return;
01062 }
01063 }
01064
01065 char * loadFile(char * fileName){
01066 long size;
01067 char * data;
01068 FILE* f;
01069 fopen_s(&f,fileName, "rb");
01070 if (f == NULL){
01071 std::cout<<"Cannot load "<<fileName<<std::endl;
01072 return NULL;
01073 }
01074 fseek(f, 0, SEEK_END);
01075 size = ftell(f);
01076 rewind(f);
01077 data = new char[size+1];
01078 fread (data, 1, size, f);
01079 data[size] = '\0';
01080 fclose(f);
01081 return data;
01082 }
01083
01084 void openFile( int control ) {
01085 OPENFILENAME ofn;
01086 char szFile[260];
01087 char szFileTitle[128];
01088
01089 szFile[0] = '\0';
01090 szFileTitle[0] = '\0';
01091
01092
01093 ZeroMemory(&ofn, sizeof(OPENFILENAME));
01094 ofn.lStructSize = sizeof(OPENFILENAME);
01095 ofn.hwndOwner = g_hWindow;
01096 ofn.lpstrFile = szFile;
01097 ofn.lpstrFile[0] = '\0';
01098 ofn.nMaxFile = sizeof(szFile);
01099 ofn.lpstrFilter = "Data\0*.GRI\0All\0*.*\0";
01100 ofn.nFilterIndex = 1;
01101 ofn.lpstrFileTitle = szFileTitle;
01102 ofn.nMaxFileTitle = sizeof(szFileTitle);
01103 ofn.lpstrInitialDir = NULL;
01104 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
01105
01106 if (GetOpenFileName(&ofn)==TRUE) {
01107
01108 std::string fileName = ofn.lpstrFile;
01109 fileName.erase(fileName.length()-4,4);
01110 std::cout << fileName << std::endl;
01111 dataset = new FlowData();
01112 bool result = dataset->loadDataset(fileName,false);
01113
01114
01115 if (!result) {system("PAUSE"); return;}
01116
01117
01118 chX = dataset->createChannelGeometry(0);
01119 chY = dataset->createChannelGeometry(1);
01120 g_xyRatio=dataset->getChannel(chX)->getRange()/dataset->getChannel(chY)->getRange();
01121
01122
01123 vel = dataset->createChannelVectorLength(0,1,2);
01124
01125 Xchan=dataset->getChannel(chX);
01126 Ychan=dataset->getChannel(chY);
01127 Xvelos=dataset->getChannel(0);
01128 Yvelos=dataset->getChannel(1);
01129
01130 if (!channelList->enabled) {
01131 channelList->enable();
01132 channelList->add_item(0, "Velocity");
01133 }
01134 for (int i=1; i<=numAddChannels; i++)
01135 channelList->delete_item(i);
01136
01137 numAddChannels = dataset->getNumAddChannels();
01138
01139 char vpMessage[128];
01140 for (int i=1; i<=numAddChannels; i++) {
01141 sprintf_s(vpMessage, sizeof(vpMessage), "Channel %d", i+1);
01142 channelList->add_item(i, vpMessage);
01143 }
01144
01145 if (numAddChannels > MAXADDCHANNELS) std::cout << "- Only the first 3 additional channels are accessible" << std::endl;
01146
01147 float rangeVel = dataset->getChannel(vel)->getRange();
01148 float minVel = dataset->getChannel(vel)->getMin();
01149
01150 float* velTex = new float[rangeX*rangeY*3];
01151 float* valueTex = new float[rangeX*rangeY*3];
01152 float minVal[MAXADDCHANNELS];
01153 float rangeVal[MAXADDCHANNELS];
01154
01155 for (int k = 0; k<numAddChannels && k<MAXADDCHANNELS; k++) {
01156 minVal[k] = dataset->getChannel(k+3)->getMin();
01157 rangeVal[k] = dataset->getChannel(k+3)->getRange();
01158 }
01159
01160 for(int i = 0; i<rangeY; i++) {
01161 for(int j = 0; j<rangeX*3; j+=3) {
01162 valueTex[i*rangeX*3+j] = dataset->getChannel(vel)->getValueNormPos(((float)j)/(rangeX*3.0f),((float)i)/rangeY);
01163 if (valueTex[i*rangeX*3+j] > 0.0f) {
01164 velTex[i*rangeX*3+j] = dataset->getChannel(0)->getValueNormPos(((float)j)/(rangeX*3.0f),((float)i)/rangeY)/valueTex[i*rangeX*3+j];
01165 velTex[i*rangeX*3+j+1] = dataset->getChannel(1)->getValueNormPos(((float)j)/(rangeX*3.0f),((float)i)/rangeY)/valueTex[i*rangeX*3+j];
01166 velTex[i*rangeX*3+j+2] = 1.0f;
01167 } else {
01168 velTex[i*rangeX*3+j] = 0.0f;
01169 velTex[i*rangeX*3+j+1] = 0.0f;
01170 velTex[i*rangeX*3+j+2] = 0.0f;
01171 }
01172
01173 velTex[i*rangeX*3+j]*=0.5f;
01174 velTex[i*rangeX*3+j+1]*=0.5f;
01175 velTex[i*rangeX*3+j]+=0.5f;
01176 velTex[i*rangeX*3+j+1]+=0.5f;
01177
01178 for(int k = 0; k<numAddChannels && k<MAXADDCHANNELS; k++) {
01179 valueTex[i*rangeX*3+j+(k+1)] = (dataset->getChannel(k+3)->getValueNormPos(((float)j)/(rangeX*3.0f),((float)i)/rangeY)-minVal[k])/rangeVal[k];
01180 }
01181
01182 valueTex[i*rangeX*3+j] -= minVel;
01183 valueTex[i*rangeX*3+j] /= rangeVel;
01184 }
01185 }
01186
01187
01188
01190 glEnable(GL_TEXTURE_2D);
01191 glActiveTexture(GL_TEXTURE0);
01192
01193 glBindTexture( GL_TEXTURE_2D, g_uVelocityTex );
01194 glTexImage2D(GL_TEXTURE_2D,0,0x881B,rangeX,rangeY,0,GL_RGB,GL_FLOAT,(void *)velTex);
01195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01197
01198 glActiveTexture(GL_TEXTURE1);
01199
01200 glBindTexture( GL_TEXTURE_2D, g_uValueTex );
01201 glTexImage2D(GL_TEXTURE_2D,0,0x881B,rangeX,rangeY,0,GL_RGB,GL_FLOAT,(void *)valueTex);
01202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01204 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
01205 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
01206
01207 glActiveTexture(GL_TEXTURE0);
01208
01209 sprintf_s(vpMessage, sizeof(vpMessage), "Flow Visualisation - %s", ofn.lpstrFileTitle);
01210 SetWindowText(g_hWindow, vpMessage);
01211
01212 for (int i = 0; i<=numAddChannels; i++)
01213 tf[i] = new TransferFunktion();
01214
01215 g_iStepsize= 0.01;
01216 g_iSeeds= 900;
01217 g_iSteps= 10;
01218 GLUI_Master.sync_live_all();
01219 glutReshape(0,0);
01220 updateStreamlines();
01221
01222
01223
01224
01225 level = new GameLevel(dataset->getChannel(chX)->getRange(),dataset->getChannel(chY)->getRange());
01226 level->setVelosityFlowChannels(Xvelos,Yvelos,dataset->getChannel(7));
01227 level->setTextures(g_uBallTex,g_uWallTex,g_uRacketTex,g_uBrickTex,g_uOverTex,g_uWinTex);
01228 }
01229 }
01230
01231 void loadSaveTransferfunktion( int control ) {
01232 if (numAddChannels < 0) return;
01233
01234 OPENFILENAME ofn;
01235 char szFile[260];
01236
01237 szFile[0] = '\0';
01238
01239
01240 ZeroMemory(&ofn, sizeof(OPENFILENAME));
01241 ofn.lStructSize = sizeof(OPENFILENAME);
01242 ofn.hwndOwner = g_hWindow;
01243 ofn.lpstrFile = szFile;
01244 ofn.lpstrFile[0] = '\0';
01245 ofn.nMaxFile = sizeof(szFile);
01246 ofn.lpstrFilter = "Transferfunction\0*.tff\0All\0*.*\0";
01247 ofn.nFilterIndex = 1;
01248 ofn.lpstrFileTitle = NULL;
01249 ofn.nMaxFileTitle = 0;
01250 ofn.lpstrInitialDir = NULL;
01251 std::string fileName;
01252 if(control==0)
01253 {
01254 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
01255 if (GetOpenFileName(&ofn)==TRUE) {
01256 fileName = ofn.lpstrFile;
01257 tf[g_iChannel]->loadPunkte(fileName);
01258 }
01259 }
01260 else
01261 {
01262 ofn.Flags =OFN_OVERWRITEPROMPT;
01263 if (GetSaveFileName(&ofn)==TRUE) {
01264 fileName = ofn.lpstrFile;
01265 if(ofn.nFileExtension==0)
01266 {
01267 fileName+=".tff";
01268 }
01269 tf[g_iChannel]->savePunkte(fileName);
01270 }
01271 }
01272
01273 }
01274
01275 void initGLUI() {
01276 std::cout << "- Initialising GLUI ..." << std::endl;
01277 GLUI *glui_subwin = GLUI_Master.create_glui_subwindow(g_iWindow,
01278 GLUI_SUBWINDOW_RIGHT );
01279
01280 GLUI_Panel* colorPanel = new GLUI_Panel( glui_subwin, "Color coding", GLUI_PANEL_EMBOSSED );
01281 channelList = new GLUI_Listbox( colorPanel, "Channel ", &g_iChannel, GLUI_SYNC, GLUIcontrol);
01282 channelList->disable();
01283
01284 new GLUI_Separator( colorPanel );
01285
01286 new GLUI_Button( colorPanel, "Load Transferfunction", 0, loadSaveTransferfunktion);
01287 new GLUI_Button( colorPanel, "Save Transferfunction", 1, loadSaveTransferfunktion);
01288
01289
01290 GLUI_Panel* arrowPanel = new GLUI_Panel( glui_subwin, "Arrow plotting", GLUI_PANEL_EMBOSSED );
01291 new GLUI_Checkbox(arrowPanel, "Enable arrow plotting", &g_iArrows, GLUI_SYNC, GLUIcontrol);
01292 GLUI_Scrollbar* scrollDistance = new GLUI_Scrollbar( arrowPanel, "Interval",GLUI_SCROLL_HORIZONTAL, &g_iArrowDist, GLUI_SYNC, GLUIcontrol);
01293 scrollDistance->set_int_limits(1,200);
01294 scrollDistance->set_int_val(g_iArrowDist);
01295 GLUI_Spinner* spinDistance = new GLUI_Spinner( arrowPanel, "Interval",GLUI_SPINNER_INT, &g_iArrowDist, GLUI_SYNC, GLUIcontrol);
01296 spinDistance->set_int_limits(1,200);
01297 spinDistance->set_int_val(g_iArrowDist);
01298 GLUI_Scrollbar* scrollSize = new GLUI_Scrollbar( arrowPanel, "Size",GLUI_SCROLL_HORIZONTAL, &g_iArrowSize, GLUI_SYNC, GLUIcontrol);
01299 scrollSize->set_int_limits(1,40);
01300 scrollSize->set_int_val(g_iArrowSize);
01301 GLUI_Spinner* spinSize = new GLUI_Spinner( arrowPanel, "Size",GLUI_SPINNER_INT, &g_iArrowSize, GLUI_SYNC, GLUIcontrol);
01302 spinSize->set_int_limits(1,40);
01303 spinSize->set_int_val(g_iArrowSize);
01304 new GLUI_Checkbox(arrowPanel, "Scale with velocity", &g_iArrowScaling, GLUI_SYNC, GLUIcontrol);
01305
01306 GLUI_Panel *streamLines = new GLUI_Panel( glui_subwin, "StreamLines",GLUI_PANEL_EMBOSSED );
01307
01308 GLUI_Spinner* g_pGLUI_SpinLines = new GLUI_Spinner( streamLines, "Lines",&g_iSeeds, STREAMLINEMOD, GLUIcontrol);
01309 g_pGLUI_SpinLines->set_alignment(GLUI_ALIGN_CENTER);
01310 g_pGLUI_SpinLines->set_int_limits(10,4096);
01311 g_pGLUI_SpinLines->set_int_val(50);
01312
01313 GLUI_Spinner* g_pGLUI_SpinStepCount = new GLUI_Spinner( streamLines, "Steps",&g_iSteps, STREAMLINEMOD, GLUIcontrol);
01314 g_pGLUI_SpinStepCount->set_alignment(GLUI_ALIGN_CENTER);
01315 g_pGLUI_SpinStepCount->set_int_limits(2,4096);
01316 g_pGLUI_SpinStepCount->set_int_val(200);
01317
01318 GLUI_Spinner* g_pGLUI_SpinStepSize = new GLUI_Spinner( streamLines, "Stepsize",&g_iStepsize, STREAMLINEMOD, GLUIcontrol);
01319 g_pGLUI_SpinStepSize->set_alignment(GLUI_ALIGN_CENTER);
01320 g_pGLUI_SpinStepSize->set_float_limits(0.0001,1);
01321 g_pGLUI_SpinStepSize->set_float_val(0.01);
01322
01323 new GLUI_Checkbox(streamLines,"Euler",&g_iEuler);
01324 new GLUI_Checkbox(streamLines,"Runge-Kutta",&g_iRungeKutta);
01325 new GLUI_Checkbox(streamLines, "Weighted Streamlines", &g_iWeightedSL, STREAMLINEMOD, GLUIcontrol);
01326
01327 new GLUI_Button( glui_subwin, "Open...", 0, openFile);
01328 new GLUI_Button( glui_subwin, "Screenshot", GLUI_PIC, GLUIcontrol);
01329 new GLUI_Button( glui_subwin, "Exit", GLUI_EXIT, GLUIcontrol);
01330
01331 GLUI_Panel *game = new GLUI_Panel( glui_subwin, "Game",GLUI_PANEL_EMBOSSED );
01332 new GLUI_Checkbox(game,"Pause",&g_iGamePause);
01333
01334
01335 glui_subwin->set_main_gfx_window( g_iWindow );
01336 }
01337
01338 void initTextures() {
01339 glEnable(GL_TEXTURE_2D);
01340
01341 glActiveTexture(GL_TEXTURE0);
01342
01343 glGenTextures( 1, &g_uVelocityTex );
01344 glBindTexture( GL_TEXTURE_2D, g_uVelocityTex );
01345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01347
01348 glActiveTexture(GL_TEXTURE1);
01349
01350 glGenTextures( 1, &g_uValueTex );
01351 glBindTexture( GL_TEXTURE_2D, g_uValueTex );
01352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01354
01355 glActiveTexture(GL_TEXTURE2);
01356
01357 glGenTextures(1, &g_uTFTex);
01358 glBindTexture(GL_TEXTURE_1D,g_uTFTex);
01359
01360
01361 ILuint image;
01362 ILuint width, height;
01363 BYTE* data;
01364
01365
01366 glActiveTexture(GL_TEXTURE3);
01367
01368 ilGenImages(1, &image);
01369 ilBindImage(image);
01370 ilLoadImage("arrow.png");
01371
01372 width = ilGetInteger(IL_IMAGE_WIDTH);
01373 height = ilGetInteger(IL_IMAGE_HEIGHT);
01374 data = new BYTE[width * height * 4];
01375 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01376 IL_UNSIGNED_BYTE, data);
01377
01378 glGenTextures( 1, &g_uArrowTex );
01379 glBindTexture( GL_TEXTURE_2D, g_uArrowTex );
01380 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
01384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
01385
01386
01387 glActiveTexture(GL_TEXTURE5);
01388
01389 ilGenImages(1, &image);
01390 ilBindImage(image);
01391 ilLoadImage("ball.png");
01392
01393 width = ilGetInteger(IL_IMAGE_WIDTH);
01394 height = ilGetInteger(IL_IMAGE_HEIGHT);
01395 data = new BYTE[width * height * 4];
01396 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01397 IL_UNSIGNED_BYTE, data);
01398
01399 glGenTextures( 1, &g_uBallTex );
01400 glBindTexture( GL_TEXTURE_2D, g_uBallTex );
01401 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
01405 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01406
01407
01408 glActiveTexture(GL_TEXTURE6);
01409
01410 ilGenImages(1, &image);
01411 ilBindImage(image);
01412 ilLoadImage("wall.png");
01413
01414 width = ilGetInteger(IL_IMAGE_WIDTH);
01415 height = ilGetInteger(IL_IMAGE_HEIGHT);
01416 data = new BYTE[width * height * 4];
01417 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01418 IL_UNSIGNED_BYTE, data);
01419
01420 glGenTextures( 1, &g_uWallTex );
01421 glBindTexture( GL_TEXTURE_2D, g_uWallTex );
01422 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01423 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01424 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01425 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
01426 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01427
01428
01429 glActiveTexture(GL_TEXTURE7);
01430
01431 ilGenImages(1, &image);
01432 ilBindImage(image);
01433 ilLoadImage("brick.png");
01434
01435 width = ilGetInteger(IL_IMAGE_WIDTH);
01436 height = ilGetInteger(IL_IMAGE_HEIGHT);
01437 data = new BYTE[width * height * 4];
01438 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01439 IL_UNSIGNED_BYTE, data);
01440
01441 glGenTextures( 1, &g_uBrickTex );
01442 glBindTexture( GL_TEXTURE_2D, g_uBrickTex );
01443 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
01447 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01448
01449
01450 glActiveTexture(GL_TEXTURE8);
01451
01452 ilGenImages(1, &image);
01453 ilBindImage(image);
01454 ilLoadImage("racket.png");
01455
01456 width = ilGetInteger(IL_IMAGE_WIDTH);
01457 height = ilGetInteger(IL_IMAGE_HEIGHT);
01458 data = new BYTE[width * height * 4];
01459 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01460 IL_UNSIGNED_BYTE, data);
01461
01462 glGenTextures( 1, &g_uRacketTex );
01463 glBindTexture( GL_TEXTURE_2D, g_uRacketTex );
01464 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01465 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01466 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
01468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01469
01470
01471 glActiveTexture(GL_TEXTURE9);
01472
01473 ilGenImages(1, &image);
01474 ilBindImage(image);
01475 ilLoadImage("gameOver.png");
01476
01477 width = ilGetInteger(IL_IMAGE_WIDTH);
01478 height = ilGetInteger(IL_IMAGE_HEIGHT);
01479 data = new BYTE[width * height * 4];
01480 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01481 IL_UNSIGNED_BYTE, data);
01482
01483 glGenTextures( 1, &g_uOverTex );
01484 glBindTexture( GL_TEXTURE_2D, g_uOverTex );
01485 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
01489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01490
01491
01492 glActiveTexture(GL_TEXTURE10);
01493
01494 ilGenImages(1, &image);
01495 ilBindImage(image);
01496 ilLoadImage("winMessage.png");
01497
01498 width = ilGetInteger(IL_IMAGE_WIDTH);
01499 height = ilGetInteger(IL_IMAGE_HEIGHT);
01500 data = new BYTE[width * height * 4];
01501 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA,
01502 IL_UNSIGNED_BYTE, data);
01503
01504 glGenTextures( 1, &g_uWinTex );
01505 glBindTexture( GL_TEXTURE_2D, g_uWinTex );
01506 glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,(void *)data);
01507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
01508 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
01509 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
01510 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01511
01512
01513 glActiveTexture(GL_TEXTURE4);
01514 glGenTextures( 4, g_uStreamlineTex );
01515
01516 glGenFramebuffersEXT(2, g_uStreamlineFBO);
01517 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
01518
01519 }
01520
01521 void initShaders() {
01522 vertexShader = loadFile("vertex.sh");
01523 fragmentShader = loadFile("fragment.sh");
01524 int fSH = glCreateShader(GL_FRAGMENT_SHADER);
01525 glShaderSource(fSH, 1, (const GLchar **) &fragmentShader, NULL);
01526 glCompileShader(fSH);
01527
01528
01529
01530 int vSH = glCreateShader(GL_VERTEX_SHADER);
01531 glShaderSource(vSH, 1, (const GLchar **) &vertexShader, NULL);
01532 glCompileShader(vSH);
01533
01534 delete[] vertexShader;
01535 delete[] fragmentShader;
01536
01537 pH = glCreateProgram();
01538 glAttachShader(pH, fSH);
01539 glAttachShader(pH, vSH);
01540 glLinkProgram(pH);
01541
01542 GLchar * error = new GLchar[2001];
01543 GLsizei len;
01544 glGetProgramInfoLog(pH, 2000, &len, error);
01545 std::cout<<"."<<error<<std::endl;
01546 delete[] error;
01547
01548 glUseProgram(pH);
01549
01550 GLint shVelocityTex = glGetUniformLocation(pH, "velocityTex");
01551 glUniform1i(shVelocityTex, 0);
01552 GLint shValueTex = glGetUniformLocation(pH, "valueTex");
01553 glUniform1i(shValueTex, 1);
01554 GLint shTFTex = glGetUniformLocation(pH, "TFTex");
01555 glUniform1i(shTFTex, 2);
01556 GLint shArrowTex = glGetUniformLocation(pH, "arrowTex");
01557 glUniform1i(shArrowTex, 3);
01558 GLint shSLTex = glGetUniformLocation(pH, "SLTex");
01559 glUniform1i(shSLTex, 4);
01560
01561 shUseTF = glGetUniformLocation(pH, "useTF");
01562 shDrawArrows = glGetUniformLocation(pH, "drawArrows");
01563 shArrowSize = glGetUniformLocation(pH, "arrowSize");
01564 shArrowScaling = glGetUniformLocation(pH, "sizeScaling");
01565 shOriginf2 = glGetUniformLocation(pH, "origin");
01566 shSizef2 = glGetUniformLocation(pH, "size");
01567 shChannel = glGetUniformLocation(pH, "channelNr");
01568 shSLIterator = glGetUniformLocation(pH, "iterator");
01569 shSLStepsize = glGetUniformLocation(pH, "stepsize");
01570 shSLxPix = glGetUniformLocation(pH, "xPix");
01571 shSLyPix = glGetUniformLocation(pH, "yPix");
01572 shPicRatio = glGetUniformLocation(pH, "xyRatio");
01573 shIntegration = glGetUniformLocation(pH, "integration");
01574 }
01575
01576 int main(int argc, char** argv)
01577 {
01578
01579 std::cout << "- Initialising GLUT ..." << std::endl;
01580 glutInit (&argc, argv);
01581 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
01582 glutInitWindowSize (g_iWidth,g_iHeight);
01583 glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
01584
01585 g_iWindow = glutCreateWindow("Flow Visualisation");
01586 g_hWindow = FindWindowA(0, "Flow Visualisation");
01587
01588 glClearColor( 200.0f/255.0f, 200.0f/255.0f, 200.0f/255.0f, 1.0f );
01589 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01590
01591
01592
01593 GLUI_Master.auto_set_viewport();
01594
01595 glMatrixMode(GL_PROJECTION);
01596 glLoadIdentity();
01597 gluOrtho2D (0, g_iWidth, g_iHeight, 0);
01598
01599 glMatrixMode(GL_MODELVIEW);
01600 glLoadIdentity();
01601
01602
01603 initGLUI();
01604
01605
01606 GLUI_Master.set_glutIdleFunc(glutIdle);
01607 glutDisplayFunc (glutDisplay);
01608 GLUI_Master.set_glutReshapeFunc(glutReshape);
01609 GLUI_Master.set_glutMouseFunc(glutMouse);
01610 glutMouseWheelFunc(glutMouseWheel);
01611 glutMotionFunc (glutMotion);
01612 glutPassiveMotionFunc(glutMotion);
01613 GLUI_Master.set_glutKeyboardFunc(glutKeyboard);
01614 glutCloseFunc(glutClose);
01615
01616 std::cout << "- GLUI initialised." << std::endl;
01617 std::cout << "- GLUT initialised." << std::endl << std::endl;
01618
01619
01620 std::cout << "- Initialising GLEW ..." << std::endl;
01621 GLenum err = glewInit();
01622 if (err != GLEW_OK)
01623 {
01624
01625 std::cerr << "Error initialising GLEW: " << glewGetErrorString(err) << std::endl;
01626 return EXIT_FAILURE;
01627 }
01628 std::cout << "- GLEW initialised." << std::endl << std::endl;
01629
01630
01631 std::cout << "- Initialising DevIL ..." << std::endl;
01632 ilInit();
01633 if (ilGetError() != IL_NO_ERROR)
01634 {
01635 std::cerr << "Error initialising DevIL" << std::endl;
01636 return EXIT_FAILURE;
01637 }
01638 ilEnable(IL_ORIGIN_SET);
01639 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
01640 std::cout << "- DevIL initialised." << std::endl << std::endl;
01641
01642
01643 int tx, ty, tw, th;
01644 GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
01645 glViewport( tx, ty, tw, th );
01646 g_iWidth = tw;
01647 g_iHeight = th;
01648
01649 GLUI_Master.sync_live_all();
01650
01652 initTextures();
01653
01654
01656 initShaders();
01657
01658
01659
01660 glutMainLoop();
01661
01662 std::cout << "- Main loop terminated." << std::endl << std::endl;
01663
01664 return EXIT_SUCCESS;
01665 }
01666