transparent polygons
I am trying to make some simple polygon objects fade from a set color [glColor3f(1.0f, 0.5f, 0.0f)] to black but transparently so that any other objects can be seen throughthem as they fade away.
I am currently using just the three colours (RGB) and reducing them by a set value each frame until they are all zero, but this gives me a solid black object that hides everything under it.
Do I need to use the alpha channel and GL_BLEND? can someone point me in the direction of a good tutorial that can help me please.
Yes, you do need to use the alpha channel and GL_BLEND...
You need to use glColor4f(r, g, b, a); to set your color - don''t change the rgb as you have been doing, just alter the alpha value from 1 (opaque) down to 0 (completely transparent).
You also need to glEnable(GL_BLEND); and there are also several permutations of glBlendFunc(a, b); that you can experiment with, I can''t remember the constants to plug into a and b off hand, but the default values (i.e. don''t call glBlendFunc) should give you a reasonable result...
To find out more, get a copy of the Red Book - it''s got a whole chapter on Blending.
You need to use glColor4f(r, g, b, a); to set your color - don''t change the rgb as you have been doing, just alter the alpha value from 1 (opaque) down to 0 (completely transparent).
You also need to glEnable(GL_BLEND); and there are also several permutations of glBlendFunc(a, b); that you can experiment with, I can''t remember the constants to plug into a and b off hand, but the default values (i.e. don''t call glBlendFunc) should give you a reasonable result...
To find out more, get a copy of the Red Book - it''s got a whole chapter on Blending.
To make something transparent using blending, you need to use the blend function:
Coding Stuff -> [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff -> [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]
[edited by - iNsAn1tY on May 2, 2003 9:22:02 AM]
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Then all you need to do is plug an alpha value into glColor4f() as mentioned above, and you have your transparency... Coding Stuff -> [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff -> [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]
[edited by - iNsAn1tY on May 2, 2003 9:22:02 AM]
I tried this, but it doesn''t work. I even tried the other blending functions and those won''t do it either. This only makes PURE WHITE be solid and BLACK be translucent. If you wanted to draw blue or green or red, it will make the black invisible, but you will also be able to see thru the colored image(font, for example) Unless you use masking.. Please tell me I''m wrong and/or show me something that proves it, I''ve seen about everything any demo site can offer and nothing gets around the need to use masking.. (except colorkeying maybe?)
I''d really like not to have to draw twice..
Take nehe''s font tutorial and try drawing the font blue, or even take it into photoshop and color the white blue, and you will see what I''m talking about.
I''d really like not to have to draw twice..
Take nehe''s font tutorial and try drawing the font blue, or even take it into photoshop and color the white blue, and you will see what I''m talking about.
You''re getting Alpha Blending confused with Alpha Testing, if you follow the above instructions and glEnable(GL_BLEND) then you will get the results you require, if you glEnable(GL_ALPHA_TEST) then you will get the effects you described.
Oh, then I guess I don''t, I test with glIsEnabled and if it is enabled my code disables it.. seriously, it doesn''t work for some reason.. Not like masking does
Sorted :o)
I have used glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) in my InitGL() function. I''m currently using the glEnable(GL_BLEND) and glDisable(GL_BLEND) either side of the code to draw my transparent polys, and it all works brilliantly.. just what I needed..
Thanks to all those who replied..
I have used glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) in my InitGL() function. I''m currently using the glEnable(GL_BLEND) and glDisable(GL_BLEND) either side of the code to draw my transparent polys, and it all works brilliantly.. just what I needed..
Thanks to all those who replied..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement