Depth Test not working

Hi everyone, I have to do a particle simulation and all the particles are nothing more than glutSolidSpheres.

However I’m unable to get the depth test to work:

It’s displaying the spheres that were drawn later on top of the others.


main()
{
glut init functions...

glEnable(GL_CULL_FACE);
  glEnable(GL_COLOR_MATERIAL);
  glClearDepth(1.0f); // any value I put here doesn't matter!?!
  glEnable (GL_DEPTH_TEST); 
  glDepthFunc(GL_LESS); // shouldn't even be needed 
  glDepthMask(GL_TRUE);
  glEnable (GL_LIGHTING); 
  glEnable (GL_LIGHT0);
  glShadeModel (GL_SMOOTH); 

  
  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteSpecularLight);
  glLightfv(GL_LIGHT0, GL_AMBIENT, blackAmbientLight);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteDiffuseLight);

callbacks and mainloop...
}

void display() // used also as idleFunc
{
glClearColor (0.0,0.0,0.0,1.0); //
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

....
}

Sorry for the dumb question but i’m stuck for 4hours in this stupid problem, it’s pulling my hair out! ( I’ve googled a lot, copied code from others and nothing)
Can someone help me out? It’s as if depth test was disabled.

It’s really urgent, thanks

Remove glClearDepth(1.0f), as default value should work.
Are you sure you create the window with a depth buffer, in the glut init ?

Hi!

Thanks

I gave up working and went to try the program in other computer without changing anything and it worked! it looks like a driver issue or a problem in freeglut.h (i’m in linux).

But thanks a lot for your time :wink:

Can you answer my question ? Specifically, what is your exact line with glutInitDisplayMode ?