Sign in to follow this  
shane1985

Alpha Testing Question (screenshot)

Recommended Posts

I'm working on creating an inventory system for my game, and I'm running into this problem: When I draw the items, they have a pink outline around them some of the time, and I don't know what's causing this behavior. My alpha function looks like this and I've enabled alpha testing: glAlphaFunc(GL_GREATER,0.1f); but if I move the value higher, it gets rid of the pink outline. However, this causes other parts of my game that have in between values to be rendered incorrectly. There's no problem with the image, as all pixels with the pink (255, 0, 255) color are set to an alpha value of 255, so .1 should work for these images. Anyone have any idea how I can solve this? Screenshot (Notice the left item) -Shane

Share this post


Link to post
Share on other sites
This is because of texture filtering, so the pink transparent texels get filtered with the neighboring opaque texels, creating a pinkish texel that is slightly transparent.

The easiest way to fix this is to use GL_NEAREST filtering mode on your textures, but then you obviously lose the nice texture filtering. If your textures are sized correctly so that one texel maps to one on-screen pixel than it won't matter, but that's probably not the case.

The nicest (in my opinion at least) but slightly more difficult way to fix this is after you load the image data, loop through it and "bleed" the colors from texels on the opaque/transparent border a few pixels into the transparent part. Then when you filter on the border, it will filter with the same color instead of with pink.

It might be easier to just take that into account when you are creating your images and use an image format that supports an alpha channel (such as TGA or PNG).

Good luck!

Share this post


Link to post
Share on other sites
Quote:
Original post by renderer
you might want to change the pink pixels to black when you initially create your textures, instead of just setting the alpha to 0.
That would just make the border blackish instead of pinkish. True, it's much less noticeable than pink and will probably be acceptable, but it's still not "correct."

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Quote:
Original post by renderer
you might want to change the pink pixels to black when you initially create your textures, instead of just setting the alpha to 0.
That would just make the border blackish instead of pinkish. True, it's much less noticeable than pink and will probably be acceptable, but it's still not "correct."

Better would be to set the transparent texels to the same color as the nearest opaque texel. It's only necessary to set the border texels though, not all transparent texels.

Share this post


Link to post
Share on other sites
Probably you are using Magenta as your colorkey. If your texture is made in photoshop or any program that works with layers, its possible that the outline of your icon has alpha values of 50%. In order to reduce this problem, use black as your color key and define the transparrency using alpha.

Luck!
Guimo


Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Quote:
Original post by renderer
you might want to change the pink pixels to black when you initially create your textures, instead of just setting the alpha to 0.
That would just make the border blackish instead of pinkish. True, it's much less noticeable than pink and will probably be acceptable, but it's still not "correct."


Perhaps, but if he turns on blending in the right way (additive) then black blending with X = X. This should give him the correct values he wants.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this