View Full Version : make some pixels transparent
05-25-2006, 06:15 PM
I draw two rectangles and one is in front of the other. The rectangles have mapped textures on them and i want to make the pixels of the one rectangle to be invinsible(set alpha 0), so the other rectangle can be shown. The pixels that i want to change are the ones that cover the rectangle, not all.
Any ideas on how to do this?
Of course, the easiest (for me) way is mapping a rectangle with a tga texture with alpha channel (painting in the alpha channel where u want transparency).
Then you enable blending in opengl.
//you setup a blending equation
//Draw the transparent rectangle
//Draw the solid rectangle
For better understanding about how glBlendFunc works take a look to the red book, it's easier than it seems at first glance :)
The other alternative is using alpha test, that u can see in the red book too :)
Hope this helps,
05-26-2006, 03:46 AM
Alpha testing is better, simpler and faster if you do not need blending, so try it.
//draw only pixels with alpha > 0.5f
glAlphaFunc(GL_GREATER, 0.5f);Note that if pixel has alpha < 0.5 then it will not be drawn nor the z-buffer will be updated - this will allow you to draw polygons in any order. Alpha blending requires drawing furthest polygon first and nearest at the end.
05-26-2006, 06:02 AM
I know how to do alpha test. My problem is how to set the pixels alpha to what i want. I dont want the whole rectangle to be invinsible, just part of it. The postitions of the rectangles are decided dynamically within my program.
My question really is How do you change the alpha of a texel?
you have to do it by setting the alpha in the texture file.
open your texture file with some image editor (photoshop, the gimp...), paint the alpha channel and save it as tga or png 32 bits with alpha channel added.
Alpha test is done per fragment, so you have to provide the alpha on a per fragment basis. And setting the alpha in the texture is the easier way.
05-27-2006, 07:43 AM
and if you want to whange it dynamically, just change data inside the array you pass to glTex[Sub]Image2D()
05-27-2006, 08:16 PM
thanx. I changed the data in the image i loaded cuz i needed to do it dynamically in the program. There is no way i can know before using the program, which areas i'll need to make invinsible.
Thanx everyone for responding
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.