• 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 
    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    boost::asio::error的用法浅析
    boost::asio::buffer
    sqlserver2008安装图解
    WCF 聊天室程序代码详细讲解教程
    C#中使用Property Grid(属性面板)控件
    TXT>Access 使用DAO数据源!(VB Code)
    读取INI文件 VbCode
    Pet Shop 4
    模式行为型
    C#编程规范
  • 原文地址:https://www.cnblogs.com/coolbear/p/10563381.html
Copyright © 2020-2023  润新知