I am attempting to put together a simple program that just displays two textured quads overlapping each other, and the textures have alpha channels.
I have successfully been able to get the quads themse开发者_C百科lves to display, and the textures look correct except for the transparency.
On this topic, the GL_BLEND flag does not seem to do anything at all, whether it is enabled or not. Is this particular flag inapplicable when shaders are being used?
I know for a fact that the alpha is being rendered in correctly, since if I set out_color = texture.aaaa, I get a nice pattern of blacks/whites/grays that match the original texture.
So, if GL_BLEND doesn't work, what are the usual methods for getting alpha blending working?
All that glEnable(GL_BLEND)
does is turn blending on and off. It does not say what the blending will do; that is controlled by the various blending functions. If you want a typical alpha transparency blend, you do this:
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
If you use pre-multiplied alpha (and you probably should), you would do:
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
精彩评论