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

2004

被折叠的 条评论
为什么被折叠?



