Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Stencil Buffer Beginner

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2010
    Location
    Montreal, Quebec, Canada
    Posts
    14

    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.

    Code :
    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();
    }

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2010
    Location
    Montreal, Quebec, Canada
    Posts
    14

    Re: Stencil Buffer Beginner

    I figured it out.

    I didn't include "GLUT_STENCIL" in the displaymode function in main.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •