--- gui.cc.orig 1996-01-30 10:35:28.000000000 -0600 +++ gui.cc 2018-04-11 18:48:55.000000000 -0500 @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include "glHacks.h" @@ -14,6 +14,7 @@ int will_draw_dem = False; +void xglutResize(int width, int height); // Prototype for our hack below. // void xglutKeepAspect(float width, float height); @@ -69,10 +70,10 @@ { int toggle = glutCreateMenu(mesh_toggle_menu); - glutAddMenuEntry("Draw DEM data", (int)&will_draw_dem); + glutAddMenuEntry("Draw DEM data", will_draw_dem); - int main = glutCreateMenu(mesh_main_menu); + glutCreateMenu(mesh_main_menu); glutAddSubMenu("Toggle", toggle); glutAddMenuEntry("Output Mesh EPS", MESH_MENU_EPS); @@ -141,6 +142,7 @@ glC(1.0, 0.15, 0.15); mesh->overEdges(draw_edge); glEnd(); + glutSwapBuffers(); } static inline void redisplay_all(int other) @@ -400,7 +402,8 @@ // --------------------------------------------------------------------- - glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + // glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); mesh_view = glutCreateWindow("TERRA: Mesh"); xglutKeepAspect(DEM->width, DEM->height); @@ -408,6 +411,7 @@ create_mesh_menus(); glutDisplayFunc(mesh_display); + glutReshapeFunc(xglutResize); glutMouseFunc(mesh_mouse); glMatrixMode(GL_PROJECTION); @@ -433,24 +437,38 @@ // //////////////////////////////////////////////////////////////////////// -extern "C" { -#include -} - -void xglutKeepAspect(float width, float height) +void xglutResize(int width, int height) { - Window win; - XSizeHints hints; + Map& map = mesh->getData(); + real w = (real)map.width; + real h = (real)map.height; + + // const float ar_origin = (float) WIDTH / (float) HEIGHT; + const float ar_origin = (float) w / (float) h; + const float ar_new = (float) width / (float) height; + + float scale_w = (float) width / (float) w; + float scale_h = (float) height / (float) h; + if (ar_new > ar_origin) { + scale_w = scale_h; + } else { + scale_h = scale_w; + } - if( __glutCurrentWindow ) - { - win = __glutCurrentWindow->win; + float margin_x = (width - w * scale_w) / 2; + float margin_y = (height - h * scale_h) / 2; + glViewport(margin_x, margin_y, w * scale_w, h * scale_h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, w / ar_origin, 0, h / ar_origin, 0, 1.0); - hints.flags = PAspect; - hints.min_aspect.x = hints.max_aspect.x = (int)(1000*width); - hints.min_aspect.y = hints.max_aspect.y = (int)(1000*height); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity() ; +} - XSetWMNormalHints(__glutDisplay, win, &hints); - } +void xglutKeepAspect(float width, float height) +{ + int w = glutGet(GLUT_WINDOW_WIDTH); + glutReshapeWindow(w, static_cast(floor(width*(height/w)+0.5))); }