From c9a2092b9cb70ec7a7c7e5ebe087e99323f083f3 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 3 Mar 2016 09:53:10 +0000 Subject: [PATCH] Fix image export on *nix. Before this commit, trying to export image on *nix platforms yielded a black rectangle, since since there is nowhere to render to when we're not in a GUI toolkit draw callback. On Windows, nothing changes: we do a repaint without the toolbar, glReadPixels, export. On *nix, we create another offscreen rendering context, render into it, then destroy it. As a bonus this avoids some minor flickering that would happen if we reused the regular rendering path. --- src/export.cpp | 7 +++++++ src/solvespace.h | 1 + src/unix/gloffscreen.cpp | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/export.cpp b/src/export.cpp index 6bfb4b5..38d7642 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -7,6 +7,9 @@ // Copyright 2008-2013 Jonathan Westhues. //----------------------------------------------------------------------------- #include "solvespace.h" +#ifndef WIN32 +#include +#endif #include void SolveSpaceUI::ExportSectionTo(const std::string &filename) { @@ -1048,6 +1051,10 @@ void SolveSpaceUI::ExportAsPngTo(const std::string &filename) { // so repaint the scene. And hide the toolbar too. bool prevShowToolbar = SS.showToolbar; SS.showToolbar = false; +#ifndef WIN32 + std::unique_ptr gloffscreen(new GLOffscreen); + gloffscreen->begin(w, h); +#endif SS.GW.Paint(); SS.showToolbar = prevShowToolbar; diff --git a/src/solvespace.h b/src/solvespace.h index d5ba6ac..c52733a 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/src/unix/gloffscreen.cpp b/src/unix/gloffscreen.cpp index 107721f..be836e2 100644 --- a/src/unix/gloffscreen.cpp +++ b/src/unix/gloffscreen.cpp @@ -27,6 +27,8 @@ GLOffscreen::GLOffscreen() : _pixels(NULL), _pixels_inv(NULL), _width(0), _heigh } GLOffscreen::~GLOffscreen() { + delete[] _pixels; + delete[] _pixels_inv; glDeleteRenderbuffersEXT(1, &_depth_renderbuffer); glDeleteRenderbuffersEXT(1, &_color_renderbuffer); glDeleteFramebuffersEXT(1, &_framebuffer);