• OSG学习:多重纹理映射


     
    #include<osgViewerViewer>
    
    #include<osgNode>
    #include<osgGeode>
    #include<osgGeometry>
    #include<osgTexture2D>
    #include<osgTexGen>
    #include<osgTexEnv>
    
    #include<osgDBReadFile>
    #include<osgDBWriteFile>
    
    #include<osgUtilOptimizer>
    
    int main()
    {
    	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
    
    	osg::ref_ptr<osg::Group> root = new osg::Group();
    
    	osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("cow.osg");
    
    	//读取贴图
    	osg::ref_ptr<osg::Image> image = osgDB::readImageFile("Images/primitives.gif");
    
    	if (image.get())
    	{
    		//创建二维纹理
    		osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
    		texture->setImage(image.get());
    
    		//设置自动生成坐标
    		osg::ref_ptr<osg::TexGen> texgen = new osg::TexGen;
    		texgen->setMode(osg::TexGen::SPHERE_MAP);
    
    		//设置文理环境,模式为BLEND
    		osg::ref_ptr<osg::TexEnv> texenv = new osg::TexEnv;
    		texenv->setMode(osg::TexEnv::BLEND);
    		//设置BLEND操作的颜色
    		texenv->setColor(osg::Vec4(0.6f, 0.6f, 0.6f, 0.0f));
    
    		//启用单元1自动生成文理坐标,并使用纹理
    		osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
    		stateset->setTextureAttributeAndModes(1, texture.get(), osg::StateAttribute::ON);
    		stateset->setTextureAttributeAndModes(1, texgen.get(), osg::StateAttribute::ON);
    
    		//设置纹理环境
    		stateset->setTextureAttribute(1, texenv.get());
    	}
    
    	root->addChild(node.get());
    
    	//优化场景数据
    	osgUtil::Optimizer optimizer;
    	optimizer.optimize(root.get());
    
    	viewer->setSceneData(root.get());
    
    	viewer->realize();
    
    	viewer->run();
    
    	return 0;
    }


    结果图:



  • 相关阅读:
    RabbitMQ的ACK机制
    Flex保存文件 FileReference.save(data,filename)
    Flex Builder cannot locate the required debugger version of Flash Player
    Flex每日小记
    IT民工
    R读取文件内容到Frame
    ArcGIS9.2 9.3
    超时空的心情
    ArcMap中设置.mxd相对路径
    MyEclipse Flex Tomcat BlazeDS
  • 原文地址:https://www.cnblogs.com/huahai/p/7270945.html
Copyright © 2020-2023  润新知