diff --git a/src/Viewer/WindowBuilder.cxx b/src/Viewer/WindowBuilder.cxx index 90eaac00a..4bedcd77e 100644 --- a/src/Viewer/WindowBuilder.cxx +++ b/src/Viewer/WindowBuilder.cxx @@ -249,6 +249,11 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode, bool i return result; } auto traits = new GraphicsContext::Traits(*defaultTraits); + + // Attempt to share context with the window that was created first + if (!wsa->windows.empty()) + traits->sharedContext = wsa->windows.front()->gc; + int traitsSet = setFromProperty(traits->hostName, winNode, "host-name"); traitsSet |= setFromProperty(traits->displayNum, winNode, "display"); traitsSet |= setFromProperty(traits->screenNum, winNode, "screen"); diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index 87c568f47..419c01697 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -1106,13 +1106,27 @@ FGRenderer::setEventHandler(FGEventHandler* eventHandler_) void FGRenderer::addCamera(osg::Camera* camera, bool useSceneData) { - _viewerSceneRoot->addChild(camera); + osg::Camera *guiCamera = getGUICamera(CameraGroup::getDefault()); + osg::GraphicsContext *gc = guiCamera->getGraphicsContext(); + camera->setGraphicsContext(gc); + if (composite_viewer) { + composite_viewer->getView(0)->addSlave(camera, false); + } else { + viewer->addSlave(camera, false); + } } void FGRenderer::removeCamera(osg::Camera* camera) { - _viewerSceneRoot->removeChild(camera); + if (composite_viewer) { + unsigned int index = composite_viewer->getView(0) + ->findSlaveIndexForCamera(camera); + composite_viewer->getView(0)->removeSlave(index); + } else { + unsigned int index = viewer->findSlaveIndexForCamera(camera); + viewer->removeSlave(index); + } } void