1
votes

I rendered multiple symbols onto a texture atlas whose background is totally transparent(the texture atlas image got alpha channel, RGBA formate). After that, I use the texture atlas to draw all the symbols so long as the symbols appeared on the texture.

The problem is when the rendered symbol is not rotated, everything is fine. However, the symbol color appear to be incorrect when it's been rotated.

As the following picture shows: the left arrow symbol is not rotated and rendered correctly. The color at the edge of the right symbol which is rotated has somehow changed.

What might cause this?

enter image description here

EDIT:

As @BDL suggested, I changed the parameter to:

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );

But some of the symbols still does not show as expected: Triangle Symbols

The triangle symbol on the right is correct.

I also tried:

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

Does not work either.

Should I change the color of the texture background the same as the symbols boundary pixel color and then use GL_LINEAR as texture filter option?

1
check your anti-aliasing technics - shan
What color are the transparent pixels in the source image? Black? White? - genpfault
@genpfault I don't get it. The correct rendered symbol has alpha value 1. and the source image has alpha value 0. Which color should I premultiply alpha on? Also the unwanted pixels I think are generated by linear interpolation. How could I control the blend function used in the interpolation process. Not quite understand the alpha premultiply :( - Shaobo Zi

1 Answers

0
votes

You are getting exactly the behavior one would expect when linear interpolation is used. Each fragment is a weighted interpolation of the four surrounding texels. Along borders, this interpolation produces semi-transparent pixels since it interpolates between opaque and transparent pixels. The gray borders comes from blending these semi-transparent pixel with the background.

If you want to disable linear interpolation, change the magnification filter of the texture by calling

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);