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);