Alpha Blending in Ortho 2D mode

Started by
2 comments, last by jonzy_x86 14 years, 8 months ago
I'm having some trouble getting my textures to blend correctly with alpha in Ortho mode. My texture loading code set black pixels to have 0.0f alpha and non-black pixels to have 1.0f alpha. Now, if I use: glAlphaFunc(GL_GREATER,0.1f); glEnable(GL_ALPHA_TEST); Then I can render the image whilst omitting the black areas as transparent, but all other pixels in that image are opaque. However... If I want to render the whole image as translucent then there is a problem: glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glColour4f(1.0f,1.0f,1.0f,1.0f); RenderImage(); The above code works, but the image appears to be semi-transparent, as if the alpha is set to 0.5f; And then... glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glColour4f(1.0f,1.0f,1.0f,0.3f); RenderImage(); Is almost completely invisible. Lighting is off. Any ideas?
Advertisement
You don't accidently have the clear color of your scene set to alpha 0.5f?
Just in case you set it somewhere else, you should make sure that the blend equations is FUNC_ADD. So, in your code, call something like that :

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glEnable(GL_BLEND);

Also, you don't need to call glColor (by-the-way, glColour does not exist) if you setup your texture environment to GL_REPLACE, for instance : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
(note: glTexEnv is deprecated in OpenGL3.0)

What is the texture environment mode in your program ? Or maybe you were using a fragment shader ?

Apart from that, the code looks fine, there should not be any problem in theory. Have you tried to run the same program on another computer (more precisely, another graphics card and/or another graphics driver) ?

[Edited by - vincoof on August 17, 2009 9:24:40 AM]
Thanks for the replies...

I've had a mess around with the code and the following code...

glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);

Renders non-black pixels opaque.

But this code...

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glEnable(GL_BLEND); // Turn blending on
glDepthMask(GL_FALSE); // Disable the depth mask

Just renders the image as semi-translucent still.

glBlendEquation is an unknown function and throws an error.

I don't know about texture environments or fragment shading, I am still learning about GL, thanks.

This topic is closed to new replies.

Advertisement