From efd358d734c78d4608906c2a5dc9210b72db4db2 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 13 Aug 2016 09:55:37 +0000 Subject: [PATCH] Unbreak PNG export. Before this commit, on Win32 the toolbar was visible, and the framebuffer was flipped, whereas on other platforms just a black image was exported. --- src/export.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/export.cpp b/src/export.cpp index 8990080..386d262 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -1089,6 +1089,11 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, //----------------------------------------------------------------------------- void SolveSpaceUI::ExportAsPngTo(const std::string &filename) { #if !defined(HEADLESS) + // Somewhat hacky way to invoke glReadPixels without dragging in all OpenGL headers. + OpenGl1Renderer canvas = {}; + canvas.camera = SS.GW.GetCamera(); + std::shared_ptr screenshot; + // No guarantee that the back buffer contains anything valid right now, // so repaint the scene. And hide the toolbar too. bool prevShowToolbar = SS.showToolbar; @@ -1097,17 +1102,22 @@ void SolveSpaceUI::ExportAsPngTo(const std::string &filename) { GlOffscreen offscreen; offscreen.Render((int)SS.GW.width, (int)SS.GW.height, [&] { SS.GW.Paint(); + screenshot = canvas.ReadFrame(); }); +#else + SS.GW.Paint(); + screenshot = canvas.ReadFrame(); #endif SS.showToolbar = prevShowToolbar; - // Somewhat hacky way to invoke glReadPixels without dragging in all OpenGL headers. - OpenGl1Renderer canvas = {}; - canvas.camera = SS.GW.GetCamera(); - std::shared_ptr screenshot = canvas.ReadFrame(); +#if defined(WIN32) || defined(HAVE_GTK) + bool flip = true; +#else + bool flip = false; +#endif FILE *f = ssfopen(filename, "wb"); - if(!f || !screenshot->WritePng(f, /*flip=*/FLIP_FRAMEBUFFER)) { + if(!f || !screenshot->WritePng(f, flip)) { Error("Couldn't write to '%s'", filename.c_str()); } if(f) fclose(f);