fboTrailsExample without using FBOs?


When I use an FBO I can define its image type (ex.: OF_PIXELS_RGBA). Can this be done for the main window?

My problem:

I’m creating a drawing adding thousands of transparent layers of a very transparent black (0,0,0,1). Theoretically, after 256 layers applied to a pixel its color should be opaque black (0,0,0,256). But it tends to grey and stays there.

This has been discussed here:

And @arturo suggested looking at example gl/fboTrailsExample which I did. This example describes something very similar to what I’m experiencing.

But all this applies to FBOs.
I was wondering if total black can this be achieved without FBOs, only by drawing directly to the screen. Can it?


This is what I mean:

void ofApp::setup(){

void ofApp::update(){

void ofApp::draw() {
  ofDrawRectangle(0, 0, 100, 100);
  ofDrawRectangle(100, 0, 100, 100);

And I get this result:

While I’d like the left square to reach 255 black, it stops darkening at 127.

Since your background is white, you want to progressively subtract from it.

    ofSetColor(ofColor::white, 1);
    ofDrawRectangle(0, 0, 100, 100);
    ofDrawRectangle(100, 0, 100, 100);

For more info on blendmodes you can see here LearnOpenGL - Blending and Anders Riggelsen - Visual glBlendFunc and glBlendEquation Tool


Ahhhh!!! Thank you so much @dizzy! What you explained makes total sense but it would probably have taken me ages to figure it out by myself.

I’m so happy! This was melting my brain and blocking my work.

Thank you also for the references. I will read the tutorial. Actually, before I posted the question, I had already played with Anders’s simulator to help me try to find the solution to my problem and did several code experiments based on what I tried there. But since my scenario is iterative, I wasn’t able to find the solution.


Ok now it seems I’m stuck again trying to do the opposite. When it ends I would like to fade to white.

I tried to add (OF_BLENDMODE_ALPHA) the transparent white (ofColor::white,1) again multiple times to the whole screen but I got the weird averaged greys again. Of course OF_BLENDMODE_SUBTRACT faded to black perfectly but that’s not what I want.

I also tried subtracting (OF_BLEND_SUBTRACT) black (ofColor:black, 1) just for fun but nothing happened as I expected.

Any suggestions?

Thanks again!

PS. I tried messing around in the simulator but, again, since this is iterative, it’s harder to reach an enlightening conclusion. Besides, I think some of the options are no longer working correctly.

Hey I tried this out and I think just changing OF_BLENDMODE_SUBTRACT to OF_BLENDMODE_ADD will incrementally add transparent white and fade from black to white. Thanks for your reply @dizzy! II had a hard time figuring this out too when I played around with it but now it makes perfect sense.


Now I’m feeling silly. Somehow I assumed OF_BLEND_SUBTRACT was the opposite of the default OF_BLEND_ALPHA and, because of that, failed to notice that there is an OF_BLEND_ADD!

Thank you @TimChi! That did the trick.