|
楼主 |
发表于 2013-1-17 17:07:05
|
显示全部楼层
模版测试代码没错,再次放在opengl里面测试是没问题的,- glEnable(GL_STENCIL_TEST);
- glClearStencil(0);
- glClear(GL_STENCIL_BUFFER_BIT);
- glStencilFunc(GL_ALWAYS, 1, 0xFF);
- glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
- /************************************************************************/
- //
- glLoadIdentity();
- glColor4d(0.0f,0.5f,0.0f,0.0f);
- glBegin(GL_POLYGON);
- glVertex3d(-300.0,-300.0,0.0);
- glVertex3d(300.0,-300.0,0.0);
- glVertex3d(300.0,300.0,0.0);
- glVertex3d(-300.0,300.0,0.0);
- glEnd();
- /************************************************************************/
- glStencilFunc(GL_NOTEQUAL, 1, 1);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- // 和模板值为1的图形进行模板测试比较
- glLoadIdentity();
- glColor4d(0.5f,0.0f,0.0f,0.25f);
- glLineWidth(10.0);
- glBegin(GL_LINES);
- glVertex3d(0.0,600.0,0.0);
- glVertex3d(0.0,-600.0,0.0);
- glEnd();
- glDisable(GL_STENCIL_TEST);
复制代码 在virtual void drawImplementation内- virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const
- {
- osg::State& state = *renderInfo.getState();
- state.disableAllVertexArrays();
- glEnable(GL_STENCIL_TEST);
- glClearStencil(0);
- glClear(GL_STENCIL_BUFFER_BIT);
- glStencilFunc(GL_ALWAYS, 1, 0xFF);
- glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
- /************************************************************************/
- glLoadIdentity();
- glColor4d(0.0f,0.5f,0.0f,0.0f);
- glBegin(GL_POLYGON);
- glVertex3d(-300.0,-300.0,0.0);
- glVertex3d(300.0,-300.0,0.0);
- glVertex3d(300.0,300.0,0.0);
- glVertex3d(-300.0,300.0,0.0);
- glEnd();
- /************************************************************************/
- glStencilFunc(GL_EQUAL, 1, 1);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- // 和模板值为1的图形进行模板测试比较
- glLoadIdentity();
- glColor4d(0.5f,0.0f,0.0f,0.25f);
- glLineWidth(10.0);
- glBegin(GL_LINES);
- glVertex3d(0.0,600.0,0.0);
- glVertex3d(0.0,-600.0,0.0);
- glEnd();
- glDisable(GL_STENCIL_TEST);
- }
复制代码 测试不通过啊,加了disableAllVertexArrays 也不成功。
这个是自己业余大的事件在改,所以也没及时问! |
|