Ok. The ‘hole’ has formed. But it is not a dead-end hole but a cut-through hole — the backward surface is also removed. Have you any good suggestion?
The following is my code:
void redraw() {
double plane0[] = {1.0, 0.0, 0.0, 0.0 };
double plane1[] = {0.0, 1.0, 0.0, 0.0 };
double plane2[] = {0.0, 0.0, 1.0, 0.0 };
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glClipPlane(GL_CLIP_PLANE0, plane0);
glClipPlane(GL_CLIP_PLANE1, plane1);
glClipPlane(GL_CLIP_PLANE2, plane2);
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glColor3f(1.0f, 1.0f, 0.0f);
glutSolidSphere(50, 40, 30);
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
// glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NOTEQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glColor3f(1.0f, 1.0f, 0.0f);
glutSolidSphere(50, 40, 30);
glColor3f(1.0f, 0.0f, 0.0f);
glutSolidSphere(10, 40, 30);
glDisable(GL_STENCIL_TEST);
glColor3f(0.0f, 0.0f, 1.0f);
glutSolidCube(40);
glPopMatrix();
// Show the graphics
glutSwapBuffers();
}