Merge branch 'brushbsp' of https://github.com/ericwa/ericw-tools into brushbsp
This commit is contained in:
commit
60255b8fe9
|
|
@ -29,6 +29,9 @@ See file, 'COPYING', for details.
|
|||
#include <QKeyEvent>
|
||||
#include <QTime>
|
||||
#include <fmt/core.h>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#include <QStandardPaths>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <common/bspfile.hh>
|
||||
#include <common/bsputils.hh>
|
||||
|
|
@ -308,6 +311,40 @@ void GLView::setDrawFlat(bool drawflat)
|
|||
update();
|
||||
}
|
||||
|
||||
void GLView::takeScreenshot(int w, int h)
|
||||
{
|
||||
// update aspect ratio
|
||||
float backupDisplayAspect = m_displayAspect;
|
||||
m_displayAspect = static_cast<float>(w) / static_cast<float>(h);
|
||||
|
||||
makeCurrent();
|
||||
{
|
||||
QOpenGLFramebufferObjectFormat format;
|
||||
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||
format.setSamples(4);
|
||||
|
||||
QOpenGLFramebufferObject fbo(w, h, format);
|
||||
assert(fbo.bind());
|
||||
|
||||
glViewport(0, 0, w, h);
|
||||
paintGL();
|
||||
|
||||
QString dest = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) +
|
||||
QLatin1String("/Screenshots/lightpreview_") +
|
||||
QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss") + QLatin1String(".png");
|
||||
|
||||
QImage image = fbo.toImage();
|
||||
image.save(dest);
|
||||
|
||||
assert(fbo.release());
|
||||
}
|
||||
doneCurrent();
|
||||
|
||||
// restore aspect ratio
|
||||
m_displayAspect = backupDisplayAspect;
|
||||
update();
|
||||
}
|
||||
|
||||
void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const std::vector<entdict_t> &entities)
|
||||
{
|
||||
// FIXME: move to a lightpreview_settings
|
||||
|
|
|
|||
|
|
@ -121,6 +121,8 @@ public:
|
|||
void setShowTris(bool showtris);
|
||||
void setDrawFlat(bool drawflat);
|
||||
|
||||
void takeScreenshot(int w, int h);
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
void paintGL() override;
|
||||
|
|
|
|||
|
|
@ -129,6 +129,8 @@ void MainWindow::setupMenu()
|
|||
|
||||
auto *openRecent = menu->addAction(tr("Open &Recent"));
|
||||
|
||||
auto *takeScreenshot = menu->addAction(tr("Take Screenshot"), this, [=]() { glView->takeScreenshot(3840, 2160); });
|
||||
|
||||
auto *exit = menu->addAction(tr("E&xit"), this, &QWidget::close);
|
||||
exit->setShortcut(QKeySequence::Quit);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue