# Clipping and Stencil problems

## Recommended Posts

Okay, I'm teaching myself how to use the Stencil Buffer and the Clipping Plane. But the program I'm writing is doing something extremely weird. I know I still have A LOT to work on, like the reflection being flipped around and not at the right position on the mirror and the lighting is completely off, I want to work on those things myself. What I DO need help with is why the damn mirror is only reflecting half of the sphere. Here's the rendering section of the code:
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

GLdouble clipPlane[] = {0.0, -1.0, 0.0, 0.0};

glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glDisable(GL_DEPTH_TEST);
mirror();//Lay out the stencil area

glEnable(GL_DEPTH_TEST);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, clipPlane);

glScalef(1, -1, 1);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosRef);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightCol);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightCol);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightCol);
glTranslatef(0, 0, -4);
sphere.render();//Render the reflection with my OBJ Loader

glDisable(GL_CLIP_PLANE0);
glDisable(GL_STENCIL_TEST);

glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightCol);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightCol);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightCol);

glTranslatef(0, 1, -4);
sphere.render();//Render the real sphere

mirror();//Render the mirror



##### Share on other sites
I'm no expert in this area but it looks like that half of the sphere may be being culled, try disabling any Culling you have enabled and see what it looks like. Also try it with a different model, other than a sphere, for example a cube.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628277
• Total Posts
2981778

• 10
• 11
• 17
• 11
• 9