Skip to main content
gamedev.net
🔒 Locked

Alpha testing

Started by Nemesis2k2 2 replies 600+ views
Original Post
Nemesis2k2
Nemesis2k2
I''m trying to get my text class fully working, but I''ve run into some unexpected difficulties with the alpha testing. First of all, let me tell you what I have. I have a full image of the font I''ll be using, along with an alpha channel to mask the areas I want to appear as transparent, all stored in a TGA file and being loaded by my program. I know the lapha channel is there, and I know it''s being successfully loaded. I checked the file myself manually, and it''s storing RGBA components for each pixel, and I also doublechecked the first few pixels as the TGA loader was reading them. The alpha channel itself consists of only full opacity and zero opacity values. There are no semi-transparent pixels. Now, I can get the thing to work if I use blending, specifically using the lines:
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
However, if my undersanding of how alpha testing works is correct, I shouldn''t have to resort to using a blend at all. This should work fine:
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.0);
When I use this however, The whole image is rendered, as well a the parts that should be discarded by the alpha test. I know the test is working however, as if I set glAlphaFunc to somthing like == 0.5 then rescale all the alpha components in the texture using the glColor command, it has the same affect of rendering the whole image. It seems that the alpha test seems to think that every alpha value is set to 1.0, while the blending function works correctly. I''ve spent a few days running around in circles, testing everything I can think of and reading and re-reading every command definition in the referance manual, but I can''t for the life of me figure out why this isn''t working. As far as I can tell it should be. If anyone has any idea where I could be going wrong, please let me know.
Raduprv
Raduprv
quote:
Original post by LockePick
Might be a wild shot, but try:
glAlphaFunc(GL_GREATER, 0.9f );


That f is not necesary, it works very well without it (OpenGL uses only floats anyway, so doubles should be converted to floats)
Anyway, setting the alpha test value to 0.0 or 1.0 defies the very purpose of alpha testing, it would either allow or deny everything.

Height Map Editor | Eternal Lands | Fast User Directory
Nemesis2k2
Nemesis2k2
quote:
Anyway, setting the alpha test value to 0.0 or 1.0 defies the very purpose of alpha testing, it would either allow or deny everything.

No, it''s not. The operation it''s performing when you use glAlphaFunc(GL_GREATER, 0.0); could be thought of as:


if(incoming_fragment > 0.0)
{
drawfragment();
}
else
{
discardfragment();
}


For what you''re thinking of to be true, you''d need to combine two of the parameters in the call glAlphaFunc(GL_LESS | GL_EQUAL, 1.0); or glAlphaFunc(GL_GREATER | GL_EQUAL, 0.0);. The normal comparison being made is >, not >=.

Anyway, I''ve tried what must be every kind of setting you can use for this command, to no avail.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.