读书笔记——使用模板缓冲区

标红的为关键代码

    glEnable(GL_STENCIL_TEST);
    glClearStencil(0);
    glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
    glStencilFunc(GL_NEVER,0,0);
    glStencilOp(GL_INCR,GL_INCR,GL_INCR);

     ...
    glStencilFunc(GL_NOTEQUAL,1,1);
    glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
    ...

	GLfloat angle=0.0f;
	GLfloat radius=1.01f;

	glEnable(GL_STENCIL_TEST);
	glClearStencil(0);
	glClear(GL_COLOR_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
	
	glColor3f(1.0f,0.0f,1.0f);
	glStencilFunc(GL_NEVER,0,0);
	glStencilOp(GL_INCR,GL_INCR,GL_INCR);
	glBegin(GL_LINE_STRIP);
		for (angle=0.0f;angle<400.0f;angle+=0.1)
		{
			glVertex2f(radius*cos(angle),radius*sin(angle));
			radius*=1.002;
		}
	glEnd();

	glColor3f(1.0f,0.0f,0.0f);
	glStencilFunc(GL_NOTEQUAL,1,1);
	glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
	glRectf(x,y,x+RectSize,y-RectSize);
 
读书笔记——使用模板缓冲区_第1张图片

你可能感兴趣的:(模板,OpenGL)