Jump to content
  • Advertisement
Sign in to follow this  

Stencil Reflection Problem

This topic is 3549 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

I try to draw a scene with an object which will reflect all the other objects in my scene. But I have some problems. All works fine, if i only add one reflecting object to the scene. but if i add 2 or more i get displaying problems. i know that i have displaying problems because of the multirendering of some objects, but at least the reflections of these objects should be visible on the reclecting objects. i hope, that somebody could help me to fix my function.
[source lang=c]
	if(m_eRendermode == REFLECTIVE) {
		for(unsigned int i = 0; i < m_ReflectSceneGraphItems.size(); i++) {
			SceneGraphItem *reflItem = m_ReflectSceneGraphItems.at(i);
			for(unsigned int j = 0; j < m_SceneGraphItems.size(); j++) {
				SceneGraphItem *item = m_SceneGraphItems.at(j);
				if(reflItem->m_iSceneIdentifier == item->m_iSceneIdentifier)


				glEnable(GL_STENCIL_TEST); 			//Enable using the stencil buffer
				glColorMask(0, 0, 0, 0); 			//Disable drawing colors to the screen
				glDisable(GL_DEPTH_TEST); 			//Disable depth testing
				glStencilFunc(GL_ALWAYS, 1, 1); 	//Make the stencil test always pass
				glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);	//Make pixels in the stencil buffer be set to 1 when the stencil test passes
				glColorMask(1, 1, 1, 1); 			//Enable drawing colors to the screen
				glEnable(GL_DEPTH_TEST); 			//Enable depth testing
				glStencilFunc(GL_EQUAL, 1, 1);		//Make the stencil test pass only when the pixel is 1 in the stencil buffer
				glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 	//Make the stencil buffer not change
					/* Draw the cube, reflected vertically, at all pixels where the stencil *
					 * buffer is 1                                                          */
						glScalef(1, -1, 1);
						/* calculate reflection relative to both objecs positions */
						Vec3f reflectionPos = item->GetPosition() - reflItem->GetPosition();
						glTranslatef(reflectionPos.x, reflectionPos.y, reflectionPos.z);
						glRotatef( 	item->GetRotationAngle(),
									item->GetRotationAxis().z );
				glDisable(GL_STENCIL_TEST); //Disable using the stencil buffer
			//Blend the floor onto the screen
			glBlendFunc(GL_DST_COLOR, GL_ZERO);
				glColor4f(1, 1, 1, 0.7f);

this is my scene in case only the quad below reflects the objects. and this happens if i activate reflecting on the upper quad

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!