From b5791629eadf91ef41302bf176748f6380a062c5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 3 Jun 2007 09:34:28 +0000 Subject: [PATCH] Added Viewer::setUpViewerAsEmbeddedInWindow convinience method --- examples/osgviewerGLUT/osgviewerGLUT.cpp | 7 +------ examples/osgviewerSDL/osgviewerSDL.cpp | 5 +---- include/osgViewer/Viewer | 7 +++++++ src/osgViewer/Viewer.cpp | 9 +++++++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/osgviewerGLUT/osgviewerGLUT.cpp b/examples/osgviewerGLUT/osgviewerGLUT.cpp index e81217311..adb7f17ea 100644 --- a/examples/osgviewerGLUT/osgviewerGLUT.cpp +++ b/examples/osgviewerGLUT/osgviewerGLUT.cpp @@ -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); diff --git a/examples/osgviewerSDL/osgviewerSDL.cpp b/examples/osgviewerSDL/osgviewerSDL.cpp index 9b9d2f2f2..64f5ebb30 100644 --- a/examples/osgviewerSDL/osgviewerSDL.cpp +++ b/examples/osgviewerSDL/osgviewerSDL.cpp @@ -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 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 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; diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 04454f065..0a1b9a054 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -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, diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 4f65600d8..f0a32ab57 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -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;