PDA

View Full Version : Reflection Problem



Asura
04-21-2006, 08:11 AM
Hi all:
I have a problem when I am drawing the reflections. My code is like following:


void Reflection(){
glDisable(GL_DEPTH_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

glEnable(GL_STENCIL_TEST);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);

DrawCheckerBoard();

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glEnable(GL_DEPTH_TEST);

glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glPushMatrix();
glScalef(1.0f, -1.0f, 1.0f);
DrawObject();
glPopMatrix();
glDisable(GL_STENCIL_TEST);
}
Outside this function I have enabled GL_BLEND and drawn the floor. The problem is that the object under the floor plane is always drawn as well. And I don't know how to remove it to just remain the reflection. I tried the method in NeHe's tutorial which uses
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, eqr);
glDisable(GL_CLIP_PLANE0);
around the push and pop matrix. But it removed the reflection at the same time when I used it. Does anybody know where's the mistake please???
Thanks very much!!!

Asura
04-21-2006, 08:15 AM
By the way, could anyone tell me how to paste the image so that I can show my problem clearer

jide
04-21-2006, 11:16 AM
This problem has been recently treated, try a search.

earthquad
04-21-2006, 02:18 PM
Perhaps this (http://www.opengl.org/resources/code/samples/mjktips/Reflect.html) will help you catch your mistake?