Skip to main content
gamedev.net
🔒 Locked

Stencil Buffer

Started by metalcrusader Oct 29, 2005 at 7:43 AM 0 replies 300+ views
Original Post
metalcrusader
metalcrusader
Hello! I want to test the Stencil buffer so I render a cube only in the Stencil Buffer which stores 1s for the contour. Then I want to render another cube( also only in the stencilbuffer) which should increment the values in the stencilbuffer for the region where the first and the second cube overlaps. After that, i enable writing to the colorbuffer and draw the third cube in the region, where a 2 is in the stencilbuffer. But something is wrong - the third cube is drawn as if i didn´t use the stencilbuffer at all. Any ideas?

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |GL_STENCIL_BUFFER_BIT);
glLoadIdentity();
gluLookAt( 0, 0, 2, 0, 0, 0, 0.0, 1.0, 0.0);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);  
glPushMatrix();
	glTranslatef( 0.0, 0.0, -3.0);
	glColor3f( 0.0, 0.0, 1.0);
	glClear( GL_STENCIL_BUFFER_BIT);
	glStencilFunc(  GL_ALWAYS, 1, 1); 
	glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE); 
	glutSolidCube(1.0);
glPopMatrix();
    
glPushMatrix();
    	glTranslatef( -0.25, -0.1, -2.0);
	glStencilFunc(  GL_EQUAL, 1, 1);
	glStencilOp( GL_KEEP,GL_KEEP, GL_INCR);
	glColor4f( 0.0, 0.0, 1.0, 1.0);
	glutSolidCube(1);
glPopMatrix();    
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);    
    glPushMatrix();
    	glTranslatef( -0.25, -0.1, 0.0);
	glStencilFunc(  GL_EQUAL, 2, 1);
	glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP);
	glColor4f( 0.0, 1.0, 0.0, 1.0);
	glutSolidCube(1);
    glPopMatrix();

Another Question: GL_INCR should increment the stored stencilvalue - but what is that "saturation" ?

Topic Locked

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

Sign in to reply to this topic.