View Full Version : Questions on Blending with Textures

02-03-2007, 04:44 AM
Hi Guys,

I have a question on Blending I am hoping someone may be able to give me a hand with - or just some advice.

I have a number of texture map images (bmp files), which contain some portions of pure black colour. My desire to for OpenGL to not render parts of the texture map that are pure black, while rendering any part of the texture map that isnt black.

I have been playing around with the glBlendFunc call, but have not had any luck. The closest I have come has been not rendering the black components of the texture, and adding the colour components onto what has already been written to the destination - so the colour sections of my texture while visible, appear transparent - which isn't the desired effect.

Am I going along the right path with using the glBlendFunc call? Is there another method I have to use in order for OpenGL to not render black sections? I have tried using an alpha channel as well, although did not seem to have any luck there either.

Any ideas or suggestions would be great.



02-03-2007, 05:51 AM
I guess the easiest thing is to use GLSL and simply set the alpha fragment to 0 where the texture color is black.

Another thing is to use a different image format, say tga, use an image manipulator, say gimp, and set the alpha channel to 0 where color is black.

Hope that helps.

Joseph Steel
02-03-2007, 05:56 AM
When reading the bmp file you could add an alpha channel that is zero for black and one for non-black and then use a glAlphaFunc(GL_GREATER, 0.0) to discard any zero fragments in the rendering. One problem with this is if you are using some form of texture filtering. In that case you can generate texels with intermediate alpha values close to the black areas. You could use glAlphaFunc(GL_EQUAL, 1.0) in those cases.