Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Texture font problems (blending?)

  1. #1

    Texture font problems (blending?)

    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?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    245

    Re: Texture font problems (blending?)

    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.

  3. #3
    Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    481

    Re: Texture font problems (blending?)

    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);

  4. #4
    Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    481

    Re: Texture font problems (blending?)

    You don't need to use the alpha test if you use our method.

  5. #5

    Re: Texture font problems (blending?)

    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..

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    245

    Re: Texture font problems (blending?)

    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.

  7. #7

    Re: Texture font problems (blending?)

    Ok thanks everyone, you've been most helpful

    I will try your solutions Aaron!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •