Results 1 to 4 of 4

Thread: Problems with glBlendFunc()...

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Problems with glBlendFunc()...

    Hi,

    I want to draw two textures on two planes. Both should be partially transparent. So it should be possible to see e.g. plane a through the transparent region of plane b.

    This works good, if I use:
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0);


    But if I use:
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    instead it only works from one direction. It is only possible to see the first drawn plane through the second drawn plane.

    So it depends on which plane is drawn first.
    I enabled GL_DEPTH_TEST.

    Does someone has an idea why it doesn't work?

    Thank you for your help,

    Michael

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678

    Re: Problems with glBlendFunc()...

    I enabled GL_DEPTH_TEST.
    That's why.

    Alpha test is not the same as blending. Alpha test actually culls the pixels, so that the depth buffer never gets written. It punches holes in the polygon, so to speak. Blending is simply combining one color with whatever happened to be there at the time.

    If you draw one polygon behind another with depth test on, it culls the pixels from the second polygon because their depth value is farther away. This doesn't stop happening just because you turn on blending.

    This is why, when you use blending, you must sort all triangles by depth. And you must turn off depth testing.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Re: Problems with glBlendFunc()...

    Thanks a lot. So there is no other way to do this but ordering or using the glAlphaFunc?

    Thanks a lot,

    Michael

  4. #4
    Senior Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    435

    Re: Problems with glBlendFunc()...

    Usually I disable depth writing (glDepthMask(0)) for transparent objects, keeping depth testing on.
    This will guarantee both transparent planes to be drawn in your case.

Similar Threads

  1. glBlendFunc
    By mikethebike in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-16-2011, 05:55 AM
  2. glBlendFunc help please....
    By Al Grant in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-17-2006, 10:29 PM
  3. glBlendFunc
    By MasTrO in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-13-2004, 11:07 AM
  4. glBlendFunc
    By HairyFotr in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-22-2003, 12:30 AM
  5. glBlendFunc?
    By Kondrat in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-28-2000, 04:26 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