BeingHumayun
BeingHumayun

Reputation: 45

Opengl Skybox Depth Buffer Hides the scene

Depth Buffer was working fine Until I added the Skybox, now it hides all my world(scene) and only renders the skybox when hiddenDepth=False... The issue is clearly the skybox as I checked it by removing skybox...

Display Function below

static void display()
{
  if (hiddenDepth) 
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
  else {
glClear(GL_COLOR_BUFFER_BIT);
}

        glPushMatrix();
        glScalef(15500, 15500, 15500);
        glTranslatef(0,0.5, 0);
        drawskybox();
        glPopMatrix();
        glScalef(40, 40, 40);
        drawWorld();

}

Here is My Skybox


    glPushMatrix();
   glPushAttrib(GL_ENABLE_BIT);
   glEnable(GL_TEXTURE_2D);
   glDisable(GL_DEPTH_TEST);
   glDepthMask(GL_FALSE);
   glDisable(GL_BLEND);

    // Render the quad

    glPopAttrib();
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glEnable(GL_BLEND);
    glPopMatrix();
}

Hidden Depth Call (true,false on key press)

if (hiddenDepth)
  {
    // Now do z buffer
    glEnable(GL_DEPTH_TEST);
    glDepthRange(nearPlane,farPlane);
    glClearDepth(farPlane);
  }

InitGrapics

static void initGraphics (void)
{
   glEnable(GL_DEPTH_TEST);
   glDepthFunc(GL_LESS);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

Main Function

int main (int argc, char * argv[])
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);

  glutInitWindowSize(550, 550);
  glutInitWindowPosition(100, 75);
  glutCreateWindow("Cube");

  initGraphics();
  glutDisplayFunc(display);
  glutReshapeFunc(resize);
  
  glutKeyboardFunc(asciiKey);
  glutSpecialFunc(specialKey);
  
  glutIdleFunc(idleRoutine);
  glutTimerFunc(timerMSecs,timer,0);
  
  glutMainLoop();
  /* Should never get here, but keeps compiler happy */
  return 0;
}

Upvotes: 0

Views: 346

Answers (1)

BeingHumayun
BeingHumayun

Reputation: 45

Fixed !!! Issue is I am using both Depth_Test and DepthMask in Skybox Function...it works only with DepthMask

Upvotes: 0

Related Questions