repainting a part of a Displaylist ---- Stencil buffer

Hello…

In my Screensaver a Bird flys over the ground. When he moves i have to repaint the part of the Displaylist (ground) which is overlapped by the Bird. How can i do this ???

I think i missunderstand how the stencilbuffer works … this is my attempt…

INIT:
glClearStencil(0);
glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);

REPAINT:
glStencilMask(bird);
glStencilFunc(GL_EQUAL,1,1);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glCallList(ground);

bird and ground are Displaylists

You probably don’t want to use the stencil buffer, because it’s not always hardware accelerated. It’s useful for masking arbitrarily complex pixel areas, but for this it’s probably good enough to use glScissor() over the region that the bird is around.

Of course, you need to figure out what that region is. One way to do that is to construct some simple bounding volume (usually a box) that always encloses the bird (transform the box w/ the bird). Instead of the trying to figure out the screen region the bird is in (which can be hard, because it can have lots of vertices) figure out the screen region the bounding box is in by projecting the vertices. This will give you a set of screen coordinates. Find the max and min of both x and y screen coordinates, and this should give you the scissor area.

If you want to use the stencil buffer, I think this should work:
INIT:
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glStencilOp(GL_REPLACE,GL_REPLACE,GL_REPLACE);

REPAINT:
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS,1,1);
glCallList(bird);
glStencilFunc(GL_EQUAL,1,1);
glCallList(ground);

BTW, this is a useful link to find out what most of the functions do.