OSG绘制四边形
代码实现绘制四边形,保存为osg 并读取显示
#include<osg/Geode>
#include<osg/Geometry>
#include<osgDB/ReadFile>
#include<osgDB/WriteFile>
#include<osgViewer/Viewer>
osg::ref_ptr<osg::Node> createSceneGraph()
{
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
//顶点数组
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
geom->setVertexArray(v.get());
v->push_back(osg::Vec3(-1.0f, 0.0f, -1.0f));
v->push_back(osg::Vec3(-1.0f, 0.0f, 1.0f));
v->push_back(osg::Vec3(1.0f, 0.0f, 1.0f));
v->push_back(osg::Vec3(1.0f, 0.0f, -1.0f));
//颜色数组
osg::ref_ptr<osg::Vec4Array> cr = new osg::Vec4Array;
geom->setColorArray(cr.get());
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
cr->push_back(osg::Vec4(1.0f, 0.0f, 0.0f,1.0f));
cr->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
cr->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
cr->push_back(osg::Vec4(1.0f, 1.0f