simple mirror reflection procedure

Hi all, I would like to ask how to create a world with a lake that can have reflection on the water whenever some moving object is on the top of the water?

I have read a reference saying that it involves two-pass technique using the stencil buffer. The procedure for the first pass:

  1. Initialize the modelview and projection matrices to the identity (glLoadIdentity).
  2. Set up a projection matrix using the glFrustum command.
  3. Set up the “real” eye point at the desired position using a gluLookAt command (or something
  4. Reflect the viewing frustum (or the scene) through the plane containing the reflector by computing a reflection matrix and combining it with the current modelview or projectionmatrices
    using the glMultMatrix command.
  5. Draw the scene.
  6. Move the eye point back to its “real” position.

The procedure regarding the second part:
Clear the stencil and depth buffers (glClear(GL COLOR BUFFER BIT |
2. Configure the stencil buffer such that a 1 will be stored at each pixel touched by a polygon:
glStencilFunc(GL_ALWAYS, 1, 1);
3. Disable drawing into the color buffers (glColorMask(0, 0, 0, 0)).

  1. Draw the mirror polygon.
  2. Reconfigure the stencil test:
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  3. Draw the scene.
  4. Disable the stencil test (glDisable(GL STENCIL TEST)).

Hi all, I can do the reflection !!! Thanks all. However, I come across a problem. When the robot walk into the lake, since the robot is too high, the reflected leg overlap with the orginal robot… and the scene is as this:
problem graphics

Would anyone kindly tell me if there is any solution can solve it?

You need to define (and activate) a clipping-plane at the same height as your lake when you render your reflection. The clippingplane then will clip everything that lies above your reflective surface.

Sorry, would you mind telling me how to use define one clippling plane that lies horizontally? Thanks a lot

And suppose the plane range from 260 to 560 in both x-coordinate and z-coordinate, and the y-coordinate is 90 through out the plane.

Thx a lot…
Maybe it is really easy to do that…but since I am new to OpenGL…pls help me…thx

Hi, I just find the function glClipPlane, however, when I try to use

GLdouble clipA[4] = {0, 1, 0, -90};
GLdouble clipB[4] = {1, 0, 0, -260};
GLdouble clipC[4] = {1, 0, 0, -560};
GLdouble clipD[4] = {0, 0, 1, -260};
GLdouble clipE[4] = {0, 0, 1, -560};

to do the clipping…
it is unsuccessful…

I CAN succesfully do it la~

Thanks very much PanzerSchreck for your hlep ar!!!