Ticket #43585: patch-opengl.diff

File patch-opengl.diff, 3.1 KB (added by lockhart (Thomas Lockhart), 11 years ago)

Patches to enable window resizing.

  • gui.cc

    diff -u ../terra.orig/gui.cc ./gui.cc
    old new  
    1 #include <iostream.h>
    2 #include <fstream.h>
     1#include <iostream>
     2#include <fstream>
    33
    44#include <GL/glut.h>
    55#include "glHacks.h"
     
    1414int will_draw_dem = False;
    1515
    1616
     17void xglutResize(int width, int height);
    1718// Prototype for our hack below.
    1819//
    1920void xglutKeepAspect(float width, float height);
     
    6970{
    7071    int toggle = glutCreateMenu(mesh_toggle_menu);
    7172
    72     glutAddMenuEntry("Draw DEM data", (int)&will_draw_dem);
     73    glutAddMenuEntry("Draw DEM data", will_draw_dem);
    7374
    7475
    75     int main = glutCreateMenu(mesh_main_menu);
     76    glutCreateMenu(mesh_main_menu);
    7677    glutAddSubMenu("Toggle", toggle);
    7778
    7879    glutAddMenuEntry("Output Mesh EPS", MESH_MENU_EPS);
     
    141142      glC(1.0, 0.15, 0.15);
    142143      mesh->overEdges(draw_edge);
    143144    glEnd();
     145    glutSwapBuffers();
    144146}
    145147
    146148static inline void redisplay_all(int other)
     
    400402
    401403    // ---------------------------------------------------------------------
    402404
    403     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
     405    // glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
     406    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    404407    mesh_view = glutCreateWindow("TERRA: Mesh");
    405408
    406409    xglutKeepAspect(DEM->width, DEM->height);
     
    408411    create_mesh_menus();
    409412
    410413    glutDisplayFunc(mesh_display);
     414    glutReshapeFunc(xglutResize);
    411415    glutMouseFunc(mesh_mouse);
    412416
    413417    glMatrixMode(GL_PROJECTION);
     
    433437//
    434438////////////////////////////////////////////////////////////////////////
    435439
    436 extern "C" {
    437 #include <GL/glutint.h>
    438 }
    439 
    440 void xglutKeepAspect(float width, float height)
     440void xglutResize(int width, int height)
    441441{
    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    }
    444457
    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;
    448460
     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);
    449465
    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}
    453469
    454         XSetWMNormalHints(__glutDisplay, win, &hints);
    455     }
     470void 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)));
    456474}