用vc6.0编译OpenSceneGraph第一个程序

王朝vc·作者佚名  2006-03-16
窄屏简体版  字體: |||超大  

(1)源程序

#include <osgDB/ReadFile>

#include <osgProducer/Viewer>

#include <osgUtil/Optimizer>

#include <osg/TexGen>

#include <osg/Texture2D>

int main(int argc,char *argv[])

{

std::string filename("cow.osg");

//load the scene.

osg::ref_ptr<osg::Node> loadedModel= osgDB::readNodeFile(filename);

if(!loadedModel)

{

std::cout << argv[0] <<": No data loaded." << std::endl;

return 1;

}

// construct the viewer.

osgProducer::Viewer viewer;

// set up the value with sensible default event handlers.

viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);

// optimize the scene graph,remove redundant nodes and state etc.

osgUtil::Optimizer optimizer;

optimizer.optimize(loadedModel.get());

// add a reflection map to the teapot.

osg::Image* image = osgDB::readImageFile("Images/lz.rgb");

if (image)

{

osg::Texture2D* texture = new osg::Texture2D;

texture->setImage(image);

osg::TexGen* texgen = new osg::TexGen;

texgen->setMode(osg::TexGen::SPHERE_MAP);

osg::StateSet* stateset = new osg::StateSet;

stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);

stateset->setTextureAttributeAndModes(0,texgen,osg::StateAttribute::ON);

loadedModel.get()->setStateSet(stateset);

}

// add model to viewer.

viewer.setSceneData(loadedModel.get());

// create the windows and run the threads.

viewer.realize();

while(!viewer.done())

{

// wait for all cull and draw threads to complete.

viewer.sync();

// update the scene by traversing it with the update visitor which will

// call all node update callbacks and animations.

viewer.update();

// fire off the cull and draw traversals of the scene.

viewer.frame();

}

// wait for all the clean up frame to complete.

viewer.sync();

return 0;

}

(2)编译

Project/Setting->c/c++,在project options的最后一个/c后加上/Zm200

(3)运行错误提示:

Could not find plugin to read objects from file "cow.osg"

这个是要编译osgdb_rgbd.dll

附录:

编译osgteapot时出现runtime errors,解决方法:

(1)Enable Run-Time Type Information(RTTI)

(2)Debug Multithreaded DLL

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航