|
这里做了一个测试,主要是想看一看,相机渲染先后顺序,代码如下,定义了
两个相机,相机ca用的是PRE_RENDER,相机cm用的是POST_RENDER,然后分别定义了
两个相机PostDrawCallback,在ca相机的回调函数中演示了1s,然后看相机的渲染
先后情况,相应的输出结果如下所示。有人能够解释一下,输出这种结果的原因吗?
1.打印结果的先后顺序,为什么是这样?
- class CameraPostDraw:public osg::Camera::DrawCallback
- {
- public:
-
- CameraPostDraw()
- {}
-
- virtual void operator() (const osg::Camera & camera) const
- {
- std::cout<< "camera 1 callback"<<std::endl;
- Sleep(1000);
- }
- };
复制代码
- class CameraPostDraw2:public osg::Camera::DrawCallback
- {
- public:
-
- CameraPostDraw2()
- {
-
- }
-
- virtual void operator() ( osg::RenderInfo & renderInfo ) const
- {
- std::cout<< "camera 2 callback"<<std::endl;
- }
-
- };
复制代码
- osgViewer::CompositeViewer cview;
- osgViewer::Viewer *view=new osgViewer::Viewer;
- Camera *ca=view->getCamera();
- ca->setViewport(0,0,400,300);
- ca->setViewMatrixAsLookAt(Vec3(0,50,200),Vec3(0,0,0),Vec3(0,0,1));
- ca->setProjectionMatrixAsPerspective(30,1.3,1,1000);
- ca->setGraphicsContext(gc);
- ca->setRenderOrder(osg::Camera::PRE_RENDER);
- ca->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- view->setSceneData(tnode);
- ca->setPostDrawCallback(new CameraPostDraw());
- osgViewer::Viewer *vw=new osgViewer::Viewer;
- //vw->setUpViewInWindow(400,400,400,400);
- osg::Camera *cm=vw->getCamera();
- cm->setViewport(400,300,400,300);
- cm->setProjectionMatrixAsPerspective(30,1.3,1,1000);
- cm->setViewMatrixAsLookAt(Vec3(0,-100,300),Vec3(0,0,0),Vec3(0,0,1));
- cm->setGraphicsContext(gc);
- cm->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- cm->setRenderOrder(osg::Camera::POST_RENDER);
- vw->setSceneData(gnode);
- cm->setPostDrawCallback(new CameraPostDraw2());
- cview.addView(view);
- cview.addView(vw);
- while(!cview.done())
- {
- std::cout<<"main fucntion 1"<<std::endl;
- cview.frame();
- std::cout<<"main fucntion 2"<<std::endl;
- }
复制代码
|
|