openframeworks / openframeworks/openFrameworks
ofClear / ofBackground not working properly
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
I posted this in the forums and it was suggested that I repost it here as an issue.
I am getting some strange behavior when I turn off automatic clearing (ofSetBackgroundAuto(false);). I am prepared to believe that I’m doing something wrong, but the behavior seems like a bug.
I refined this down to a simple sketch that draws a new circle in a random location in each pass of the draw loop. There is a noticeable flicker as the circle count increases, which was a little surprising. However, the real buggy behavior is I have it configured to clear the screen when any key is typed. To make it really obvious I also change the circle color.
What I expect: the screen will slowly fill in with little circles of one color. When I press a key, the screen will clear and I will get a new collection of circles in the new color.
What I get: the screen doesn’t clear so I can see circles of both colors. However, it is weirder than just not working – it seems to partially clear. Some circles go away. If I clear enough times in rapid succession I can get it completely clear. At a conceptual level, it looks like we are double buffering and the clear only clears one of them (the flicker also seems to line up with multiple buffers that don’t both have the same information).
Here is my test code:
ofColor currentColor;
void changeColor(){
currentColor.set(ofRandom(0,255),ofRandom(0,255), ofRandom(0,255) );
ofBackground(0);
}
//--------------------------------------------------------------
void ofApp::setup(){
ofSetBackgroundAuto(false);
ofBackground(0);
changeColor();
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(currentColor);
ofFill();
ofDrawCircle(ofRandom(0,ofGetWidth()), ofRandom(0,ofGetHeight()), 3);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
changeColor();
}
I tried turning off double buffering and it helped with the flicker problem and clearing work more often, but not all of the time. Sometimes the previous drawing will remain, and more bizarrely, sometimes a previous drawing that was cleared will return.
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 with the minimal sketch in the issue and reproduce the behavior using ofSetBackgroundAuto(false), ofBackground(0), and the draw loop. Investigate the rendering and double-buffering entry points used by these APIs, then verify that clearing on key presses removes prior circles consistently without flicker or resurrected drawings.
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
- Mostly clear
- Newbie friendliness
- 35/100