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.
This commit is contained in:
parent
a886746e71
commit
c9a2092b9c
|
@ -7,6 +7,9 @@
|
||||||
// Copyright 2008-2013 Jonathan Westhues.
|
// Copyright 2008-2013 Jonathan Westhues.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#include "solvespace.h"
|
#include "solvespace.h"
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <unix/gloffscreen.h>
|
||||||
|
#endif
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
void SolveSpaceUI::ExportSectionTo(const std::string &filename) {
|
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.
|
// so repaint the scene. And hide the toolbar too.
|
||||||
bool prevShowToolbar = SS.showToolbar;
|
bool prevShowToolbar = SS.showToolbar;
|
||||||
SS.showToolbar = false;
|
SS.showToolbar = false;
|
||||||
|
#ifndef WIN32
|
||||||
|
std::unique_ptr<GLOffscreen> gloffscreen(new GLOffscreen);
|
||||||
|
gloffscreen->begin(w, h);
|
||||||
|
#endif
|
||||||
SS.GW.Paint();
|
SS.GW.Paint();
|
||||||
SS.showToolbar = prevShowToolbar;
|
SS.showToolbar = prevShowToolbar;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
|
@ -27,6 +27,8 @@ GLOffscreen::GLOffscreen() : _pixels(NULL), _pixels_inv(NULL), _width(0), _heigh
|
||||||
}
|
}
|
||||||
|
|
||||||
GLOffscreen::~GLOffscreen() {
|
GLOffscreen::~GLOffscreen() {
|
||||||
|
delete[] _pixels;
|
||||||
|
delete[] _pixels_inv;
|
||||||
glDeleteRenderbuffersEXT(1, &_depth_renderbuffer);
|
glDeleteRenderbuffersEXT(1, &_depth_renderbuffer);
|
||||||
glDeleteRenderbuffersEXT(1, &_color_renderbuffer);
|
glDeleteRenderbuffersEXT(1, &_color_renderbuffer);
|
||||||
glDeleteFramebuffersEXT(1, &_framebuffer);
|
glDeleteFramebuffersEXT(1, &_framebuffer);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user