OSG使用模板缓存
作者:互联网
参考帖子:
https://blog.csdn.net/csxiaoshui/article/details/23457273
osg::Geometry *lineStripGeometry = new osg::Geometry; osg::Vec3Array *lineVertexArray = new osg::Vec3Array; double dRadius = 0.1; for (float angle = 0.0; angle < 400.0; angle += 0.1) { lineVertexArray->push_back(osg::Vec3(dRadius * cos(angle), dRadius * sin(angle), 0)); dRadius *= 1.002; } osg::Vec4Array *lineColorArray = new osg::Vec4Array; lineColorArray->push_back(osg::Vec4(1.0, 1.0, 1.0, 1.0)); lineStripGeometry->setVertexArray(lineVertexArray); lineStripGeometry->setColorArray(lineColorArray); //OSG 3.2之后的版本在setColorArray中设置绑定方式 lineStripGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); lineStripGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, lineVertexArray->size())); lineStripGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //添加模板测试 osg::Stencil *lineStripStencil = new osg::Stencil; lineStripStencil->setFunction(osg::Stencil::NEVER, 0x0, 0x0); lineStripStencil->setOperation(osg::Stencil::INCR, osg::Stencil::INCR, osg::Stencil::INCR); lineStripGeometry->getOrCreateStateSet()->setAttributeAndModes(lineStripStencil); ////////////////////////////////////////////////////////////////////////// osg::Geometry *quadGeometry = new osg::Geometry; osg::Vec3Array *quadVertexArray = new osg::Vec3Array; quadVertexArray->push_back(osg::Vec3(0, 0, 0)); quadVertexArray->push_back(osg::Vec3(25, 0, 0)); quadVertexArray->push_back(osg::Vec3(25, 25, 0)); quadVertexArray->push_back(osg::Vec3(0, 25, 0)); osg::Vec4Array *quadColorArray = new osg::Vec4Array; quadColorArray->push_back(osg::Vec4(0.0, 1.0, 1.0, 1.0)); quadGeometry->setVertexArray(quadVertexArray); quadGeometry->setColorArray(quadColorArray); quadGeometry->setColorBinding(osg::Geometry::BIND_OVERALL); quadGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4)); quadGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); osg::Stencil *quadStencil = new osg::Stencil; quadStencil->setFunction(osg::Stencil::NOTEQUAL, 0x1, 0x1); quadStencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); quadGeometry->getOrCreateStateSet()->setAttributeAndModes(quadStencil); osg::Geode *geode = new osg::Geode; geode->addDrawable(lineStripGeometry); geode->addDrawable(quadGeometry); --------------------- 作者:csxiaoshui 来源:CSDN 原文:https://blog.csdn.net/csxiaoshui/article/details/23457273 版权声明:本文为博主原创文章,转载请附上博文链接!
标签:Stencil,quadGeometry,lineStripGeometry,back,缓存,模板,new,osg,OSG 来源: https://www.cnblogs.com/coolbear/p/10563381.html