osg::Sphere,osg::Texture2D,osg::StateSet,osg::TexEnv的使用
2012-02-21 11:12
316 查看
//By smells2 at Lab 2012-02-21 #include <osg/Group> #include <osg/Geode> #include <osg/ShapeDrawable> #include <osg/Texture2D> #include <osgViewer/Viewer> #include <osgDB/readfile> #include <osg/PositionAttitudeTransform> #include <osg/TexEnv> #include <osg/Texture2D> #include <iostream> int main() { osg::ref_ptr<osg::Group> root = new osg::Group; osgViewer::Viewer myViewer; //Declear Sphere instance,the constructor takes an osg::vec3 to define //center and a float to define the radius. //Then we declear the ShapDrawable instance that derive from Drawable .We should //initalize it with the shape we create above . osg::ref_ptr<osg::Geode> unitSphere = new osg::Geode; osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(osg::Vec3(0,0,0), 1.0f); osg::ref_ptr<osg::ShapeDrawable> shapeDrawable = new osg::ShapeDrawable(sphere.get()); unitSphere->addDrawable(shapeDrawable.get()); osg::ref_ptr<osg::PositionAttitudeTransform> sphereForm = new osg::PositionAttitudeTransform; sphereForm->setPosition(osg::Vec3(2.5,0.0,0.0)); sphereForm->addChild(unitSphere.get()); root->addChild(sphereForm.get()); //load image from the file osg::ref_ptr<osg::Texture2D> earthTexture = new osg::Texture2D; earthTexture->setDataVariance(osg::Object::DYNAMIC); osg::ref_ptr<osg::Image> earthImage = osgDB::readImageFile("D:\\OSG\\osg2.9\\OpenSceneGraph2.9.5\\data\\Images\\land_shallow_topo_2048.jpg"); if (!earthImage.get()) { std::cout<<"load texture failed !"<<std::endl; return -1; } //assign the texture from the image file earthTexture->setImage(earthImage.get()); //set the stateset for decal texture osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv; osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet; texenv->setMode(osg::TexEnv::DECAL); stateset->setTextureAttributeAndModes(0,earthTexture.get(),osg::StateAttribute::ON); stateset->setTextureAttribute(0,texenv.get()); //realize root->setStateSet(stateset.get()); myViewer.setSceneData(root.get()); myViewer.realize(); myViewer.run(); }
相关文章推荐
- Android 中使用OpenGL ES进行2D开发(纹理Texture使用)
- opengl 使用 texture2d 关键步骤
- 【Unity Shaders】Diffuse Shading——使用2D ramp texture来创建一个假的BRDF(双向反射分布函数)
- 【Unity Shaders】Diffuse Shading——使用2D ramp texture来创建一个假的BRDF(双向反射分布函数)
- Texture2D.GetPixelBilinear(float u, float v)的使用,官方例子注释
- unity3D ShaderLab <五>漫反射光照改善技巧之使用2D ramp texture来创建一个假的BRDF(双向反射分布函数)
- Android 中使用OpenGL ES进行2D开发(纹理Texture使用)
- OSG与Qt结合--成功使用QTabWidget
- iOS开发UI高级—38Quartz2D使用(绘制基本图形)
- 在iOS开发的Quartz2D使用中实现图片剪切和截屏功能
- iOS-绘图(Quartz2D)的简单使用(原创)
- Unity在运行时,将Texture2D转换成Sprite格式
- cocos2dx使用TiledMap模拟3D地图场景----斜45度2D地图的靠墙直线移动
- Quartz2D之渐变使用初步
- 使用路径(1)Quartz 2D
- 【使用Unity开发Windows Phone上的2D游戏】(2)初识工具
- android 下使用Direct Texture
- iOS开发UI篇—Quartz2D使用(图形上下文栈)
- LibGdx UI编辑器 OverLap2D 学习(2) 学习UI使用,通过Button学习
- Opengl学习笔记之Texture 2D Array