OSG基本图元随笔

创建图元大致结构

  • osg::Geode
    • osg::ShapeDrawable
      • osg::Color
    • osg::Material
    • osg::Texture2D
      • osg::Image

创建osg::Geode的实例

osg::ref_ptr<osg::Geode> geode=new osg::Geode;

Image的读取可以使用以下模板例子

osg::ref_ptr<osg::Texture2D> t2d=new osg::Texture2D;
osg::ref_ptr<osg::Image> image=osgDB::readImageFile("imagepath");
if(image.valid()){
    t2d->setImage(0,image.get());
}

最后将osg::Texture2D添加到osg::Geode的属性中

geode->getOrCreateStateSet()->setTextureAttributeAndModes(0,t2d.get(),osg::StateAttribute::ON);

注 * 以上省略了向geode中添加osg::shapedrawable的操作

关于自定义图形形状

  • 需要用到osg::Geometry,将设计好的osg::Geometry添加到osg::Geode中。
  • osg::Geode继承自osg::Node

  • 可以自定义形状

    • 顶点位置
    • 顶点颜色
    • 形状的法线
    • 形状的线宽
    osg::ref_ptr<osg::Vec3Array> coord = new osg::Vec3Array;
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    osg::ref_ptr<osg::LineWidth> width = new osg::LineWidth;

其中,形状的线宽需要在osg::Geode中设置,而非osg::Geometry

本文为博主学习OSG时的自我总结和记录,如出现错误的地方,还请留言指正,共同进步

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值