Sign in to follow this  
Drunken_Monkey

Clipping and Stencil problems

Recommended Posts

Drunken_Monkey    157
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};

	glLoadIdentity();
	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);
	mirror();//Lay out the stencil area
	
	glEnable(GL_DEPTH_TEST);
	glColorMask(1, 1, 1, 1);
	glStencilFunc(GL_EQUAL, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	glEnable(GL_CLIP_PLANE0);
	glClipPlane(GL_CLIP_PLANE0, clipPlane);

	glLoadIdentity();
	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);

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

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

	glLoadIdentity();
	mirror();//Render the mirror

Share this post


Link to post
Share on other sites
AndyEsser    394
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this