|
我想读取本地一张图片,并显示出来,设定viewer窗口的大小和图片分辨率一样的,为什么显示不正常呢,图片偏到右上角了。
- osg::ref_ptr<osg::Image> image=osgDB::readImageFile("my_pic.bmp");
- osgViewer::Viewer viewer;
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- traits->x = 30;
- traits->y = 20;
- traits->width = 600;
- traits->height = 480;
- traits->windowDecoration = true;
- traits->doubleBuffer = true;
- traits->sharedContext = 0;
- traits->pbuffer=false;
- osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
- viewer.getCamera()->setGraphicsContext(gc.get());
- viewer.getCamera()->setViewport(0,0,600,480);
- osg::ref_ptr<osg::DrawPixels> bmp=new osg::DrawPixels;
- bmp->setPosition(osg::Vec3(0,0,0));
- bmp->setImage(image.get());
- osg::ref_ptr<osg::Geode> geode=new osg::Geode;
- geode->addDrawable(bmp.get());
- viewer.setSceneData(geode.get());
- viewer.run();
复制代码 |
|