diff -u ../terra.orig/gui.cc ./gui.cc
old
|
new
|
|
1 | | #include <iostream.h> |
2 | | #include <fstream.h> |
| 1 | #include <iostream> |
| 2 | #include <fstream> |
3 | 3 | |
4 | 4 | #include <GL/glut.h> |
5 | 5 | #include "glHacks.h" |
… |
… |
|
14 | 14 | int will_draw_dem = False; |
15 | 15 | |
16 | 16 | |
| 17 | void xglutResize(int width, int height); |
17 | 18 | // Prototype for our hack below. |
18 | 19 | // |
19 | 20 | void xglutKeepAspect(float width, float height); |
… |
… |
|
69 | 70 | { |
70 | 71 | int toggle = glutCreateMenu(mesh_toggle_menu); |
71 | 72 | |
72 | | glutAddMenuEntry("Draw DEM data", (int)&will_draw_dem); |
| 73 | glutAddMenuEntry("Draw DEM data", will_draw_dem); |
73 | 74 | |
74 | 75 | |
75 | | int main = glutCreateMenu(mesh_main_menu); |
| 76 | glutCreateMenu(mesh_main_menu); |
76 | 77 | glutAddSubMenu("Toggle", toggle); |
77 | 78 | |
78 | 79 | glutAddMenuEntry("Output Mesh EPS", MESH_MENU_EPS); |
… |
… |
|
141 | 142 | glC(1.0, 0.15, 0.15); |
142 | 143 | mesh->overEdges(draw_edge); |
143 | 144 | glEnd(); |
| 145 | glutSwapBuffers(); |
144 | 146 | } |
145 | 147 | |
146 | 148 | static inline void redisplay_all(int other) |
… |
… |
|
400 | 402 | |
401 | 403 | // --------------------------------------------------------------------- |
402 | 404 | |
403 | | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); |
| 405 | // glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); |
| 406 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); |
404 | 407 | mesh_view = glutCreateWindow("TERRA: Mesh"); |
405 | 408 | |
406 | 409 | xglutKeepAspect(DEM->width, DEM->height); |
… |
… |
|
408 | 411 | create_mesh_menus(); |
409 | 412 | |
410 | 413 | glutDisplayFunc(mesh_display); |
| 414 | glutReshapeFunc(xglutResize); |
411 | 415 | glutMouseFunc(mesh_mouse); |
412 | 416 | |
413 | 417 | glMatrixMode(GL_PROJECTION); |
… |
… |
|
433 | 437 | // |
434 | 438 | //////////////////////////////////////////////////////////////////////// |
435 | 439 | |
436 | | extern "C" { |
437 | | #include <GL/glutint.h> |
438 | | } |
439 | | |
440 | | void xglutKeepAspect(float width, float height) |
| 440 | void xglutResize(int width, int height) |
441 | 441 | { |
442 | | Window win; |
443 | | XSizeHints hints; |
| 442 | Map& map = mesh->getData(); |
| 443 | real w = (real)map.width; |
| 444 | real h = (real)map.height; |
| 445 | |
| 446 | // const float ar_origin = (float) WIDTH / (float) HEIGHT; |
| 447 | const float ar_origin = (float) w / (float) h; |
| 448 | const float ar_new = (float) width / (float) height; |
| 449 | |
| 450 | float scale_w = (float) width / (float) w; |
| 451 | float scale_h = (float) height / (float) h; |
| 452 | if (ar_new > ar_origin) { |
| 453 | scale_w = scale_h; |
| 454 | } else { |
| 455 | scale_h = scale_w; |
| 456 | } |
444 | 457 | |
445 | | if( __glutCurrentWindow ) |
446 | | { |
447 | | win = __glutCurrentWindow->win; |
| 458 | float margin_x = (width - w * scale_w) / 2; |
| 459 | float margin_y = (height - h * scale_h) / 2; |
448 | 460 | |
| 461 | glViewport(margin_x, margin_y, w * scale_w, h * scale_h); |
| 462 | glMatrixMode(GL_PROJECTION); |
| 463 | glLoadIdentity(); |
| 464 | glOrtho(0, w / ar_origin, 0, h / ar_origin, 0, 1.0); |
449 | 465 | |
450 | | hints.flags = PAspect; |
451 | | hints.min_aspect.x = hints.max_aspect.x = (int)(1000*width); |
452 | | hints.min_aspect.y = hints.max_aspect.y = (int)(1000*height); |
| 466 | glMatrixMode(GL_MODELVIEW); |
| 467 | glLoadIdentity() ; |
| 468 | } |
453 | 469 | |
454 | | XSetWMNormalHints(__glutDisplay, win, &hints); |
455 | | } |
| 470 | void xglutKeepAspect(float width, float height) |
| 471 | { |
| 472 | int w = glutGet(GLUT_WINDOW_WIDTH); |
| 473 | glutReshapeWindow(w, static_cast<int>(floor(width*(height/w)+0.5))); |
456 | 474 | } |