Jump to content
  • Advertisement
Sign in to follow this  
Drunken_Monkey

Clipping and Stencil problems

This topic is 4095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

	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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!