PDA

View Full Version : about trimming a texture



dbsboy
04-03-2003, 09:32 PM
Hi I'm new to this board. I've tried searching the forum for previous post about this topic but can't seem to find any.

here's my problem, I have a pink background bmp file and I've set the alpha to 0 for those pink pixels, now major pink parts are gone but there appears to have a slight pink edge.

i've used the following function

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);

Can anyone tell me what my problem is?

JustHanging
04-03-2003, 10:15 PM
Set the new color values of all your pink texels to tha average of their adjacent non-pink texels. If there aren't any, just make the texel black.

-Ilkka

dbsboy
04-04-2003, 06:50 AM
thanks!
but i'm still wondering, isn't the pink edge caused by blending? so shouldn't i be able to eliminate it by disabling blending? (i don't mind the cut edges)

but when i tried that i got an even thicker pink outline...

please correct me if i'm wrong

Ysaneya
04-04-2003, 07:11 AM
No, it appears because of the bilinear filtering. Filtering works by sampling neighbooring texels and averaging them. As a result, if you only specify texels with an alpha of 0 (transparent) and 1 (opaque), you can still end up with pixels in the [0-1] range. Near the pink contour, you can have a pixel with 0.2 alpha (which passes the alpha test), but that's still an average of a few pink texels and a few opaque texels.. this leads to pink halos around your objects.

You can disable filtering, or replace the transparent pink texels with the closest opaque texels, as JustHanging suggests.

Y.

Raduprv
04-04-2003, 01:21 PM
You might want to use only alpha testing, not alphablending, which is slower.
So, use something like:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
(and remove the blending part)

dbsboy
04-06-2003, 11:27 AM
thanks alot!
that really helps!

[This message has been edited by dbsboy (edited 04-06-2003).]