From fca0faf5e5146865a21217ef070e1c59a7289ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Wed, 9 Jan 2013 17:46:13 -0200 Subject: [PATCH] keep aspect ratio while resizing the window --- openglcanvas.cpp | 10 +++++----- openglcanvas.h | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/openglcanvas.cpp b/openglcanvas.cpp index ced8346..2ed9039 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -157,11 +157,11 @@ void OpenGLCanvas::initializeGL(){ struct stat testbuf; if(stat(input_image,&testbuf)){ fprintf(stderr,"the default image file does not exist!\n"); - free(input_image); load_image(QFileDialog::getOpenFileName(this,tr("Choose Panorama File")).toStdString().c_str()); }else{ load_image(input_image); } + free(input_image); // mesh resolution int m,n; @@ -196,9 +196,7 @@ void OpenGLCanvas::initializeGL(){ numberOfIndices = meshNumIndices; triangleIndices = indices; - free(input_image); setShaders(); - } void OpenGLCanvas::define_texture_coordinates(float *texCoord, int m, int n, float min_phi, float max_phi, float min_lambda, float max_lambda){ @@ -458,8 +456,10 @@ void OpenGLCanvas::readTextureBytes(const char * const progname, } void OpenGLCanvas::resizeGL(int w, int h){ - glViewport(0,0,w,h); - + if(w>h) + glViewport(0,(h-w)/2,w,w); + else + glViewport((w-h)/2,0,h,h); } char * OpenGLCanvas::textFileRead(char *fn) { diff --git a/openglcanvas.h b/openglcanvas.h index 835834e..88fdc7b 100644 --- a/openglcanvas.h +++ b/openglcanvas.h @@ -86,9 +86,8 @@ private: unsigned int * triangleIndices; float * verticesPositions; float * textureCoordinates; - float windowWidth; - float windowHeight; - + //float windowWidth; + //float windowHeight; }; #endif // OPENGLCANVAS_H -- GitLab