Stencil Buffer Beginner

What am I doing wrong… I can’t figure it out.
I’m just trying to draw a quad with a hole in it using the stencil buffer. Eventually (I hope that), the hole will be increasing in size and shape, and moving within the quad with time. For now, I’m just trying to get the hole working but I’m failing. Right now, the entire quad is being drawn.


void drawHole()
{
	glPushMatrix();
	GLUquadricObj *hole;
	hole = gluNewQuadric();
	glColor3f(0.8, 0.5, 0.5);
	glTranslated(0.0, 0.0, -2.0);
	gluDisk(hole, 0, 0.5, 20, 20);
	gluDeleteQuadric(hole);
	glPopMatrix();
}

void drawQuad()
{
	glPushMatrix();
	glColor4f(0.5, 0.5, 0.8, 0.7);
	glBegin(GL_POLYGON);
	glVertex3f(1.0, 1.0, -2.0);
	glVertex3f(-1.0, 1.0, -2.0);
	glVertex3f(-1.0, -1.0, -2.0);
	glVertex3f(1.0, -1.0, -2.0);
	glEnd();
	glPopMatrix();
}

void display()
{
	setprojection();
	glClear(GL_COLOR_BUFFER_BIT 
                | GL_DEPTH_BUFFER_BIT 
                | GL_STENCIL_BUFFER_BIT);
	
	glEnable(GL_STENCIL_TEST);				
	glColorMask(0, 0, 0, 0);
	glDisable(GL_DEPTH_TEST);
	glStencilFunc(GL_ALWAYS, 1, 1);			
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
	drawHole();

	glColorMask(1,1,1,1);	
	glEnable(GL_DEPTH_TEST);
	glStencilFunc(GL_NOTEQUAL, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	drawQuad();
	glDisable(GL_STENCIL_TEST);

	glutSwapBuffers();
}

I figured it out.

I didn’t include “GLUT_STENCIL” in the displaymode function in main.