正在加载图片...
osg:Geode*pyramidGeode createPyramid(); root->addChild(pyramidGeode); 现在,准备加纹理。这里我们会声明一个纹理实例并将它的数据不一致性设为‘DYNAMIC'。(如 果不把纹理声明为dynamic,osg的一些优化程序会删除它。)这个texture类包装了OpenGL纹理 模式(wrap,filter,等等)和一个osg:Image.。下面的代码说明了如何从文件里读取osg:Image 实例并把这个图像和纹理关联起来。 osg:Texture2D*KLN89FaceTexture new osg:Texture2D: /protect from being optimized away as static state: KLN89FaceTexture->setDataVariance(osg:Object:DYNAMIC): /load an image by reading a file: osg:Image*kInFace osgDB:readImageFile("KLN89FaceB.tga"); if (!klnFace) { std:cout <<couldn't find texture,quiting."<<std:endl; return -1; /Assign the texture to the image we read from file: KLN89FaceTexture->setImage (klnFace); 纹理可以和渲染StateSet关联起来。下一步就产生一个StateSet,关联并启动我们的纹理,并 将这个StateSet附加到我们的geometry上。 //Create a new StateSet with default settings: osg:StateSet*stateOne new osg:StateSet () /Assign texture unit 0 of our new StateSet to the texture /we just created and enable the texture. stateOne->setTextureAttributeAndModes(0,KLN89FaceTexture, osg:StateAttribute:ON); /Associate this state set with the Geode that contains /the pyramid: pyramidGeode->setStateSet(stateOne); 最后一步是仿真循环: //The final step is to set up and enter a simulation loop. viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS): viewer.setSceneData(root ) viewer.realize(); while(!viewer.done()) { viewer.sync(); viewer.update(); viewer.frame(); return 0: >7 osg::Geode* pyramidGeode = createPyramid(); root->addChild(pyramidGeode); 现在,准备加纹理。这里我们会声明一个纹理实例并将它的数据不一致性设为‘DYNAMIC'。(如 果不把纹理声明为 dynamic,osg 的一些优化程序会删除它。)这个 texture 类包装了 OpenGL 纹理 模式(wrap,filter,等等)和一个 osg::Image。下面的代码说明了如何从文件里读取 osg::Image 实例并把这个图像和纹理关联起来。 osg::Texture2D* KLN89FaceTexture = new osg::Texture2D; // protect from being optimized away as static state: KLN89FaceTexture->setDataVariance(osg::Object::DYNAMIC); // load an image by reading a file: osg::Image* klnFace = osgDB::readImageFile("KLN89FaceB.tga"); if (!klnFace) { std::cout << " couldn't find texture, quiting." << std::endl; return -1; } // Assign the texture to the image we read from file: KLN89FaceTexture->setImage(klnFace); 纹理可以和渲染 StateSet 关联起来。下一步就产生一个 StateSet,关联并启动我们的纹理,并 将这个 StateSet 附加到我们的 geometry 上。 // Create a new StateSet with default settings: osg::StateSet* stateOne = new osg::StateSet(); // Assign texture unit 0 of our new StateSet to the texture // we just created and enable the texture. stateOne->setTextureAttributeAndModes(0,KLN89FaceTexture, osg::StateAttribute::ON); // Associate this state set with the Geode that contains // the pyramid: pyramidGeode->setStateSet(stateOne); 最后一步是仿真循环: //The final step is to set up and enter a simulation loop. viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); viewer.setSceneData( root ); viewer.realize(); while( !viewer.done() ) { viewer.sync(); viewer.update(); viewer.frame(); } return 0; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有