OSG第一个程序-绘制四边形保存读取

这篇博客介绍了如何用OpenSceneGraph(OSG)实现四边形的绘制,并详细说明了如何将绘制的四边形保存为osg文件以及之后的读取和显示过程。代码实现中特别提示注意文件路径的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值