Why does ofBackgroundGradient not work when called in setup()?

I’m getting started with OF tonight, and I came across a reference to ofBackgroundGradient in one of the tutorials. I first tried using it within setup() and found that it didn’t work – I had to put it within draw()? Can you explain to me why that’s the case? I would have expected it to work just like ofBackground().

Thanks!
Kevin

I was just wondering the same thing. It would be nice to have it working on update too :smile:

yes that might be kind of confusing, the reason is that while ofBackground is calling a GL function to actually clear the screen, glClear, and it’s set so it automatically clears the background every frame, ofBackgroundGradient was added much later and just draws a gradient so when draw happens it clears the whole screen clearing the gradient too. it probably shouldn’t have been called ofBackgroundGradient and just be a function to draw a gradient like ofDrawGradient so it’s clearer what it’s really doing

I was also wondering how to get rid of the stripes/steps that it creates. They are more obvious if you do like ofBackgroundGradient(50, 40); there should be a way to apply some little noise so that the gradient is actually smoth… any hints that I could try?

(Maybe i should open a new topic) …

Oh… I see it is a VBO…? so how could I smooth that out? I’m totally lost here…

i guess you can use an fbo with 32bits floats instead of 8bit, that should help also as you say doing some dithering by applying some noise should make it less noticeable too

1 Like