Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 7 123 ... LastLast
Results 1 to 10 of 64

Thread: transparency problem

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Apr 2002
    Location
    raanan israel
    Posts
    54

    transparency problem

    Hi,
    i am drawing two objects the first one is opaque , and the second one is semi transparent on a black
    background.
    the alpha factor of the opaque object is 1.0 and of the transparent one is 0.5
    i have the following problem :
    if i use the blending functions :
    glBlendFunc (GL_SRC_ALPHA, GL_ONE);
    or
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    I see only the opaque object and not the transparent one.
    if i use :
    glBlendFunc(GL_ONE ,GL_ONE);
    both objects appear but when they are one in front of the other
    the blended pixels turns white, and the transparent object turns white also in some angles when is just
    against the black background.(as if it reflects to much light even that the specular component is disabled)
    if i use:
    glBlendFunc (GL_SRC_ALPHA, GL_SRC_COLOR);
    I get good results when the transparent object is in front of the opaque object, but when the transparent
    object is on the black background it disappears !!! (if i change the color of the background to white
    it works great, but I need it black....)
    the display function is :

    GLfloat SurfaceColor[4];

    // Erase last list
    if (m_ListOpenGL)
    if (glIsList(m_ListOpenGL))
    ::glDeleteLists(m_ListOpenGL,1);

    // Search for a new list
    m_ListOpenGL = ::glGenLists(1);
    if(m_ListOpenGL == 0)
    return 0;

    // Start list
    unsigned int NbVertex = (unsigned int)m_ArrayVertex.GetSize();
    if(!NbVertex)
    return 0;

    unsigned int NbFace = (unsigned int)m_ArrayFace.GetSize();
    if(!NbFace)
    return 0;

    CFace3d* pFace;
    CVector3d* pVector;
    CColor* pColorPrevious;

    ::glNewList(m_ListOpenGL,GL_COMPILE_AND_EXECUTE);

    //the alph value of the mesh
    if(m_fTransperentLevel< 1.0)
    {
    //both objects appear but when are one in fron of the
    //other
    //the blendind turns white, and the transparent object is
    //white in some angles.
    //glBlendFunc(GL_ONE ,GL_ONE);
    //only the solid object appear, the transperent isn't
    //glBlendFunc (GL_SRC_ALPHA, GL_ONE);
    //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //works good but dissapear in black backround
    glBlendFunc (GL_SRC_ALPHA, GL_SRC_COLOR);
    glEnable(GL_BLEND);
    //turn off the depth buffer
    glDepthMask (GL_FALSE);
    }

    // Init color
    pFace = m_ArrayFace[0];
    pColorPrevious = pFace->GetColor();

    ::glBegin(GL_TRIANGLE_STRIP);
    // form the first two vertices of the N-2 triangle strip.
    SurfaceColor[0] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->r();
    SurfaceColor[1] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->g();
    SurfaceColor[2] = (float)1 / (float)255 * (float)pFace->v(0)->GetColor()->b();
    SurfaceColor[3] = m_fTransperentLevel;
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, SurfaceColor);


    pVector = pFace->v(0)->GetNormal();
    ::glNormal3f(pVector->x(),pVector->y(),pVector->z());
    ::glVertex3f(pFace->v(0)->x(),pFace->v(0)->y(),pFace->v(0)->z());
    pVector = pFace->v(1)->GetNormal();
    ::glNormal3f(pVector->x(),pVector->y(),pVector->z());
    ::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y(),pFace->v(1)->z());

    for(unsigned int i=0; i< NbFace-1; i++)
    {
    pFace = m_ArrayFace[i];
    // Normal (per face)
    if(m_NormalBinding == NORMAL_PER_FACE)
    {
    pVector = pFace->GetNormal();
    ::glNormal3f(pVector->x(),pVector->y
    (),pVector->z());
    }
    // Color (per face)
    if(m_ColorBinding == COLOR_PER_FACE &&
    pColorPrevious != pFace->GetColor())
    pColorPrevious = pFace->GetColor();
    // Normal
    if(m_NormalBinding == NORMAL_PER_VERTEX)
    {
    pVector = pFace->v(2)->GetNormal
    ();
    ::glNormal3f(pVector->x(),pVector-
    >y(),pVector->z());
    }
    // Color (per vertex)
    if(m_ColorBinding == COLOR_PER_VERTEX &&
    pColorPrevious != pFace->v(2)->GetColor())
    {
    SurfaceColor[0] = (float)1 /
    (float)255 * (float)pFace->v(2)->GetColor()->r();
    SurfaceColor[1] = (float)1 /
    (float)255 * (float)pFace->v(2)->GetColor()->g();
    SurfaceColor[2] = (float)1 /
    (float)255 * (float)pFace->v(2)->GetColor()->b();
    SurfaceColor[3] =
    if(m_fTransperentLevel< 1.0)
    {
    //change the transperent
    //object color from the
    //original color
    SurfaceColor[0] -= 0.4;
    if(SurfaceColor[0] < 0)
    SurfaceColor[0] = 0;
    SurfaceColor[1] -= 0.3;
    if(SurfaceColor[1] < 0)
    SurfaceColor[1] = 0;
    SurfaceColor[2] -= 0.1;
    if(SurfaceColor[2] < 0)
    SurfaceColor[2] = 0;


    }
    glMaterialfv(GL_FRONT,
    GL_AMBIENT_AND_DIFFUSE,
    SurfaceColor);

    pColorPrevious = pFace->v(2)->GetColor();
    }


    // Vertex
    ::glVertex3f(pFace->v(2)->x(),pFace->v(2)-
    >y(),pFace->v(2)->z());

    }
    //complete the last ring triangle strip
    pFace = m_ArrayFace[i-39];
    pVector = pFace->v(1)->GetNormal();
    ::glNormal3f(pVector->x(),pVector->y(),pVector->z
    ());
    ::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y
    (),pFace->v(1)->z());
    pVector = pFace->v(2)->GetNormal();
    ::glNormal3f(pVector->x(),pVector->y(),pVector->z
    ());
    ::glVertex3f(pFace->v(2)->x(),pFace->v(2)->y
    (),pFace->v(2)->z());
    pFace = m_ArrayFace[i-37];
    pVector = pFace->v(1)->GetNormal();
    ::glNormal3f(pVector->x(),pVector->y(),pVector->z
    ());
    ::glVertex3f(pFace->v(1)->x(),pFace->v(1)->y
    (),pFace->v(1)->z());


    ::glEnd();


    if(m_fTransperentLevel< 1.0)
    {
    glDepthMask (GL_TRUE);
    glDisable(GL_BLEND);
    }
    ::glEndList();

    // List is done now
    m_ListDone = TRUE;
    m_Modified = FALSE;

    return 1;

    any ideas ????
    thanks in advance

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: transparency problem

    wow.. lovely knacky..
    are you in love? or got payed holidays at work? or what?

    yeah, listen to knacky he tells you all you need to know. good luck on reordering your stuff.
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  3. #3
    Intern Contributor
    Join Date
    Apr 2002
    Location
    raanan israel
    Posts
    54

    Re: transparency problem

    >>I don't mean to offend you
    you didn't
    >>you have to draw transparent objects >>AFTER opaque ones, and they must be drawn >>in strict order from the far plane to the >>near plane, with glDepthMask(GL_FALSE);
    DA, this is the paint function of an object of type 3dMesh, and if you would bother to read the code you would have seen that of the transparency level is < 1.0 (that is the alpha level of the mesh) I transform the depth buffer to a read only mode using glDepthMask(GL_FALSE)
    since there are two mesh objects I draw the
    opaque one first and then the transparent one and therefore the if condition is being entered during the rendering of the second mesh.

    >>Wasn't I nice, everyone?
    actually Not really.

  4. #4
    Member Regular Contributor
    Join Date
    Nov 2000
    Posts
    409

    Re: transparency problem

    Originally posted by snow_master:
    [B][snip]
    and if you would bother to read the code you would have seen that ...[snip]
    [B]
    LOL geeze Knackered... can't you read?

    I want that code debugged and ready to go in an hour! Get to it, before we send you to n00bie land!

    p.s. Sleep? Whats that? Dunno, but if you don't get any, it sure makes you say strange things!

  5. #5
    Intern Contributor
    Join Date
    Apr 2002
    Location
    raanan israel
    Posts
    54

    Re: transparency problem

    >>I didn't bother to read your code because it's almost unreadable

    you probably meant you couldn't understand it because things I have long forgotten regarding programming you will probably never learn....

    >>and I shouldn't have even replied to you

    so don't.
    you bother me and spend my valuable (and very expensive) time, and except bitching you aren't being helpful, so just spare me your "wane be" smart answers.

    >>You are also very ungrateful

    you got to be kidding.....I should be grateful for what ?

  6. #6
    Intern Contributor
    Join Date
    Apr 2002
    Location
    raanan israel
    Posts
    54

    Re: transparency problem

    thank god for the internet....otherwise people like you would have never had the chance to interact with people like me...I find it amusing....but you live in this sad comedy.....I pity you.
    p.s
    if you are such a good programmer (I hope you are because judging your inter relationship with human beans, you probably haven't got any friends....) instead of answering intelligently insulting replays...try to debug the problem and earn some respect...

  7. #7
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Posts
    102

    Re: transparency problem

    As a vegetarian, I object to the whole
    concept of these "human beans".

  8. #8
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Philadelphia
    Posts
    332

    Re: transparency problem

    Originally posted by gumby:
    As a vegetarian, I object to the whole
    concept of these "human beans".
    It was a typo. He meant "humans and beans".

  9. #9
    Intern Contributor
    Join Date
    Apr 2002
    Location
    raanan israel
    Posts
    54

    Re: transparency problem

    again if you would have bother to read the question and the code....you would have noticed that i tryed many blending functions (including some that are not writen) it didn't made any sence to me either why when the src factor of the blending function is src_alpha (which make sence)that the whight of the closer transparent pixel alpha value will be multiplied, but the dest factor is GL_SRC_COLOR which dosen't make sence at all, but this is the only way i got good results...(when the background isn't black), the reasnobele choise was to put ONE_MINUS_SRC_ALPHA, but as i wrote earlier this method made only the opaque object to appear.
    >>God, your spelling is almost as bad as
    i appologize for my bad spelling, but english isn't my first language, and actualy i speak read and write in 7 languages.(i bet you do to....)

    now, dosen't any one else read this fourum ? can someone please try to be more helpfull...?...?

  10. #10
    Intern Contributor
    Join Date
    Apr 2002
    Location
    raanan israel
    Posts
    54

    Re: transparency problem

    please do go away already !!!
    now doesn't any one else can please be kind and try to suggest a solution ?

Posting Permissions

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