PDA

View Full Version : Reflexion problem



laf
05-11-2002, 01:43 AM
I'm using the routine at the end of this post to draw a reflexion. But I don't know why sometimes the reflected objects dissapear. Could anyone help me??

double eqr[] = {0.0,-1.0, 0.0, 0.0}; // Plane Equation To Use For The Reflected Objects

glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glEnable (GL_STENCIL_TEST ); // Enable Stencil Buffer For "marking" The Floor
glStencilFunc (GL_ALWAYS, 1, 0x1); // Always Passes, 1 Bit Plane, 0x1 As Mask
glStencilOp (GL_KEEP, GL_KEEP, GL_REPLACE ); // We Set The Stencil Buffer To 1 Where We Draw Any Polygon
// Keep If Test Fails, Keep If Test Passes But Buffer Test Fails
// Replace If Test Passes
glDisable (GL_DEPTH_TEST); // Disable Depth Testing
[suelo drawStencil:nil]; //DrawFloor(); // // Draw The Floor (Draws To The Stencil Buffer)
// We Only Want To Mark It In The Stencil Buffer
glEnable (GL_DEPTH_TEST); // Enable Depth Testing

glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // Set Color Mask to true, true, true, true
glStencilFunc ( GL_EQUAL, 1, 0x1 ); // We Draw Only Where The Stencil Is 1
// (I.E. Where The Floor Was Drawn)
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); // Don't Change The Stencil Buffer
glEnable (GL_CLIP_PLANE0); // Enable Clip Plane For Removing Artifacts
// (When The Object Crosses The Floor)
glClipPlane (GL_CLIP_PLANE0, eqr); // Equation For Reflected Objects

enumerator = [objetos objectEnumerator];

while ((anObject = [enumerator nextObject]))
{
Objeto* o = (Objeto*) anObject;
glScalef( 1.0, -1.0, 1.0 ); // Da la vuelta a la figura para el reflejo
[o draw];
}

glDisable (GL_CLIP_PLANE0); // Disable Clip Plane For Drawing The Floor
glDisable (GL_STENCIL_TEST);