PDA

View Full Version : blending problem



01-15-2002, 11:05 AM
I'm having trouble getting blending to do exactly what I want. I would like to blend as if I were working in the range [-1,1], so that (-.5)+(-.5)=-1.0 and .5+.5=1.0. The following code is as close as I have come with floats between 0.0 and 1.0. The two middle rows show two sets of two overlapping rectangles. The top and bottom rows of squares show the values I would like for the overlapping rectangles. The overlapping regions are currently 0.125 and 0.875 respectively and I would like them to be 0.0 and 1.0 respectively. Where the rectangles don't overlap I would like them to have the value 0.25 and 0.75 respectively, which they currently have.

When I tried working in GLbytes it seemed to clamp the values to between 0.0 and 1.0 before the blend operation. Can the negative range be used for blending?
Do I need a different blend function or equation?
Any other suggestions?

Thanks in advance for the help.

code:



void MyDisplay (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ZERO);
glColor4f(0.25,0.25,0.25,0.5);
glRectf(-0.7,-0.5,0.3,0.0);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.0,0.0,0.0,0.5);
glRectf(-0.3,-0.5,0.7,0.0);

glBlendFunc(GL_ONE,GL_ZERO);
glColor4f(0.75,0.75,0.75,0.5);
glRectf(-0.7,0.1,0.3,0.6);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0,1.0,1.0,0.5);
glRectf(-0.3,0.1,0.7,0.6);

glDisable(GL_BLEND);

/* desired values */
glColor4f(1.0,1.0,1.0,0.5);
glRectf(-0.1,0.7,0.1,0.9);
glColor4f(0.75,0.75,0.75,0.5);
glRectf(-0.7,0.7,-0.5,0.9);
glRectf(0.5,0.7,0.7,0.9);
glColor4f(0.0,0.0,0.0,0.5);
glRectf(-0.1,-0.6,0.1,-0.8);
glColor4f(0.25,0.25,0.25,0.5);
glRectf(-0.7,-0.6,-0.5,-0.8);
glRectf(0.5,-0.6,0.7,-0.8);

}
void MyInit (void) {
glShadeModel (GL_FLAT);
glClearColor(0.5,0.5,0.5,0.0);
glDisable(GL_DEPTH_TEST);
}