osg::Geomtery多图元重叠闪烁问题

在使用osg库进行图形绘制时,DrawGeom函数中遇到多图元重叠部分出现闪烁的问题。尝试了多种方法,但无法有效解决,由于缺乏扎实的OpenGL基础,导致进展困难。博主分享了初学osg时的困扰和学习过程。

void DrawGeom()

{

if(!_geom.valid())

    {
        _geom = new osg::Geometry;
        _geom->setDataVariance(osg::Object::DYNAMIC);\
        _geom->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
        _geom->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
        osg::ref_ptr<osg::CullFace> cullface = new osg::CullFace(osg::CullFace::BACK);
             _geom->getOrCreateStateSet()->setAttribute(cullface.get());
     
                osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
                polyoffset->setFactor(-100.0f);
                polyoffset->setUnits(-10.0f);
                osg::PolygonMode* polymode = new osg::PolygonMode;
                polymode->setMode(osg::PolygonMode::FRONT,osg::PolygonMode::FILL);
                _geom->getOrCreateStateSet()->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
                _geom->getOrCreateStateSet()->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
        //定义颜色数组
        osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
        _geom->setColorArray(c.get());
        _geom->setColorBinding(osg::Geometry::BIND_OVERALL);
        c->push_back(_LineColor);
        //定义法线
        osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
        _geom->setNormalArray(n.get());
        _geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
        n->push_back(osg::Vec3(0.f, -1.f, 0.f));
        _pointArray = new osg::Vec3Array;
        _geom->setVertexArray(_pointArray.get());
        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
        geode->addDrawable(_geom.get());
        //geode->setUpdateCallback(new FadeCallback(_LineColor));
        geode->getOrCreateStateSet()->setAttributeAndModes(new osg::BlendFunc);
        geode->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
        geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
        _shapeGroup->addChild(geode.get());
        primitiveSetCount = 0L;
    }
    _pointArray->push_back(wp1*mat);
    _pointArray->push_back(wp2*mat);
    _pointArray->push_back(wp3*mat);
    _pointArray->push_back(wp4*mat);
    _geom->addPrimitiveSet(
                new osg::DrawArrays(osg::PrimitiveSet::QUADS, primitiveSetCount*4, 4));
    primitiveSetCount++;

}

这样还是会有重叠的效果  试过很多方法 还是不行  没有好的opengl基础 真是空中楼阁  碰到点难得就不会 完全没有思路 跟着网上的东西走 心累 初学osg 记录自己的心路历程



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值