• 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 
    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    php 数组处理
    PHP 递归几种方法
    PHP取一算法
    oracle的db link
    sql2008破解加密存储过程
    ATT 解锁手机
    jQuery 通配符
    win10 Enable developer Mode
    Win8.1 远程桌面 凭据无法工作
    html5media.js 让浏览器兼容<Video><Audio> 标签
  • 原文地址:https://www.cnblogs.com/coolbear/p/10563381.html
Copyright © 2020-2023  润新知