标红的为关键代码

    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);
 
读书笔记——使用模板缓冲区

相关文章:

  • 2022-12-23
  • 2021-07-26
  • 2021-07-19
  • 2021-06-08
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
猜你喜欢
  • 2022-12-23
  • 2021-04-20
  • 2021-08-10
  • 2021-03-28
  • 2022-02-05
  • 2021-11-17
  • 2022-12-23
相关资源
相似解决方案