Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: problem with transparency

  1. #1
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    problem with transparency

    I have 2 cubes, one is closer, second is further. When I look at straight ahead closer and further cubest looks strange (closer cube is too much transparency), when I rotate camera about 270 degrees second cube looks ok (it isn't so transparent like first one):

    http://img34.imageshack.us/i/55489397.jpg/

    What is going on ?
    My code:

    Code :
    //here draw some other objects
     
    glDepthMask(GL_FALSE); 
    glEnable(GL_BLEND);	
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    //here draw closer cube
     
    glDisable(GL_BLEND); 
    glEnable(GL_DEPTH_TEST); 
    glDepthMask(GL_TRUE);
     
    //here draw other objects
     
    glDepthMask(GL_FALSE);
    glEnable(GL_BLEND);	
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    //here draw further cube
     
    glDisable(GL_BLEND); 
    glEnable(GL_DEPTH_TEST); 
    glDepthMask(GL_TRUE); 
     
    //here draw other objects

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: problem with transparency

    Blending does not work with depth testing.
    Search the forum / the web / the wiki for details, any solution will be a "performance versus visual quality" tradeoff.

  3. #3
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    Re: problem with transparency

    But when I glDisable(GL_DEPTH_TEST) then mine cubes are always closer then other objects - effect is horrible. I have strong computer so I don't need to performance - what is the solution ?

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: problem with transparency

    Did you do what ZbuffeR said and do a search?

  5. #5
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    Re: problem with transparency

    Before I had written here I searched.

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: problem with transparency

    First, in any case, opaque objects "//here draw other objects" should be drawn FIRST. This is extremely basic stuff, and you have not done it...
    So what other information did you learn from your searches ?

  7. #7
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: problem with transparency

    Before I had written here I searched.
    Why do people think they can say "I searched" when it's so easy to show they didn't? Google for "blending depth buffer". The very first hit explains your problem in detail and the solution to it.

  8. #8
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    Re: problem with transparency

    Thx it works but http://www.sjbaker.org/steve/omniv/alpha_sorting.html

    "The first fix - upon which all the other fixes depend is to make sure you draw all your opaque polygons before you draw any translucent ones. This is easy to do in most applications and solves most of the problems. The only thing that remains is when you try to render one translucent polygon behind another."

    Strange - for me it works when I draw first transparent objects and then not transparent - why ? And in this article they said that I should first draw not transparent and then transparent.

  9. #9
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: problem with transparency

    Quote Originally Posted by alex2
    Strange - for me it works when I draw first transparent objects and then not transparent - why ? And in this article they said that I should first draw not transparent and then transparent.
    ....and if you change your field of view (ie rotate the scene or camera position)? I bet it does not work after that.

  10. #10
    Member Newbie
    Join Date
    Feb 2011
    Posts
    37

    Re: problem with transparency

    hm yes..... you know something - could you tell ?

Page 1 of 2 12 LastLast

Similar Threads

  1. Transparency problem
    By betwixt in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-14-2010, 09:09 PM
  2. Transparency problem
    By Floware in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-10-2005, 02:18 PM
  3. Transparency problem
    By Viper00 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-26-2003, 08:46 AM
  4. problem with transparency
    By dcd in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 08-14-2002, 05:01 AM
  5. Transparency problem
    By Roach in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-05-2000, 05:22 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