openframeworks / openframeworks/openFrameworks
ofSaveScreen(…) does not work with ofSetAutoBackground(false) on windows due to single buffering
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
Moving discussion from forum thread to here.
The problem is that when the background is set to not autoclear, the save screen functions (ofSaveScreen(...), ofSaveFrame(...) and ofImage.grabScreen(...)) do not actually grab what is displayed on the screen - they grab an empty, gray screen. This only applies to windows. I'm running Windows 7 (64) with oF 0.8.0 in Code::Blocks 12.11.
Example code that causes the issue:
void testApp::setup(){
ofSetBackgroundAuto(false);
}
void testApp::draw(){
ofBackground(0);
ofSetColor(255);
ofRect(0, 0, 200, 200);
if (ofGetKeyPressed('s')) ofSaveScreen("test.png");
}
The issue, as I understand it, has to do with the single buffering workaround from 4 years ago (@ofZach's #78?). When bClearAuto is false in ofAppGLFWindow::display(), only the front buffer is used since glDrawBuffer (GL_FRONT) is called and then there are no glfwSwapBuffers(...) calls. ofImage::grabScreen(...) uses glReadPixels(...) to get the frame buffer. This defaults to reading from the back buffer which is always empty in this situation. Inserting glReadBuffer(GL_FRONT) before the pixel reading fixes the issue.
Anyone know what the issues were in #78 that required the single buffering workaround? If the workaround was to avoid swapping buffers, then could we use glDrawBuffer (GL_FRONT_AND_BACK) instead of glDrawBuffer (GL_FRONT) on this line of ofAppGLFWWindow? That would keep the back buffer updated for the glReadPixels(...) call.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in libs/openFrameworks/app/ofAppGLFWWindow.cpp at the display logic around line 304, then inspect the ofSaveScreen(), ofSaveFrame(), and ofImage::grabScreen() paths described in the issue. Reproduce the supplied example on Windows with automatic background clearing disabled and compare front/back buffer behavior. Done means screen captures contain the displayed drawing instead of a gray image without breaking the existing single-buffering workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100