Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/StelMainView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1631,11 +1631,16 @@ void StelMainView::doScreenshot(void)
// HiDPI screens interfere, and the viewing angle has to be maintained.
// First, image size:
glWidget->makeCurrent();
float pixelRatio = static_cast<float>(QOpenGLContext::currentContext()->screen()->devicePixelRatio());
const bool nightModeWasEnabled=nightModeEffect->isEnabled();
nightModeEffect->setEnabled(false);
const float pixelRatio = static_cast<float>(QOpenGLContext::currentContext()->screen()->devicePixelRatio());
qDebug() << "pixelRatio:" << QString::number(pixelRatio, 'f', 2);
int imgWidth =static_cast<int>(stelScene->width());
int imgHeight=static_cast<int>(stelScene->height());
bool nightModeWasEnabled=nightModeEffect->isEnabled();
nightModeEffect->setEnabled(false);
// Screen scaling makes things worse again.
//int scaledImgWidth = int(static_cast<float>(imgWidth) * pixelRatio);
//int scaledImgHeight = int(static_cast<float>(imgHeight) * pixelRatio);

if (flagUseCustomScreenshotSize)
{
// Borrowed from Scenery3d renderer: determine maximum framebuffer size as minimum of texture, viewport and renderbuffer size
Expand Down Expand Up @@ -1681,6 +1686,7 @@ void StelMainView::doScreenshot(void)
return;
}
}

// The texture format depends on used GL version. RGB is fine on OpenGL. on GLES, we must use RGBA and circumvent problems with a few more steps.
bool isGLES=(QOpenGLContext::currentContext()->format().renderableType() == QSurfaceFormat::OpenGLES);

Expand All @@ -1689,25 +1695,30 @@ 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<int>(static_cast<float>(imgWidth) * pixelRatio), static_cast<int>(static_cast<float>(imgHeight) * pixelRatio), 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(static_cast<int>(static_cast<float>(imgWidth) * pixelRatio), static_cast<int>(static_cast<float>(imgHeight) * pixelRatio));
//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 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))
customScreenshotMagnification=static_cast<float>(imgHeight)/static_cast<float>(qApp->screenAt(QPoint(stelScene->width()*0.5, stelScene->height()*0.5))->geometry().height());
#else
customScreenshotMagnification=static_cast<float>(imgHeight)/static_cast<float>(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);
Expand Down