Set colour to no colour -- isolating styles ofPushStyle() and ofPopStyle()

How to set ofsetcolour() to no colour?

There is no way to set “no color”, but you could make the current color transparent.

ofSetColor(ofColor(0, 0, 0, 0)); // red: 0, green: 0, blue: 0, alpha: 0

Does this also make a background image transparent?

You can “tint” (i.e. like tint() in Processing) an image in processing by calling ofSetColor(...) before calling img.draw(...).

void ofApp::draw()
{
    ofSetColor(255);
    img.draw(0, 0);

    ofSetColor(255, 127);
    img.draw(100, 100);

    ofSetColor(255, 0);
    img.draw(200, 200);

}

I have a background canvas image that I dont want to get affected by ofsetcolor. How do i manage that?

You can explicitly set color each time before you draw your background image …

void ofApp::draw()
{   
    // Draw background image.
    ofSetColor(255);
    backgroundImage.draw(0, 0);

    // Draw whatever else.
    ofSetColor(255, 127);
    img.draw(100, 100);

    ofSetColor(255, 0);
    img.draw(200, 200);

}

or you can use ofPushStyle() / ofPopStyle() to isolate your styles.

1 Like

Thank you! ofPushStyle() / ofPopStyle() did the trick!

1 Like