From 4c8c529fe742b6d1c0711ef7f0c6e89f3bbae1c3 Mon Sep 17 00:00:00 2001 From: Georg Zotti Date: Wed, 15 Feb 2023 01:36:08 +0100 Subject: [PATCH 1/3] Experimental: avoid scaling --- src/StelMainView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StelMainView.cpp b/src/StelMainView.cpp index c190f3aff2550..8fc1d0c24fa38 100644 --- a/src/StelMainView.cpp +++ b/src/StelMainView.cpp @@ -1631,7 +1631,7 @@ void StelMainView::doScreenshot(void) // HiDPI screens interfere, and the viewing angle has to be maintained. // First, image size: glWidget->makeCurrent(); - float pixelRatio = static_cast(QOpenGLContext::currentContext()->screen()->devicePixelRatio()); + float pixelRatio = 1.f; // static_cast(QOpenGLContext::currentContext()->screen()->devicePixelRatio()); int imgWidth =static_cast(stelScene->width()); int imgHeight=static_cast(stelScene->height()); bool nightModeWasEnabled=nightModeEffect->isEnabled(); From 76535c317bfffdb7b9eecfb701b7350c2c0bb582 Mon Sep 17 00:00:00 2001 From: Georg Zotti Date: Thu, 16 Feb 2023 00:46:17 +0100 Subject: [PATCH 2/3] Reactivate pixelPatio. - Now only custom-sized screenshots are broken... --- src/StelMainView.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/StelMainView.cpp b/src/StelMainView.cpp index 8fc1d0c24fa38..7e51e0ea4f515 100644 --- a/src/StelMainView.cpp +++ b/src/StelMainView.cpp @@ -818,7 +818,7 @@ QSurfaceFormat StelMainView::getDesiredGLFormat(QSettings* configuration) #else const bool vsdef = true; #endif - if (configuration->value("video/vsync", vsdef).toBool()) + if (configuration && configuration->value("video/vsync", vsdef).toBool()) fmt.setSwapInterval(1); else fmt.setSwapInterval(0); @@ -1631,11 +1631,15 @@ void StelMainView::doScreenshot(void) // HiDPI screens interfere, and the viewing angle has to be maintained. // First, image size: glWidget->makeCurrent(); - float pixelRatio = 1.f; // static_cast(QOpenGLContext::currentContext()->screen()->devicePixelRatio()); + const bool nightModeWasEnabled=nightModeEffect->isEnabled(); + nightModeEffect->setEnabled(false); + const float pixelRatio = static_cast(QOpenGLContext::currentContext()->screen()->devicePixelRatio()); int imgWidth =static_cast(stelScene->width()); int imgHeight=static_cast(stelScene->height()); - bool nightModeWasEnabled=nightModeEffect->isEnabled(); - nightModeEffect->setEnabled(false); + // Screen scaling makes things worse again. + int finalImgWidth = int(static_cast(imgWidth) * pixelRatio); + int finalImgHeight = int(static_cast(imgHeight) * pixelRatio); + if (flagUseCustomScreenshotSize) { // Borrowed from Scenery3d renderer: determine maximum framebuffer size as minimum of texture, viewport and renderbuffer size @@ -1672,8 +1676,8 @@ void StelMainView::doScreenshot(void) int maximumFramebufferSize = qMin(texSize,qMin(rbSize,qMin(viewportSize[0],viewportSize[1]))); qCDebug(mainview)<<"Maximum framebuffer size:"<format().renderableType() == QSurfaceFormat::OpenGLES); @@ -1689,16 +1694,17 @@ void StelMainView::doScreenshot(void) fbFormat.setInternalTextureFormat(isGLES ? GL_RGBA : GL_RGB); // try to avoid transparent background! if(const auto multisamplingLevel = configuration->value("video/multisampling", 0).toInt()) fbFormat.setSamples(multisamplingLevel); - QOpenGLFramebufferObject * fbObj = new QOpenGLFramebufferObject(static_cast(static_cast(imgWidth) * pixelRatio), static_cast(static_cast(imgHeight) * pixelRatio), fbFormat); + QOpenGLFramebufferObject * fbObj = new QOpenGLFramebufferObject(finalImgWidth, finalImgHeight, fbFormat); fbObj->bind(); // Now the painter has to be convinced to paint to the potentially larger image frame. - QOpenGLPaintDevice fbObjPaintDev(static_cast(static_cast(imgWidth) * pixelRatio), static_cast(static_cast(imgHeight) * pixelRatio)); + QOpenGLPaintDevice fbObjPaintDev(finalImgWidth, finalImgHeight); // It seems the projector has its own knowledge about image size. We must adjust fov and image size, but reset afterwards. StelCore *core=StelApp::getInstance().getCore(); StelProjector::StelProjectorParams pParams=core->getCurrentStelProjectorParams(); StelProjector::StelProjectorParams sParams=pParams; - //qCDebug(mainview) << "Screenshot Viewport: x" << pParams.viewportXywh[0] << "/y" << pParams.viewportXywh[1] << "/w" << pParams.viewportXywh[2] << "/h" << pParams.viewportXywh[3]; + qCDebug(mainview) << "Screenshot Viewport: x" << pParams.viewportXywh[0] << "/y" << pParams.viewportXywh[1] << "/w" << pParams.viewportXywh[2] << "/h" << pParams.viewportXywh[3]; + qCDebug(mainview) << "Screenshot: setting dimensions to" << imgWidth << "x" << imgHeight; sParams.viewportXywh[2]=imgWidth; sParams.viewportXywh[3]=imgHeight; @@ -1708,6 +1714,7 @@ void StelMainView::doScreenshot(void) #else customScreenshotMagnification=static_cast(imgHeight)/static_cast(qApp->screens().at(qApp->desktop()->screenNumber())->geometry().height()); #endif + qCDebug(mainview) << "Screenshot: customScreenshotMagnification" << customScreenshotMagnification; sParams.viewportCenter.set(0.0+(0.5+pParams.viewportCenterOffset.v[0])*imgWidth, 0.0+(0.5+pParams.viewportCenterOffset.v[1])*imgHeight); sParams.viewportFovDiameter = qMin(imgWidth,imgHeight); core->setCurrentStelProjectorParams(sParams); From 8a887b17d87130cb18aacd8243e80117fdf45d37 Mon Sep 17 00:00:00 2001 From: Georg Zotti Date: Sun, 19 Feb 2023 14:59:47 +0100 Subject: [PATCH 3/3] Do not scale screenshot --- src/StelMainView.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/StelMainView.cpp b/src/StelMainView.cpp index 7e51e0ea4f515..e2bded4d8cf98 100644 --- a/src/StelMainView.cpp +++ b/src/StelMainView.cpp @@ -1634,11 +1634,12 @@ void StelMainView::doScreenshot(void) const bool nightModeWasEnabled=nightModeEffect->isEnabled(); nightModeEffect->setEnabled(false); const float pixelRatio = static_cast(QOpenGLContext::currentContext()->screen()->devicePixelRatio()); + qDebug() << "pixelRatio:" << QString::number(pixelRatio, 'f', 2); int imgWidth =static_cast(stelScene->width()); int imgHeight=static_cast(stelScene->height()); // Screen scaling makes things worse again. - int finalImgWidth = int(static_cast(imgWidth) * pixelRatio); - int finalImgHeight = int(static_cast(imgHeight) * pixelRatio); + //int scaledImgWidth = int(static_cast(imgWidth) * pixelRatio); + //int scaledImgHeight = int(static_cast(imgHeight) * pixelRatio); if (flagUseCustomScreenshotSize) { @@ -1676,8 +1677,8 @@ void StelMainView::doScreenshot(void) int maximumFramebufferSize = qMin(texSize,qMin(rbSize,qMin(viewportSize[0],viewportSize[1]))); qCDebug(mainview)<<"Maximum framebuffer size:"<value("video/multisampling", 0).toInt()) fbFormat.setSamples(multisamplingLevel); - QOpenGLFramebufferObject * fbObj = new QOpenGLFramebufferObject(finalImgWidth, finalImgHeight, fbFormat); + //QOpenGLFramebufferObject * fbObj = new QOpenGLFramebufferObject(scaledImgWidth, scaledImgHeight, fbFormat); + QOpenGLFramebufferObject * fbObj = new QOpenGLFramebufferObject(imgWidth, imgHeight, fbFormat); fbObj->bind(); // Now the painter has to be convinced to paint to the potentially larger image frame. - QOpenGLPaintDevice fbObjPaintDev(finalImgWidth, finalImgHeight); + //QOpenGLPaintDevice fbObjPaintDev(scaledImgWidth, scaledImgHeight); + QOpenGLPaintDevice fbObjPaintDev(imgWidth, imgHeight); // It seems the projector has its own knowledge about image size. We must adjust fov and image size, but reset afterwards. StelCore *core=StelApp::getInstance().getCore(); - StelProjector::StelProjectorParams pParams=core->getCurrentStelProjectorParams(); + const StelProjector::StelProjectorParams pParams=core->getCurrentStelProjectorParams(); StelProjector::StelProjectorParams sParams=pParams; qCDebug(mainview) << "Screenshot Viewport: x" << pParams.viewportXywh[0] << "/y" << pParams.viewportXywh[1] << "/w" << pParams.viewportXywh[2] << "/h" << pParams.viewportXywh[3]; qCDebug(mainview) << "Screenshot: setting dimensions to" << imgWidth << "x" << imgHeight; sParams.viewportXywh[2]=imgWidth; sParams.viewportXywh[3]=imgHeight; + sParams.devicePixelsPerPixel=1.; // Forget about scaling. We know what we want! // Configure a helper value to allow some modules to tweak their output sizes. Currently used by StarMgr, maybe solve font issues? #if (QT_VERSION>=QT_VERSION_CHECK(5,12,0))