Q: opengl stencil buffer multiple simultaneous uses I've managed to successfully use OpenGL's stencil buffer for a single instance in a scene. However, I'm unsure of how to use it in two different places in the same scene. Defining two stencil shapes in sequence prevents either from working, and my attempts to nest one use inside of the other didn't work either. I've seen examples of multiple uses of stencil buffer in the same scene, but I was not able to understand or adapt the code. Here is what I've been able to get working so far.
void display(void) {
    // store floor shape in stencil buffer
    glClearStencil(0);
    glClear(GL_STENCIL_BUFFER_BIT);
    glEnable(GL_STENCIL_TEST);
    glStencilMask(1);
    glStencilFunc(GL_ALWAYS, 1, 1);
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    floor->draw();
            glBegin(GL_QUADS);                   //
                glVertex3f(0.0, 0.0, 0.0);       //
                glVertex3f(0.0, 100.0, 0.0);     //
                glVertex3f(0.0, 100.0, 100.0);   //
                glVertex3f(0.0, 0.0, 100.0);     //
            glEnd();                             //

    // draw scene outside floor
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    scene();

    // draw reflection of scene in floor
    glStencilFunc(GL_EQUAL, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glPushMatrix();
    glScalef(1.0, 1.0, -1.0);
    scene();
    glPopMatrix();
    glDisable(GL_STENCIL_TEST);

    // draw translucent floor
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(1.0, 1.0, 1.0, 0.7);
    floor->draw();
    //windowHole();
    glDisable(GL_BLEND);

    glFlush();
    glutSwapBuffers();
    glutPostRedisplay();
}


