Commit e1700dd03360641a7dce685886ffdfa85e44f4c3
1 parent
19ec4731
fixed bugs when introducing lighting
Showing
1 changed file
with
74 additions
and
47 deletions
Show diff stats
main.cu
... | ... | @@ -74,6 +74,7 @@ float delta; |
74 | 74 | float sigma = 3; //default sigma |
75 | 75 | float radius = 3; //equals to radius |
76 | 76 | int adjoint_fac = 0; |
77 | +int light_fac = 0; | |
77 | 78 | |
78 | 79 | //sets an OpenGL viewport taking up the entire window |
79 | 80 | void glut_render_single_projection(){ |
... | ... | @@ -142,18 +143,19 @@ void glut_render(void) { |
142 | 143 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
143 | 144 | |
144 | 145 | glEnable(GL_TEXTURE_1D); //enable texture mapping |
145 | - if(adjoint_fac == 1) | |
146 | + if(light_fac == 0) | |
146 | 147 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color |
147 | - else if (adjoint_fac == 0) | |
148 | + else | |
148 | 149 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
150 | + | |
149 | 151 | glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map |
150 | 152 | |
151 | 153 | GT.glCylinder(sigma, radius); //render the GT network |
152 | 154 | if (adjoint_fac == 1) { |
153 | - glDisable(GL_TEXTURE_1D); | |
155 | + glDisable(GL_TEXTURE_1D); //disable texture in order to render in other color | |
154 | 156 | glEnable(GL_BLEND); //enable color blend |
155 | 157 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set blend function |
156 | - glDisable(GL_DEPTH_TEST); //should disable depth | |
158 | + glDisable(GL_DEPTH_TEST); //should disable depth to render transparancy | |
157 | 159 | glColor4f(0.0f, 0.3f, 0.0f, 0.2f); |
158 | 160 | T.glAdjointCylinder(sigma, radius); |
159 | 161 | glDisable(GL_BLEND); |
... | ... | @@ -185,9 +187,9 @@ void glut_render(void) { |
185 | 187 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the screen |
186 | 188 | |
187 | 189 | glEnable(GL_TEXTURE_1D); //enable texture mapping |
188 | - if (adjoint_fac == 1) | |
190 | + if (light_fac == 0) | |
189 | 191 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //texture map will be used as the network color |
190 | - else if (adjoint_fac == 0) | |
192 | + else | |
191 | 193 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//map light to texture |
192 | 194 | glBindTexture(GL_TEXTURE_1D, cmap_tex); //bind the Brewer texture map |
193 | 195 | |
... | ... | @@ -229,34 +231,41 @@ void glut_render(void) { |
229 | 231 | } |
230 | 232 | } |
231 | 233 | } |
232 | - glDisable(GL_TEXTURE_1D); //disable texture | |
233 | - | |
234 | - //if (num_nets == 2) { // works only with two networks | |
235 | - // std::ostringstream ss; | |
236 | - // if (mappingMode) // if it is in mapping mode | |
237 | - // ss << "Mapping Mode"; | |
238 | - // else | |
239 | - // ss << "Compare Mode"; // default mode is compare mode | |
240 | - // glMatrixMode(GL_PROJECTION); // set up the 2d viewport for mode text printing | |
241 | - // glPushMatrix(); | |
242 | - // glLoadIdentity(); | |
243 | - // int X = glutGet(GLUT_WINDOW_WIDTH); // get the current window width | |
244 | - // int Y = glutGet(GLUT_WINDOW_HEIGHT); // get the current window height | |
245 | - // glViewport(0, 0, X / 2, Y); // locate to left bottom corner | |
246 | - // gluOrtho2D(0, X, 0, Y); // define othogonal aspect | |
247 | - // glColor3f(0.0, 1.0, 0.0); // using green to show mode | |
248 | - | |
249 | - // glMatrixMode(GL_MODELVIEW); | |
250 | - // glPushMatrix(); | |
251 | - // glLoadIdentity(); | |
252 | - | |
253 | - // glRasterPos2f(0, 5); //print text in the left bottom corner | |
254 | - // glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); | |
255 | - | |
256 | - // glPopMatrix(); | |
257 | - // glMatrixMode(GL_PROJECTION); | |
258 | - // glPopMatrix(); | |
259 | - //} | |
234 | + | |
235 | + if (num_nets == 2) { // works only with two networks | |
236 | + std::ostringstream ss; | |
237 | + if (mappingMode) // if it is in mapping mode | |
238 | + ss << "Mapping Mode"; | |
239 | + else | |
240 | + ss << "Compare Mode"; // default mode is compare mode | |
241 | + | |
242 | + glDisable(GL_TEXTURE_1D); | |
243 | + if (light_fac == 1) | |
244 | + glDisable(GL_LIGHTING); | |
245 | + glMatrixMode(GL_PROJECTION); // set up the 2d viewport for mode text printing | |
246 | + glPushMatrix(); | |
247 | + glLoadIdentity(); | |
248 | + int X = glutGet(GLUT_WINDOW_WIDTH); // get the current window width | |
249 | + int Y = glutGet(GLUT_WINDOW_HEIGHT); // get the current window height | |
250 | + glViewport(0, 0, X / 2, Y); // locate to left bottom corner | |
251 | + gluOrtho2D(0, X, 0, Y); // define othogonal aspect | |
252 | + glColor3f(0.8, 0.0, 0.0); // using red to show mode | |
253 | + | |
254 | + glMatrixMode(GL_MODELVIEW); | |
255 | + glPushMatrix(); | |
256 | + glLoadIdentity(); | |
257 | + | |
258 | + glRasterPos2f(0, 5); //print text in the left bottom corner | |
259 | + glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)(ss.str().c_str())); | |
260 | + | |
261 | + glPopMatrix(); | |
262 | + glMatrixMode(GL_PROJECTION); | |
263 | + glPopMatrix(); | |
264 | + glColor3f(1.0, 1.0, 1.0); //clear red color | |
265 | + if (light_fac == 1) | |
266 | + glEnable(GL_LIGHTING); | |
267 | + } | |
268 | + | |
260 | 269 | glutSwapBuffers(); |
261 | 270 | } |
262 | 271 | |
... | ... | @@ -393,11 +402,27 @@ void glut_keyboard(unsigned char key, int x, int y){ |
393 | 402 | radius = 0.2; |
394 | 403 | break; |
395 | 404 | |
405 | + // turn on/off the light | |
406 | + case 'l': // if keyboard 'l' is pressed, then change the light | |
407 | + if (!light_fac && !adjoint_fac) { | |
408 | + light_fac = 1; | |
409 | + glEnable(GL_LIGHTING); | |
410 | + glEnable(GL_LIGHT0); | |
411 | + glEnable(GL_LIGHT1); | |
412 | + } | |
413 | + else if (light_fac && !adjoint_fac) { | |
414 | + light_fac = 0; | |
415 | + glDisable(GL_LIGHTING); | |
416 | + glDisable(GL_LIGHT0); | |
417 | + glDisable(GL_LIGHT1); | |
418 | + } | |
419 | + break; | |
420 | + | |
396 | 421 | // render a transparant T very close to GT in compare mode |
397 | 422 | case 32: // if keyboard 'SPACE' is pressed, then change the adjoint_fac |
398 | - if (!adjoint_fac && compareMode) | |
423 | + if (!adjoint_fac && compareMode && !light_fac) | |
399 | 424 | adjoint_fac = 1; |
400 | - else if(adjoint_fac && compareMode) | |
425 | + else if(adjoint_fac && compareMode && !light_fac) | |
401 | 426 | adjoint_fac = 0; |
402 | 427 | break; |
403 | 428 | |
... | ... | @@ -473,26 +498,28 @@ void glut_initialize(){ |
473 | 498 | cam.LookAt(c[0], c[1], c[2]); //look at the center of the network |
474 | 499 | |
475 | 500 | // light |
476 | - stim::vec3<float> eye = cam.getPosition(); //get the camera position point | |
477 | - stim::vec3<float> focus = cam.getLookAt(); //get the camera focal point | |
478 | - | |
479 | 501 | GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 }; |
480 | - GLfloat diffuse1[] = { 1.0, 1.0, 1.0, 1.0 }; | |
481 | - GLfloat diffuse2[] = { 0.2, 0.2, 0.2, 1.0 }; | |
482 | - GLfloat position1[] = { 3*focus[0], 3*focus[1], -3*eye[2], 1.0 }; // upper right light source | |
483 | - GLfloat position2[] = { -2*focus[0], -2*focus[1], -3*eye[2], 0.0 }; // lower left light source | |
502 | + GLfloat diffuse1[] = { 0.8, 0.8, 0.8, 1.0 }; | |
503 | + GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 }; | |
504 | + //GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 }; | |
505 | + GLfloat position1[] = { 2 * c[0], 4 * c[1], 1 * c[0], 1.0 }; // upper right light source | |
506 | + GLfloat position2[] = { 0.0, -2 * c[1], 1 * c[0], 1.0 }; // lower left light source | |
484 | 507 | glClearColor(0.0, 0.0, 0.0, 1.0); |
485 | 508 | glShadeModel(GL_SMOOTH); |
486 | 509 | |
487 | - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); | |
510 | + | |
511 | + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); | |
512 | + | |
488 | 513 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1); |
514 | + //glLightfv(GL_LIGHT0, GL_SPECULAR, specular); | |
489 | 515 | glLightfv(GL_LIGHT0, GL_POSITION, position1); |
490 | - glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); | |
516 | + //glMaterialfv(GL_FRONT, GL_SPECULAR, specular); | |
517 | + //glMaterialf(GL_FRONT, GL_SHININESS, 60.0); | |
518 | + | |
491 | 519 | glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); |
492 | 520 | glLightfv(GL_LIGHT1, GL_POSITION, position2); |
493 | 521 | |
494 | - glEnable(GL_LIGHTING); | |
495 | - glEnable(GL_LIGHT0); | |
522 | + glEnable(GL_NORMALIZE); | |
496 | 523 | } |
497 | 524 | |
498 | 525 | #ifdef __CUDACC__ | ... | ... |