Skip to content

Commit

Permalink
Merge pull request patriciogonzalezvivo#128 from Wilhansen/fix-screen…
Browse files Browse the repository at this point in the history
…shot-events

Fix screenshot saving from wrong buffer.
  • Loading branch information
patriciogonzalezvivo authored Feb 15, 2019
2 parents c87c307 + 41cd425 commit 7ee4f50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,12 +1102,12 @@ int main(int argc, char **argv){
// Draw Cursor and 2D Debug elements
sandbox.drawDebug2D();

// Finish drawing
sandbox.drawDone();

// Swap the buffers
renderGL();

// Finish drawing
sandbox.drawDone();

if ( timeLimit >= 0.0 && getTime() >= timeLimit ) {
bRun.store(false);
}
Expand Down
18 changes: 16 additions & 2 deletions src/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,22 @@ void Sandbox::onViewportResize(int _newWidth, int _newHeight) {
void Sandbox::onScreenshot(std::string _file) {
if (_file != "" && isGL()) {
unsigned char* pixels = new unsigned char[getWindowWidth() * getWindowHeight()*4];
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels);
savePixels(_file, pixels, getWindowWidth(), getWindowHeight());

glGetError();
GLint currentBuffer;
glGetIntegerv(GL_READ_BUFFER, &currentBuffer);

glReadBuffer(GL_FRONT);
{
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels);
GLenum err;
while ( (err = glGetError()) != GL_NO_ERROR ) {
std::cout << "// Error in saving screenshot: 0x" << std::hex << err << std::endl;
}
savePixels(_file, pixels, getWindowWidth(), getWindowHeight());
}
glReadBuffer(currentBuffer);

if (!m_record) {
std::cout << "// Screenshot saved to " << _file << std::endl;
Expand Down

0 comments on commit 7ee4f50

Please sign in to comment.