How to not show something in back of object

Hi, I have a Sphere that I created with
glutSolidSphere, and on that sphere there is some cyllinders that I put on it, however when I rotate the entire object the Cylinders show up at all times, even when they should be “behind” the sphere, you can see them through the sphere…How do I stop it from doing this?

I tried
glEnable(GL_CULLING);
glCullFace(GL_BACK);

and that didn’t seem to do anything…

Thanks for any help.

Did you set up your Depth Buffer correctly?

glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

and of course, make sure you’ve allocated bits to it via the pixel format call or in case of GLUT, with the GLUT_DEPTH call in your glutInitDisplayMode()

Hi I didn’t have the GLUT_DEPTH in there, but I had everytyhing else…
now that I added GLUT_DEPTH my Linux is giving me the same problems as the Windows one is.

its probably some dumb mistake, I just cant find it.

Nevermind, I figured it out, I was not
clearing my GL_DEPTH_BUFFER_BIT
I fixed that so it works now.