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 2 of 2

Thread: see background through two translucent textures

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2010
    Posts
    1

    see background through two translucent textures

    I draw 3D cloud, it is a dimensional rectangle(x,y,z > 0) textured with a RGBA cloud bmp image.
    if the camera is some where at the assurgent, some translucent cloud looked have opaque caps, As if the translucent front side of the cloud together with the translucent back side of the cloud result in opaque, so I can't see background color through the opaque caps.
    I suppose the translucent front side of the cloud together with the translucent back side of the cloud will also result in translucency.
    here is my code:
    //begin
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glHint(GL_PERSPECTIVE_CORRECTION_Hint, GL_NICEST);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(openGL.GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    glLoadIdentity();
    glTranslatef(fMoveX, fMoveY, -2.5f);
    glRotatef(fAngleX, 1.0f, 0.0f, 0.0f);
    glRotatef(fAngleY, 0.0f, 1.0f, 0.0f);
    glRotatef(fAngleZ, 0.0f, 0.0f, 1.0f);
    glScalef(Scale, Scale, Scale);
    if (Width1 > 0 && Height1 > 0)
    {
    glBindTexture(GL_TEXTURE_2D, intexture[1]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(openGL.GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(openGL.GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 4, Width1, Height1, GL_BGRA_EXT, GL_UNSIGNED_byte, m_symbol);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    float[] light_position ={ 0.0f, 6.0f, 3.5f, 0.0f };
    float[] light_ambient ={ 1.0f, 1.0f, 1.0f, 1.0f };
    float[] mat_env ={ 0.75f, 0.75f, 0.75f, 0.0f };
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_env);
    draw(); //glDrawElements()
    glDisable(GL_LIGHTING);
    }
    glDisable(GL_TEXTURE_2D);
    //end
    please tell me where is the mistake

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

    Re: see background through two translucent textures

    glEnable(GL_DEPTH_TEST);
    Depth testing only works properly for totally opaque objects.

    If you first draw front face of cube, then back face, the depth test will skip back face totally, and you will only see front face.
    If you first draw back face of cube, then front face, the depth test will do nothing (all pixels pass) and you will see both back and front.

    A lazy fix is to just disabled depth test for translucent objects. The correct fix is to manually sort faces at each frame, and draw back to front, because GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA is also order dependent.

Posting Permissions

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