Hi, I have read a reference talking abt the water reflection in which the procedure is as follows:
- Initialize the modelview and projection matrices to the identity (glLoadIdentity).
- Set up a projection matrix using the glFrustum command.
- Set up the “real” eye point at the desired position using a gluLookAt command (or something
similar). - 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. - Draw the scene.
- 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 |
GL DEPTH BUFFER BIT)).
2. Configure the stencil buffer such that a 1 will be stored at each pixel touched by a polygon:
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 1);
glEnable(GL_STENCIL_TEST);
3. Disable drawing into the color buffers (glColorMask(0, 0, 0, 0)).
- Draw the mirror polygon.
- Reconfigure the stencil test:
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NOTEQUAL); - Draw the scene.
- Disable the stencil test (glDisable(GL STENCIL TEST
However, it seems to me that there is no need to place the eye point under water (as in my case, I am doing water reflection) and no calculation on this new eye point of viewing frustum is needed. It seems to me that when I need is to utilize the stencil buffer, and then just draw the objects 2 times…
It seems that the effect is the same…
Could anyone tell me if I have misunderstood anything and do my implementation wrongly?
Thx