Results 1 to 3 of 3

Thread: Bizzare depth buffer problem

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    5

    Bizzare depth buffer problem

    I have no idea why this is occuring... but for some reason the depth buffer is not being cleared in between frames in my program. It has something to do with enabling/disabling glDepthMask.

    Here's the situation:
    If i enable glDepthMask (disabling GL_BLEND) to render my opaque object, then disable it (enabling GL_BLEND) for my transparent object, the depth information for the opaque object is not removed when i use glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) and opaque object is occluded if it, for example, is moved further away.

    However... if i leave glDepthMask either enabled or disabled for the entirety of the program, everything will go fine (Except of course for depth checking issues)

    i'm sure it has something to do with the specifics of my code, so i'll post my rendering portion here:

    int DrawGLScene(GLvoid)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
    glLoadIdentity();

    if(!blend)
    {
    glDisable(GL_BLEND);
    glDepthMask(GL_TRUE);
    }

    glPushMatrix(); //start screwing with stuff now!
    glTranslatef(0.0f, 0.0f, zdepth);// Move Into The Screen

    glRotatef(xrot,1.0f,0.0f,0.0f);// Rotate On The X Axis
    glRotatef(yrot,0.0f,1.0f,0.0f);// Rotate On The Y Axis

    glCallList(box);
    glPopMatrix();

    glDepthMask(GL_FALSE);
    glEnable(GL_BLEND);

    glPushMatrix(); // Reset The Current Modelview Matrix
    glPushAttrib(GL_LIGHTING_BIT);
    glDisable(GL_LIGHTING);
    glTranslatef(LightPosition[0], LightPosition[1], LightPosition[2]);

    glCallList(light);
    glEnable(GL_LIGHTING);
    glPopAttrib();

    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Re-Position The Light
    glPopMatrix();

    return TRUE;// Keep Going
    }

    and my gl initilization

    int InitGL(GLvoid) // All Setup For OpenGL Goes Here
    {
    glMatrixMode(GL_MODELVIEW);
    multitextureSupported=initMultitexture();
    glLoadIdentity();

    if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
    {
    return FALSE; // If Texture Didn't Load Return FALSE ( NEW )
    }
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_NORMALIZE);

    glEnable(GL_COLOR_MATERIAL);// Enable Material Coloring
    glColor4f(1.0f,1.0f,1.0f,1.0f);
    glMaterialf(GL_FRONT, GL_SHININESS, 25.0f);
    glMaterialfv(GL_FRONT,GL_SPECULAR, matSpec);
    buildLists();
    // Enable Texture Mapping ( NEW )
    glShadeModel(GL_SMOOTH); // Enable Smooth Shading
    glClearColor(fogColor[0],fogColor[1],fogColor[2],fogColor[3]); // We'll Clear To The Color Of The Fog ( Modified )

    glClearDepth(1.0f);

    // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST); // Enables Depth Testing
    glDepthFunc(GL_LEQUAL);

    glEnable(GL_CULL_FACE);

    glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency Based On Source Alpha Value ( NEW )

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

    initLights();

    //fog
    glFogi(GL_FOG_MODE, GL_LINEAR);// Fog Mode
    glFogfv(GL_FOG_COLOR, fogColor);// Set Fog Color
    glFogf(GL_FOG_DENSITY, fogDensity);// How Dense Will The Fog Be
    glHint(GL_FOG_HINT, GL_NICEST);// Fog Hint Value
    glFogf(GL_FOG_START, 1.0f);// Fog Start Depth
    glFogf(GL_FOG_END, 200.0f);// Fog End Depth

    return TRUE; // Initialization Went OK
    }

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Bizzare depth buffer problem

    OpenGL state is persistent and your last call w.r.t. masking in your loop is glDepthMask(GL_FALSE). When you finish the previous frame you leave the depth buffer masked, so when you come around the next frame the depth buffer is still masked when you call clear and so the depth buffer clear has no effect.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2003
    Posts
    5

    Re: Bizzare depth buffer problem

    Ahhhh, that was it. Thank you. For some reason i assumed that the glClear command wasn't restricted by glDepthMask, but i was clearly wrong.

Similar Threads

  1. Depth buffer problem
    By egydev in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-19-2010, 06:26 AM
  2. Bizzare glColor3f() problem
    By robtheg in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-18-2008, 02:50 AM
  3. depth buffer problem?
    By in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 02-23-2004, 10:00 PM
  4. Depth buffer problem ?
    By Vlasko in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-08-2003, 07:17 AM
  5. Bizzare texture seam problem on LOD terrain.
    By ceenda in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 05-24-2002, 03:54 PM

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