Per-pixel contrast control using fixed pipeline

40 Views Asked by At

I'm using fixed-pipeline rendering, and would like to control the contrast of my images (i.e., difference from background) in a per-pixel manner. In other words, if C is R/G/B, I'd like to get

C = A*Cs + (1 - A)*C0

where C0 is the background color, and A can vary from pixel to pixel. If the background is black (C0 = 0), I know how to do this: first set the alpha in the framebuffer to what I want on a per-pixel basis, then

glBlendFunc(GL_DST_ALPHA, GL_ZERO)

If the background isn't black, then you can set the alpha, clear the color to background, and do

glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA)

This works only if none of the objects you draw overlap; in case of overlap, the framebuffer value is no longer the background color, and therefore you no longer get C = A*Cs + (1 - A)*C0.

Is there some obvious way to do this that I'm missing? Maybe I shouldn't use alpha blending but something else?

0

There are 0 best solutions below