|
就是画一个正方形, 非常简单, 然后照上
Group::getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::ON |osg::StateAttribute::OVERRIDE);
可是,光照效果非常弱, 很黑. 设定了normal, 正方形的一个面完全就看不到, 彻底黑(这是应该的吧); 但是把正方形翻转过来, 不是彻底黑,但是只能看到一点浅浅的灰黑色. (我觉得应该是白花花的颜色啊)
这究竟是为何?
画正方形代码非常简单: 如下:
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- osg::ref_ptr<osg::LineWidth> linewidth = new osg::LineWidth;
- v->push_back(leftTop);
- v->push_back(rightTop);
- v->push_back(rightBottom);
- v->push_back(leftBottom);
- osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array;
- color->push_back(osg::Vec4(1.0,1.0,1.0,1.0));
- osg::ref_ptr<osg::DrawArrays> da = new osg::DrawArrays(GL_QUADS, 0, v->size());
- geometry->setVertexArray(v);
- geometry->addPrimitiveSet(da);
- geometry->setColorArray(color);
- geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
- osg::Vec3Array* quadNormal = new osg::Vec3Array;
- geometry->setNormalArray(quadNormal);
- geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
- quadNormal->push_back(osg::Vec3(0.f, 1.0f, 0.0f));
- linewidth->setWidth(2.0);
- geode->addDrawable(geometry);
- geometry->getOrCreateStateSet()->setAttributeAndModes(linewidth, osg::StateAttribute::ON);
- geometry->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
- geometry->getOrCreateStateSet()->setMode(GL_LINE_SMOOTH, osg::StateAttribute::ON);
- geometry->getOrCreateStateSet()->setRenderBinDetails( 20, "TraversalOrderBin",
- osg::StateSet::USE_RENDERBIN_DETAILS );
- geometry->getOrCreateStateSet()->setNestRenderBins(true);
- ////////////////////////////////
- geometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);
复制代码 |
-
一面是彻底黑色
-
另一面(光照面) 颜色深得几乎看不到
|