|
我是个OSG初学者,仿照osgoutline的例子显示box轮廓线正常,代码如下:
- int main(int argc, char **argv)
- {
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(), 2)));
-
- osg::ref_ptr<osg::Group> root = new osg::Group;
- osg::ref_ptr<osgFX::Outline> outline = new osgFX::Outline;
- root->addChild(outline.get());
- outline->setWidth(8);
- outline->setColor(osg::Vec4(1,1,0,1));
- outline->addChild(geode.get());
- // must have stencil buffer...
- osg::DisplaySettings::instance()->setMinimumNumStencilBits(1);
- // construct the viewer
- osgViewer::Viewer viewer;
- viewer.setSceneData(root.get());
- // must clear stencil buffer...
- unsigned int clearMask = viewer.getCamera()->getClearMask();
- viewer.getCamera()->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT);
- viewer.getCamera()->setClearStencil(0);
- viewer.setUpViewInWindow(100, 100, 800, 600);
- return viewer.run();
- }
复制代码
box
但是我想画一个矩形的轮廓线,main函数前两句改为
- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- v->push_back(osg::Vec3(1, 1, 1));
- v->push_back(osg::Vec3(2, 1, 1));
- v->push_back(osg::Vec3(2, 2, 1));
- v->push_back(osg::Vec3(1, 2, 1));
- geom->setVertexArray(v.get());
- osg::ref_ptr<osg::DrawElementsUInt> quad = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
- quad->push_back(0);
- quad->push_back(1);
- quad->push_back(2);
- quad->push_back(3);
- geom->addPrimitiveSet(quad.get());
- osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
- c->push_back(osg::Vec4(1, 0, 0, 1));
- geom->setColorArray(c.get());
- geom->setColorBinding(osg::Geometry::BIND_OVERALL);
- osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
- n->push_back(osg::Vec3(0, 0, 1));
- geom->setNormalArray(n.get());
- geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable(geom.get());
复制代码
矩形下方可以正常显示轮廓线,但是矩形上方无法显示
下方
上方
请大家帮我看看问题出在哪里?谢谢 |
|