Results 1 to 2 of 2

Thread: texture blending problems...

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    11

    texture blending problems...

    Hello all,

    I am trying to blend 2 textures (applied to the same plane), both of which contain transparent areas.

    The way I do it now is with two passes:
    if(pass==0)
    {
    glBindTexture(GL_TEXTURE_2D, openGLName[0]);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);

    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE );
    }
    else
    {
    glBindTexture(GL_TEXTURE_2D, openGLNam [1]);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);

    glBlendFunc(GL_DST_ALPHA,GL_ZERO);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    }
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_NOTEQUAL,0);

    I first apply the first texture and on top of it I blend the second. What seems to happen though is that the second texture covers and hides the transparent regions of the first one, something that shouldn't happen with a (GL_DST_ALPHA,GL_ZERO) blending function.

    Am I right, or if not what am I doing wrong??

    Thanks a lot for any help!!

    Kostas.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    Re: texture blending problems...

    you should read up on the equation on blendFunc

    glBlendFunc(GL_DST_ALPHA,GL_ZERO);

    that will be srcFragment*destAlpha + destFragment(the frame buffer)*0

    so you will replace everything on the screen with srcfragment*destAlpha, and if destAlpha isnt present ( very common on older cards) i think you will get 1 there every time, so basically youre replacing the framebuffer with the new texture.

    i think you want
    (srcFragment * srcAlpha) + (destFragment * invsrcAlpha)

    that is
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Similar Threads

  1. Replies: 1
    Last Post: 05-01-2013, 09:37 PM
  2. Problems with fbo's and blending
    By memo in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-27-2009, 04:54 PM
  3. Texture font problems (blending?)
    By kaysoft in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-27-2002, 01:41 AM
  4. Blending Problems
    By jono_123 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-05-2002, 02:53 AM
  5. Problems with Blending
    By d_christop in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-03-2002, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean