Alpha problem

Hello …

I’m having a problem getting OpenGL to properly display a textured quad using an alpha channel.

Below is a blown-up picture showing the difference between what I get (left, using OpenGL) and what I want (right). The speckled stuff is a background.

Where the texture-image (whether a “.png” or a “.tif”) is completely transparent or completely opaque, OpenGL renders it properly. Not so in the transitional regions between transparent and fully opaque. (There’s a very faint, nearly transparent white glow about the top of the “peg”.) OpenGL makes those regions unusually dark.

The image is loaded as a 32-bit texture, blending is enabled. I’ve tried altering parameters of glBlendFunc() --the image shown uses glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)-- to no avail. I’m not sure what else to try.

This is in a custom OpenGLView in a Cocoa project in Mac OS X, using an ATi Rage 128 Pro graphics card (on an indigo iMac). Image loading code follows a NeHe tutorial.

Pointers?

Thanks,

DayLateDon

“OpenGL renders it correctly when it is completely transparent…” doest it means it disappears completely? What does this means exactly?

I am quite sure you already turned blending on, so I won’t bother you with that.

Have you tried to read buffer/image data to see if it is correct?

Are you sure your GL card actually supports that? For example, old permedia2 video cards does not support alpha testing, resulting in bad artifacts. I can remember some old ATi graphic cards had problems with some blendfuncs (basically, only some are supported), but I think this is not really the point.

Maybe post a url to the image…

Hello …

You’re right: forgot the image URL.

Again, left is the OpenGL render; right is what I want.

The “.tif” image I’m using for my texture (minus the shadow at the bottom), is here:
http://www.daylateanddollarshort.com/misc/bluePegg.tif

You can tell from darkened area what the general dimensions of the texture are. So, for instance, a couple of pixels left or right of the “peg” are in the texture, but are completely transparent (and are drawn --or not drawn?-- properly by OpenGL). And the darkened “halo” area at the top is partially transparent and seems to blend more or less properly … it’s just dark.

(Could it be the video card? The card does fine with all the graphic craziness Mac OS X throws at it.)

I hope that clarifies things.

Thanks for the help,

DayLateDon

[This message has been edited by DayLateDon (edited 03-24-2003).]

Hi,

It looks like your image has wrong color values at pixels with partial transparency. This happens easily in a paint program, since they usually export pre-blended colors. So if you have a black background (or even none at all), the background is shining through, spoiling colors at translucent pixels. You can fix this by using the same background color as the translucent parts are, in your case propably white. You could also fix the problem at load-time by dividing all values with their alpha, but that might lead to decreased precision at translucent parts.

-Ilkka

Hello …

It looks like your image has wrong color values at pixels with partial transparency. This happens easily in a paint program, since they usually export pre-blended colors.

The right half of my image shows the self-same .tif, with proper colors at the transparent places. (That half of the image isn’t composited in a drawing program, but taken from a screenshot in which the image is displayed in an “image view”.)

So, I don’t think the image file itself is a problem.

Perhaps I need to tinker with the texture-loading portion of my code.

Thanks for the input …

DayLateDon

[This message has been edited by DayLateDon (edited 03-24-2003).]