Commit 635f2ee3 authored by Alexander Dielen's avatar Alexander Dielen Committed by Max Lyon
Browse files

correct aspect ratio for snapshots

parent 728bc727
...@@ -388,7 +388,7 @@ void glViewer::setFOVY(double _fovy) { ...@@ -388,7 +388,7 @@ void glViewer::setFOVY(double _fovy) {
updateProjectionMatrix(); updateProjectionMatrix();
} }
void glViewer::updateProjectionMatrix() void glViewer::updateProjectionMatrix(double _aspect)
{ {
if( projectionUpdateLocked_ ) if( projectionUpdateLocked_ )
return; return;
...@@ -397,7 +397,7 @@ void glViewer::updateProjectionMatrix() ...@@ -397,7 +397,7 @@ void glViewer::updateProjectionMatrix()
glstate_->reset_projection(); glstate_->reset_projection();
const double aspect = this->aspect_ratio(); const double aspect = _aspect ? _aspect : this->aspect_ratio();
// In stereo mode we have to use a perspective matrix // In stereo mode we have to use a perspective matrix
if ( projectionMode_ == PERSPECTIVE_PROJECTION) if ( projectionMode_ == PERSPECTIVE_PROJECTION)
{ {
...@@ -542,7 +542,7 @@ void glViewer::updateGL() ...@@ -542,7 +542,7 @@ void glViewer::updateGL()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void glViewer::drawScene() void glViewer::drawScene(double _aspect)
{ {
// Inside the glWidget rendering, the system should not send extra updates // Inside the glWidget rendering, the system should not send extra updates
...@@ -574,7 +574,7 @@ void glViewer::drawScene() ...@@ -574,7 +574,7 @@ void glViewer::drawScene()
properties_.setPlanes(nearPlane,farPlane); properties_.setPlanes(nearPlane,farPlane);
updateProjectionMatrix(); updateProjectionMatrix(_aspect);
// store time since last repaint in gl state and restart timer // store time since last repaint in gl state and restart timer
glstate_->set_msSinceLastRedraw (redrawTime_.restart ()); glstate_->set_msSinceLastRedraw (redrawTime_.restart ());
...@@ -1029,7 +1029,7 @@ void glViewer::initializeGL() ...@@ -1029,7 +1029,7 @@ void glViewer::initializeGL()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void glViewer::paintGL() void glViewer::paintGL(double _aspect)
{ {
if (!initialized_) if (!initialized_)
initializeGL (); initializeGL ();
...@@ -1065,7 +1065,7 @@ void glViewer::paintGL() ...@@ -1065,7 +1065,7 @@ void glViewer::paintGL()
properties_.unLockUpdate(); properties_.unLockUpdate();
// draw scene // draw scene
drawScene(); drawScene(_aspect);
glPopMatrix(); glPopMatrix();
...@@ -2205,17 +2205,16 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo ...@@ -2205,17 +2205,16 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
// Get viewport data // Get viewport data
glstate_->get_viewport(left, bottom, w, h); glstate_->get_viewport(left, bottom, w, h);
double aspect = (double)w / (double)h;
// Test if size is given: // Test if size is given:
if(_width != 0 || _height != 0) { if(_width != 0 || _height != 0) {
// Adapt dimensions if aspect ratio is demanded // Adapt dimensions if aspect ratio is demanded
if(_width == 0) { if(_width == 0) {
double aspect = (double)w / (double)h;
_width = (int)((double)_height * aspect); _width = (int)((double)_height * aspect);
} }
if(_height == 0) { if(_height == 0) {
double aspect = (double)w / (double)h;
_height = (int)((double)_width / aspect); _height = (int)((double)_width / aspect);
} }
bak_w = w; bak_w = w;
...@@ -2225,8 +2224,9 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo ...@@ -2225,8 +2224,9 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
// Set new viewport // Set new viewport
glstate_->viewport(0, 0, w, h); glstate_->viewport(0, 0, w, h);
aspect = (double)w / (double)h;
} }
QFramebufferObjectFormat format; QFramebufferObjectFormat format;
format.setInternalTextureFormat(GL_RGBA); format.setInternalTextureFormat(GL_RGBA);
format.setTextureTarget(GL_TEXTURE_2D); format.setTextureTarget(GL_TEXTURE_2D);
...@@ -2238,7 +2238,7 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo ...@@ -2238,7 +2238,7 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
format.setSamples(samples); format.setSamples(samples);
makeCurrent(); makeCurrent();
QFramebufferObject fb(w,h,format); QFramebufferObject fb(w,h,format);
if ( fb.isValid() ){ if ( fb.isValid() ){
...@@ -2278,7 +2278,7 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo ...@@ -2278,7 +2278,7 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
ACG::GLState::lockBlendFuncSeparate(false, true); ACG::GLState::lockBlendFuncSeparate(false, true);
glEnable(GL_MULTISAMPLE); glEnable(GL_MULTISAMPLE);
paintGL(); paintGL(aspect);
glFinish(); glFinish();
ACG::GLState::unlockBlendFuncSeparate(); ACG::GLState::unlockBlendFuncSeparate();
...@@ -2324,12 +2324,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo ...@@ -2324,12 +2324,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
} }
if(_width != 0 || _height != 0) { if(_width != 0 || _height != 0) {
// Reset viewport to former size // Reset viewport to former size
glstate_->viewport(left, bottom, bak_w, bak_h); glstate_->viewport(left, bottom, bak_w, bak_h);
} }
glstate_->pop_modelview_matrix(); glstate_->pop_modelview_matrix();
glstate_->pop_projection_matrix(); glstate_->pop_projection_matrix();
} }
......
...@@ -483,7 +483,7 @@ protected: ...@@ -483,7 +483,7 @@ protected:
/// initialize OpenGL states /// initialize OpenGL states
virtual void initializeGL(); virtual void initializeGL();
/// draw the scene. Triggered by updateGL(). /// draw the scene. Triggered by updateGL().
virtual void paintGL(); virtual void paintGL(double _aspect = 0.0);
/// handle resize events /// handle resize events
virtual void resizeEvent(QGraphicsSceneResizeEvent * _e); virtual void resizeEvent(QGraphicsSceneResizeEvent * _e);
/// handle move events /// handle move events
...@@ -515,7 +515,7 @@ protected: ...@@ -515,7 +515,7 @@ protected:
/// updates projection matrix /// updates projection matrix
void updateProjectionMatrix(); void updateProjectionMatrix(double _aspect = 0.0);
//------------------------------------------------------------- protected slots //------------------------------------------------------------- protected slots
...@@ -545,7 +545,7 @@ private: ...@@ -545,7 +545,7 @@ private:
/* Recursively draws each node in the scene graph. /* Recursively draws each node in the scene graph.
Called by paintGL(). */ Called by paintGL(). */
void drawScene(); void drawScene(double _aspect = 0.0);
// helper called by drawScene(). // helper called by drawScene().
void drawScene_mono(); void drawScene_mono();
/// helper function for setting the projection mode of the coordinate system node /// helper function for setting the projection mode of the coordinate system node
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment