Drawing objects on top of one another.

I’m teaching myself opengl via the “OpenGL Programming Guide 3rd Edition” In there, there is a program called “planet.c” Which makes two “glutWireSphere”'s and makes them rotate about each other. I copied the code and proceded to play with it. Now, I need to know how to make the “planet” sphere disappear when it moves behind the “sun” sphere. Here’s the display code:

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

glPushMatrix();
glutSolidSphere(1.0,20,16);

glRotatef((GLfloat)year,0.0,1.0,0.0);
glTranslatef((GLfloat)2.0,0.0,0.0);
glRotatef((GLfloat)day,0.0,1.0,0.0);
glutWireSphere(0.2,10,8);

glPopMatrix()
glutSwapBuffers();

}

Thanks

You need the depthbuffer. When initializing the window, use a bitwise or to add GLUT_DEPTH to the other arguments.

In your setup code, add glEnable(GL_DEPTH_TEST);

And then you have to make the two spheres solid, or you can still see the one of then through the other. Replace glutWireSphere with glutSolidSphere.

[This message has been edited by Bob (edited 09-04-2000).]