Skip to main content
gamedev.net
🔒 Locked

Stencil Buffer Reflection Problem 2

Started by MarcusMaximus 1 reply 350+ views
Original Post
MarcusMaximus
MarcusMaximus
Ok, I have a major problem now. The terrain reflects perfectly but it actually draws the inverted terrain under the reflective water. Isn''t the reflected image in stencil buffer supposed to be invisible? Thanks for your help. -Mark
-Mark
_the_phantom_
_the_phantom_
screen shots?
details?
code?
sorry, but i didnt bring my ''mind reading'' device with me today...
MarcusMaximus
MarcusMaximus
Sorry, Here's the code segment that draws the mountains and the reflective water. Basically everything works but it displays an inverted copy of the mountains under the water. Isnt the inverted copy supposed to be invisible unless its being viewed through the water? BTW: some of the comments are incorrect as I had to change some of nehe's code to make it work with what I had.

glColorMask(0,0,0,0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glDisable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-2,-2,.1);
glVertex3f(-2,2,.1);
glVertex3f(2,2,.1);
glVertex3f(2,-2,.1);
glEnd();
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
glColorMask(1,1,1,1); // Set Color Mask to TRUE, TRUE, TRUE, TRUE
glStencilFunc(GL_EQUAL, 1, 1); // We Draw Only Where The Stencil Is 1
// (I.E. Where The Floor Was Drawn)
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
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
glPushMatrix(); // Push The Matrix Onto The Stack
//glTranslatef(0,0,.1);
glScalef(1.0f, 1.0f, -1.0f);
glEnable(GL_LIGHTING);
glCallList(map1);
glDisable(GL_LIGHTING);
glPopMatrix(); // Pop The Matrix Off The Stack
glDisable(GL_CLIP_PLANE0); // Disable Clip Plane For Drawing The Floor
glDisable(GL_STENCIL_TEST); // We Don't Need The Stencil Buffer Any More (Disable)
glEnable(GL_BLEND);
glDisable(GL_LIGHTING); // Since We Use Blending, We Disable Lighting
glColor4f(1.0f, 1.0f, 1.0f, 0.3f); // Set Color To White With 80% Alpha
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Blending Based On Source Alpha And 1 Minus Dest Alpha
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-2,-2,0);
glVertex3f(-2,2,0);
glVertex3f(2,2,0);
glVertex3f(2,-2,0);
glEnd();
glEnable(GL_LIGHTING); // Enable Lighting
glDisable(GL_BLEND); // Disable Blending
glCallList(map1);

-Mark

[edited by - MarcusMaximus on April 2, 2004 5:52:48 PM]
-Mark

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.