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.
This commit is contained in:
whitequark 2016-08-13 09:55:37 +00:00
parent 6e860fb148
commit efd358d734

View File

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