Inconsistent alpha values

Hi All,

I have one semi-transparent green cube on white background drawn using the glEnable(GL_BLEND) without touching the glBlendFunc() settings.

// color settings
glClearColor(1,1,1,0); // alpha is zero
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, new float[] { 0, 1, 0, .5f});

I capture this scene using a glReadPixel and a 32bit bitmap with alpha channel support and save the bitmap in *.png format.

I open the bitmap in Photoshop an see the image with the typical checkerboard backgorund: the image is semi-transparent. I set a white canvas for image comparison.

What I don’t understand is why if I use:

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, new float[] { 0, 1, 0, .9f});

the transparency is almost similar,

while if I use:

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, new float[] { 0, 1, 0, .1f});

the transparency is very different: the cube is completely tranparent.

Any idea?

Thanks and happy new year!


Look at the actual value. You may be perceiving the effects of a non-linear color space or an actual conversion somewhere. You can specify per vertex alpha to ensure you are getting a range of values but how linear they appear after blending in photoshop is a very complex issue that involves more than just destination pixel alpha.

Hi dorbie,

Sorry for the delay in my answer, but I don’t receive notifications from this new OpenGL forum.

I discovered that if I used the following clear color:

// color settings
glClearColor(1,1,1,1); // alpha is one

The two images match, but I loose the transparent background.

BTW, the thing I don’t understand is:

If I draw a 50% transparent background on a solid white background, why should it appear different to draw it on a transparent background and placing a solid white rectangle underneath it?

In a certain way the differences I see are consinstent with the gl.ONE_MINUS_ALPHA default settings, I see more difference with alpha 0.1 (1-0.1=0.9) then with alpha 0.9 (1-0.9=0.1). BTW using a destination color of gl.ONE alters everything in a way I cannot understand either.

Happy 2008 to everybody!


Hi All,

After studing many hours, looks like there is no way to generate a transparent background image from a solid background scene.

Semi-transparent areas will always be different from what you see on screen. If the destination alpha value is zero all the glBledFunc computations are different from what you get with destination alpha one.

We are very sad to unfulfill this dream, but no solution was found.



Please write out a single-pixel math example of what you “want” to have happen.

Rescanning your messages twice, I still don’t get what you want to have happen mathematically.

All I can figure from the above-quoted statement is that you want alpha blending without alpha writing. If so, use only source alpha for blending (typical), and mask out writes to the alpha channel with glColorMask.

I wouldn’t bother, he’s probably on strike today. They strike a lot in italy.