I’m designing a relatively simple 2D app using OpenGL and I’m having issues with the transparency of an item.
This item is supposed to float above all other objects (older and newer) and thus I gave it a z value of 1 while all the other objects have a z value of 0.
The problem is that over the older items the blending is done correctly with a value of 0.6 but over the newer ones there is no blending at all.
I beleieve this is a really simple problem but I don’t know enough to solve it. Can you help??
I’m guessing that you haven’t disabled the depth buffer. When you’re drawing the ‘newer’ items (which are behind the closer ‘floating’ one), they just aren’t rendered because the depth-buffering algoritm thinks they are obscured by the ‘floating’ one.
Try disabling the depth buffer ( glDisable(GL_DEPTH_TEST) ) and see if that helps.
By the way, if several transparent items overlap you may need to depth-sort them first to get the right colour blending (e.g. yellow blended with red looks different that red blended with yellow).
You have to draw the transparent object last. Because, whenever an overlapping, non-transparent object is drawn afterwards, it’s fragments will either be discarded through z-test, or completely replace the transparent object.
Blending is only effective while it’s enabled (while the transparent object is drawn), and can only blend against what is already in the color buffer.