osg给Box添加材质和纹理

这个博客展示了如何使用OpenSceneGraph(osg)库为Box添加材质和纹理。通过创建osg::Geode对象,设定TessellationHints,定义osg::Material的各个属性以及加载osg::Texture2D,实现了Box的着色和纹理映射。同时,博客还提供了读取图像文件并应用到纹理上的示例代码。
摘要由CSDN通过智能技术生成
#include<Windows.h>//要放在前面
#include<osgDB\ReadFile>
#include<osgViewer\Viewer>
#include<osgGA\GUIEventAdapter>
#include<osgViewer\ViewerEventHandlers>
#include<osg\ShapeDrawable>
#include<osg\Geode>
#include<osg\StateSet>
#include<osg\Image>
#include<osg\Texture2D>
#include<osg\Material>
#include<iostream>

osg::ref_ptr<osg::Geode> GreateBox()
{
	osg::ref_ptr<osg::Geode> geode = new osg::Geode;//Geode是Node的派生类,为了绘制图元的管理类
	osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;//设置精度的类
	osg::ref_ptr < osg::ShapeDrawable >shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0,0.0,0.0),1.0,10.0,10.0),hints.get());
	osg::ref_ptr<osg::Material> material = new osg::Material;
	osg::ref_ptr<osg::Texture2D>texture2D = new osg::Texture2D;
	osg::ref_ptr<osg::Image> image;
	shape->setColor(osg::Vec4(0.5, 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值