|
本帖最后由 zhuliangxiong 于 2009-9-4 01:20 编辑
写了一小段代码 将GIS数据作为纹理贴到地形上.下面是主要的代码.目前出来的效果是这样的.纹理没贴上去,而且显示效果也非常卡.
不使用纹理烘焙的时候,不管是二维矢量数据还是三维的地形数据本身都可以贴上纹理 而且显示效果很流畅.
请帮忙分析一下代码,我现在感觉 纹理没贴上是因为内部的camera的观察矩阵没有设置好.但是为什么系统这么慢呢?- void applyTextureToGis(){
- Group* root=new Group();
- Node* terrain=osgDB::readNodeFile ("1000/county10.ive");
- Group* gp=OsgHelper::readShapefile ("hh/county10.shp")->asGroup();
- string images[]={"images/skymap.jpg","images/land01.jpg"};
- //首先把原始的纹理贴在二维的GIS节点上
- for(unsigned int i=0;i<gp->getNumChildren ();i++){
- Geode* node=gp->getChild (i)->asGeode ();
- Image* img=osgDB::readImageFile (images[i%2]);
- applyGeode(node,img,2,2);
- }
- //构造一个Camera,将二维GIS节点添加到Camera.
- BoundingBox box=OsgHelper::computeBoundingBox (terrain);
- int w=(box.xMax ()-box.xMin());
- int h=(box.yMax ()-box.yMin());
- int txt_width=800,txt_height=450;
- Camera *camera=new Camera;
- camera->setClearColor(osg::Vec4(1.f,1.f,1.f,1.0f));
- camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- camera->setProjectionMatrix(osg::Matrix::ortho2D(-w/2,w/2,-h/2,h/2));
- camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
-
- camera->setViewport(0,0,txt_width,txt_height);
- camera->setRenderOrder(osg::Camera::POST_RENDER);
- camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
- //构造一个Image,让Camera的COLOR_BUFFER连接到这个Image.
- Image* txtImg=new Image();
- txtImg->allocateImage(txt_width, txt_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
- camera->attach(osg::Camera::COLOR_BUFFER,txtImg,0,0);
- camera->addChild (gp);
- //把这个Image做为纹理贴到地形上去.
- applyTexture(terrain,txtImg,1.0,1.0);
- root->addChild (camera);
- root->addChild(terrain);
- Viewer view;
- view.setSceneData (root);
- view.run();
- }
复制代码 |
|