#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,
osg给Box添加材质和纹理
最新推荐文章于 2023-12-17 00:05:51 发布
这个博客展示了如何使用OpenSceneGraph(osg)库为Box添加材质和纹理。通过创建osg::Geode对象,设定TessellationHints,定义osg::Material的各个属性以及加载osg::Texture2D,实现了Box的着色和纹理映射。同时,博客还提供了读取图像文件并应用到纹理上的示例代码。
摘要由CSDN通过智能技术生成