0

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;
}
  • Sorry, but I can't see any obvious issue in this code. The skybox is drawn first and the depth test is always disabled when the sybox is drawn. – Rabbid76 Oct 17 '20 at 16:14
  • Thank you for the response :) I am also figuring it what is the issue :( – BeingHumayun Oct 17 '20 at 16:17
  • What about drawing skybox at the end? any suggestion ? – BeingHumayun Oct 17 '20 at 16:18
  • 1
    I recommend to find the bug in your application. In general your approach is correct. If it doesn't work, you have a bug in your application. Anyway you can draw the skybox at the end The depth test has to be enabled, the depth function has to be `GL_LEQUAL` ([`glDepthFunc(GL_LEQUAL)`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDepthFunc.xhtml)) and you have to draw the skybox with a z coordinate of 1.0. The matrices have to be the identity matrices (`GL_MODELVIEW` and `GL_PROJECTION`). – Rabbid76 Oct 17 '20 at 16:23
  • I'll try that thanks – BeingHumayun Oct 18 '20 at 06:36
  • Fixed !!! Issue is I am using both Depth_Test and DepthMask in Skybox Function...it works only with DepthMask. – BeingHumayun Oct 18 '20 at 07:16
  • Any tutorial on Moon light in opengl? I am done with sun light in my Project...Just curious how moon light works...Like sun or it is different – BeingHumayun Oct 18 '20 at 07:29

1 Answers1

0

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