PDA

View Full Version : Question about texture transparent effect



CGDeveloper
06-12-2003, 04:43 PM
I have a question as following:
A texture has been displayed in the screen, now i wanna display another small texture in some place on it (such as fade in/out). The color of the small texture's part is BLACK,and i want this part is tranparent.How can i blend them or realize this effect?
Thanks!

jwatte
06-12-2003, 07:15 PM
By selecting the appropriate glBlendFunc() and enabling GL_BLEND.

Write out the math you want the final pixel value to have (i e, something like "finalColor = firstPixel*(1-secondAlpha)+secondPixel*secondAlpha") and then determine how that can be done with BlendFunc.

CGDeveloper
06-12-2003, 07:42 PM
Thank you for your help!
I use Blend and i get the transparent effect,but there is some strange phenomena
in the transparent place that seems something covers the background picture.Why?

knackered
06-13-2003, 01:53 AM
Let's get this straight. You want black pixels in your texture to be transparent, while every other colour should not be transparent?
As far as I'm aware, there's no way of doing this with unextended opengl. You have to create an alpha channel in your texture, so instead of using a texture format of RGB you would use a texture format of RGBA. Now scan through your texture, putting a 1 in the alpha channel whereever the equivalent colour is not black, and a 0 in the alpha channel whereever the colour is black.
Then, issue these commands before drawing.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);