Depth buffer / depth test question

Hello everyone,

I am running into a problem when trying to draw some simple shapes. I want to draw a sort of “planet”, so I am using a gluCylinder to draw the sphere and then I have a loop to draw out a circular ring around the sphere. The code is as follows:


gluSphere(gluNewQuadric(), 0.5, 360, 360);
for(float theta = 0; theta < 360; theta+=0.5){
                float x = 1 * cosf(theta);
                float y = 1 * sinf(theta);
                glBegin(GL_POINTS);
                glVertex3f(x, 0, y);
                glEnd();
}

The issue that I am running into is that when I rotate the view using glRotatef and actually even when I am not, essentially, the ring can be seen both in front and behind the sphere. Its like the sphere is see-through. I want it to draw the ring in front of the sphere when facing the “camera” and hide the portion of the “ring” that is behind the sphere.

I am assuming this has something to do with the depth buffer, but I am a beginner so I may be wrong. I tried turning on glEnable(GL_DEPTH_TEST) but nothing works. I am clearing the depth buffer too.

Is there a way to fix this?? Are there some calls I need to make? I would greatly appreciate some help on this.

Thanks

Both of those are necessary. However: do you actually have a depth buffer? Depending upon the toolkit used, you may have to specifically request a depth buffer. E.g. for GLUT, you need to include the GLUT_DEPTH flag in the glutInitDisplayMode() call.