PDA

View Full Version : Texture font problems (blending?)



kaysoft
10-25-2002, 06:21 AM
Hello, I finally implemented texture fonts in my engine, but when rendering text, the background is shown, even if i use 1 of alpha. The blend type i use is GL_SRC_ALPHA and GL_ONE. It is like the clear color of my background is blended with the text color. Any ideas?

*Aaron*
10-25-2002, 08:30 AM
Of course your text is being blended with the background. That's what that blending mode does. You want to use src=GL_SRC_ALPHA and dst=GL_ONE_MINUS_SRC_ALPHA for your blending function.

Leyder Dylan
10-25-2002, 01:15 PM
First, you must always display your Font at the end of your DrawGLScene.

// We display the text on the screen
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);
// Draw your text
glDisable(GL_BLEND);

Leyder Dylan
10-25-2002, 01:18 PM
You don't need to use the alpha test if you use our method.

kaysoft
10-26-2002, 02:57 AM
No, none of those worked. Auron, your solution doesnt make the black transparent, so it is no use.
I do render the text after all my geometry. Uh... Im confused here..

*Aaron*
10-26-2002, 11:47 AM
Oops, I assumed that you were loading the texture either as GL_RGBA or just GL_ALPHA. And I thought by "background" you meant what was drawn to the framebuffer before the text. If you want the font to be only one hue, then load it as GL_ALPHA. You have to convert the image to grayscale first. Then, before drawing, specify the color you want your text to be with glColor*. If the font has multiple hues, load it as an RGBA texture. Of course, with this method, the image you use as the texture must have an alpha channel, or you must generate one procedurally. The alpha channel could simply be the average intensity of the color components, thus giving the black background a value of 0. Set the texture application mode to GL_MODULATE. Call glColor3f(1,1,1) before drawing.

Now about the blending mode thing. You were using additive blending (dst=GL_ONE). This means that what is already in the framebuffer will always be added to the text that you draw, no matter what alpha value you specify. Using dst=GL_ONE_MINUS_SRC_ALPHA, however, will make a pixel completely replace the pixel behind it when it's alpha value is 1. I'm not sure which of these blending modes you are looking for. I think that additive blending might actually look better in this case, but I'm not sure. If you read about the blending equation in the spec, you can figure out what the different blending modes do.


First, you must always display your Font at the end of your DrawGLScene.

// We display the text on the screen
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);
// Draw your text
glDisable(GL_BLEND);This appears to be exactly what he was doing already.

kaysoft
10-27-2002, 12:41 AM
Ok thanks everyone, you've been most helpful http://www.opengl.org/discussion_boards/ubb/smile.gif

I will try your solutions Aaron!