Added Viewer::setUpViewerAsEmbeddedInWindow convinience method

This commit is contained in:
Robert Osfield 2007-06-03 09:34:28 +00:00
parent 089b9dbd88
commit b5791629ea
4 changed files with 18 additions and 10 deletions

View File

@ -91,14 +91,9 @@ int main( int argc, char **argv )
glutMotionFunc( mousemove );
glutKeyboardFunc( keyboard );
window = new osgViewer::GraphicsWindowEmbedded(100,100,800,600);
// create the view of the scene.
viewer = new osgViewer::Viewer;
viewer->getCamera()->setGraphicsContext(window.get());
viewer->getCamera()->setViewport(new osg::Viewport(0,0,800,600));
viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
window = viewer->setUpViewerAsEmbeddedInWindow(100,100,800,600);
viewer->setSceneData(loadedModel.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
viewer->addEventHandler(new osgViewer::StatsHandler);

View File

@ -108,15 +108,12 @@ int main( int argc, char **argv )
// If we used 0 to set the fields, query the values so we can pass it to osgViewer
windowWidth = screen->w;
windowHeight = screen->h;
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> gw = new osgViewer::GraphicsWindowEmbedded(0,0,windowWidth,windowHeight);
osgViewer::Viewer viewer;
viewer.getCamera()->setGraphicsContext(gw.get());
viewer.getCamera()->setViewport(new osg::Viewport(0,0,windowWidth,windowHeight));
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> gw = viewer.setUpViewerAsEmbeddedInWindow(0,0,windowWidth,windowHeight);
viewer.setSceneData(loadedModel.get());
viewer.setCameraManipulator(new osgGA::TrackballManipulator);
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
viewer.realize();
bool done = false;

View File

@ -47,8 +47,15 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
/** Set the sene graph data that viewer with view.*/
virtual void setSceneData(osg::Node* node);
/** Convinience method for setting up the viewer so it can be used embedded in an external managed window.
* Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer. */
virtual GraphicsWindowEmbedded* setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height);
enum ThreadingModel
{
SingleThreaded,

View File

@ -773,6 +773,15 @@ void Viewer::setSceneData(osg::Node* node)
setUpRenderingSupport();
}
GraphicsWindowEmbedded* Viewer::setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height)
{
setThreadingModel(SingleThreaded);
osgViewer::GraphicsWindowEmbedded* gw = new osgViewer::GraphicsWindowEmbedded(x,y,width,height);
getCamera()->setViewport(new osg::Viewport(0,0,width,height));
getCamera()->setGraphicsContext(gw);
return gw;
}
void Viewer::setThreadingModel(ThreadingModel threadingModel)
{
if (_threadingModel == threadingModel) return;