Quantcast
Channel: bugs, errors - openFrameworks
Viewing all articles
Browse latest Browse all 636

ofClear / ofBackground not working as expected

$
0
0

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).

I am using a brand new MacBook Pro (M1 Pro) running Monterey, so it could be an untested configuration as well.

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();
}

It would be great to know if this is a bug or a misapprehension of mine (I am new to OF, but not graphics/code sketching).

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 636

Trending Articles