/** Run the dynamics for a cycle. */ void run( Real dt ) { // fetch the command in the buffer //get_command(); #ifdef USE_OSG if (ONSCREEN_RENDER) { if (viewer.done()) return; viewer.frame(); } #endif // Note: research how the original driver sets up all the parameters that // drive step size. sim->step(dt) is not sufficient in and of itself so // there must be another or more parameters that manipulate this state info //sim->step( dt ); // step the sim forward STEP_SIZE = dt; step((void*) &sim); // publish any state change //publish_state(); //#ifdef USE_OSG //usleep(DYNAMICS_FREQ); //#endif }
int main(int argc, char** argv) { viewer.setSceneData(root.get()); filename = argv[1]; startMenu = new StartMenu(&viewer, startApplication); root->addChild(startMenu->_camera); if(root.valid()) { //viewer.setCameraManipulator(new osgGA::TrackballManipulator()); viewer.realize(); while(!viewer.done()) { viewer.frame(); //update(); } } else { std::cout << "Invalid Graph!" << std::endl; } return 0; }
/// Utility function you call before something you want to time, so that the /// recorded times will all be consistent using the viewer's time. void startTiming(osgViewer::Viewer& viewer, const std::string& name) { osg::Timer_t tick = osg::Timer::instance()->tick(); double currentTime = osg::Timer::instance()->delta_s(viewer.getStartTick(), tick); int framenumber = viewer.getFrameStamp()->getFrameNumber(); viewer.getViewerStats()->setAttribute(framenumber, name + " begin", currentTime); }
Level::Level(const std::string &mapfile) : _numDeaths(0), _reachedFinish(false) { _shadowedScene = new osgShadow::ShadowedScene; _shadowedScene->setReceivesShadowTraversalMask(RECEIVE_SHADOW_MASK); _shadowedScene->setCastsShadowTraversalMask(CAST_SHADOW_MASK); _shadowedScene->setShadowTechnique(new osgShadow::ShadowMap); addChild(_shadowedScene); _headUpDisplay = new HeadUpDisplay(); addChild(_headUpDisplay->getCamera()); addChild((new Sky())->getCamera()); initializePhysicsWorld(); // load map from file loadMapFromFile(mapfile); // add player to level _shadowedScene->addChild(Player::getInstance()); addChild(Player::getInstance()->getParticleEffects()); // add player ghost object to world _physicsWorld->addCollisionObject(Player::getInstance()->getGhostObject(), btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter); // register player controller _physicsWorld->addAction(Player::getInstance()->getController()); // initialize members LazyCameraManipulator *cameraManipulator = new LazyCameraManipulator(); // setup manipulator to track the player cameraManipulator->setTrackNode(Player::getInstance()); cameraManipulator->setHomePosition(LEVEL_CAMERA_HOME_EYE, LEVEL_CAMERA_HOME_CENTER, LEVEL_CAMERA_HOME_UP); // player must be updated after physic is updated Player::getInstance()->setUpdateCallback(new PlayerUpdater()); // set _cameraManipulator as manipulator for the scene viewer.setCameraManipulator(cameraManipulator); LevelUpdater *stepCallback = new LevelUpdater(this); setUpdateCallback(stepCallback); // player keyboard control _keyboardHandler = new LevelKeyboardHandler(); viewer.addEventHandler(_keyboardHandler); initializeLighting(); Sound::getInstance()->stop(MENU_MUSIC_FILE); Sound::getInstance()->playInLoop(LEVEL_MUSIC_FILE); }
void viewerSetUp( osgViewer::Viewer& viewer, unsigned int width, unsigned int height, osg::Node* node ) { double aspect = (double)width / (double)height; viewer.setThreadingModel( osgViewer::ViewerBase::SingleThreaded ); viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR ); viewer.getCamera()->setProjectionMatrix( createProjection( aspect ) ); viewer.getCamera()->setClearMask( 0 ); viewer.setSceneData( backdropFX::Manager::instance()->getManagedRoot() ); // No longer needed, apparently. Seems like Viewer used to focus the // camera manipulator on the entire SkyDome, putting it too far away from // the scene. This code compensated for that. //osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator(); //viewer.setCameraManipulator( tb ); //tb->setNode( root.get() ); //tb->home( 0 ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::ThreadingHandler ); viewer.addEventHandler( new ResizeHandler( viewer, width, height ) ); osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator; viewer.setCameraManipulator( tbm ); tbm->setNode( node ); tbm->home( 0 ); }
// Step the dynamics forward void step( const Real &dt ) { #ifdef USE_OSG if( ONSCREEN_RENDER ) { if( viewer.done( ) ) return; viewer.frame( ); } #endif // step the sim forward STEP_SIZE = dt; step( (void*) &sim ); }
void AppState::updateNear() { // Assume that the viewing frustum is symmetric. double fovy, aspectRatio, cNear, cFar; viewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, cNear, cFar); viewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, cFar); stringstream nearStream; nearStream << "near: " << zNear; zNearText->setText(nearStream.str()); zNearText->update(); }
void InitWnd(osgViewer::Viewer &viewer) { int xoffset = 40; int yoffset = 40; osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = xoffset + 0; traits->y = yoffset + 0; traits->width = 600; traits->height = 480; traits->windowDecoration = true; traits->doubleBuffer = true; traits->sharedContext = 0; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera; camera->setGraphicsContext(gc.get()); camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; camera->setDrawBuffer(buffer); camera->setReadBuffer(buffer); //camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //camera->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f)); //camera->setProjectionMatrixAsPerspective( // 30.0f, static_cast<double>(traits->width) / static_cast<double>(traits->height), 1.0, 1000.0); // add this slave camera to the viewer, with a shift left of the projection matrix viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0, 0.0, 0.0), osg::Matrixd()); }
void setViewer(osgViewer::Viewer& viewer, float width, float height, float distance) { double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0); // double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0); viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0); }
void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer) { osg::notify(osg::INFO)<<"received events = "<<_events.size()<<std::endl; // copy the events to osgProducer style events. viewer.getEventQueue()->appendEvents(_events); }
void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name) { osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device_name); if (dev.valid()) { OSG_INFO << "Adding Device : " << device_name << std::endl; viewer.addDevice(dev.get()); if (dev->getCapabilities() & osgGA::Device::SEND_EVENTS) viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get())); } else { OSG_WARN << "could not open device: " << device_name << std::endl; } }
void LevelMenu::loadLevels() { _itemsPat = new osg::PositionAttitudeTransform(); _itemsPat->setPosition(osg::Vec3(viewer.getCamera()->getViewport()->width() - 400, viewer.getCamera()->getViewport()->height() - 250, 0)); // load XML document rapidxml::file<> mf(LEVEL_OVERVIEW_FILE); rapidxml::xml_document<> xml_doc; xml_doc.parse<0>(mf.data()); int itemIndex = 0; // parse XML document for(rapidxml::node_iterator<char> it(xml_doc.first_node()); it.dereference() != NULL; ++it, ++itemIndex) { if(strcmp(it->name(), "road") == 0) { std::string name = it->first_attribute("name")->value(); osg::Geode *itemNode = new osg::Geode(); osgText::Text *text = new osgText::Text(); text->setFont(MENU_FONT); text->setPosition(osg::Vec3(0, - (itemIndex * MENU_ITEM_HEIGHT), 0)); text->setText(name); itemNode->addDrawable(text); _itemsPat->addChild(itemNode); std::map<std::string, std::string> item; item["name"] = it->first_attribute("name")->value(); item["filename"] = it->first_attribute("filename")->value(); item["besttime"] = it->first_attribute("besttime")->value(); item["completions"] = it->first_attribute("completions")->value(); item["deaths"] = it->first_attribute("deaths")->value(); _items.push_back(item); } else { throw std::runtime_error("Error: Unrecognized element in level file!"); } } _menuPat->addChild(_itemsPat); }
/// Utility function you call after something you want to time, so that the /// recorded times will all be consistent using the viewer's time. void endTiming(osgViewer::Viewer& viewer, const std::string& name) { osg::Timer_t tick = osg::Timer::instance()->tick(); double currentTime = osg::Timer::instance()->delta_s(viewer.getStartTick(), tick); int framenumber = viewer.getFrameStamp()->getFrameNumber(); viewer.getViewerStats()->setAttribute(framenumber, name + " end", currentTime); double begin = 0.0; double elapsed = 0.0; if (viewer.getViewerStats()->getAttribute(framenumber, name + " begin", begin)) { elapsed = currentTime - begin; } viewer.getViewerStats()->setAttribute(framenumber, name + " time taken", elapsed); }
void CameraPacket::readEventQueue(osgViewer::Viewer& viewer) { _events.clear(); viewer.getEventQueue()->copyEvents(_events); osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl; }
void SetCameraProjectionMatrix (osgViewer::Viewer& viewer, dFloat viewAngleInDegress, dFloat aspectRatio, dFloat nearPlane, dFloat farPlane) { osg::Camera* const camera = viewer.getCamera(); camera->setProjectionMatrixAsPerspective (viewAngleInDegress, aspectRatio, nearPlane, farPlane); // camera->setViewMatrixAsLookAt (osg::Vec3 (-3.0f, -5.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 1.0f)); camera->setViewMatrixAsLookAt (osg::Vec3 (-0.0f, -5.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 1.0f)); }
void viewerSetUp( osgViewer::Viewer& viewer, double aspect, osg::Node* node ) { viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR ); viewer.getCamera()->setProjectionMatrixAsPerspective( 35., aspect, .1, 50. ); viewer.getCamera()->setClearMask( 0 ); viewer.setSceneData( backdropFX::Manager::instance()->getManagedRoot() ); // No longer needed, apparently. Seems like Viewer used to focus the // camera manipulator on the entire SkyDome, putting it too far away from // the scene. This code compensated for that. //osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator(); //viewer.setCameraManipulator( tb ); //tb->setNode( root.get() ); //tb->home( 0 ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::ThreadingHandler ); osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator; viewer.setCameraManipulator( tbm ); tbm->setNode( node ); tbm->home( 0 ); }
void LevelMenu::returnFromLevel() { if(_currentLevel->playerReachedFinish()) { // update completions { std::stringstream ss; ss << atoi(_items[_currentItemIndex]["completions"].c_str()) + 1; _items[_currentItemIndex]["completions"] = ss.str(); } // update best time { time_t t = _currentLevel->getTime(); if(_items[_currentItemIndex]["besttime"] == "" | t < atol(_items[_currentItemIndex]["besttime"].c_str())) { std::stringstream ss; ss << t; _items[_currentItemIndex]["besttime"] = ss.str(); } } } // update number of deaths { std::stringstream ss; ss << atoi(_items[_currentItemIndex]["deaths"].c_str()) + _currentLevel->getNumDeaths(); _items[_currentItemIndex]["deaths"] = ss.str(); } viewer.setCameraManipulator(NULL); viewer.getCamera()->setViewMatrixAsLookAt(MENU_CAMERA_HOME_EYE, MENU_CAMERA_HOME_CENTER, MENU_CAMERA_HOME_UP); _currentLevel->resetScene(); viewer.setSceneData(this); _currentLevel = NULL; Player::getInstance()->reset(); updateDetails(); Sound::getInstance()->stop(LEVEL_MUSIC_FILE); Sound::getInstance()->playInLoop(MENU_MUSIC_FILE); }
void setViewer(osgViewer::Viewer& viewer, float width, float height, float distance) { double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0); // double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0); viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0); OSG_NOTICE<<"setProjectionMatrixAsPerspective( "<<vfov<<", "<<width/height<<", "<<0.1<<", "<<1000.0<<");"<<std::endl; }
void Level::playerDied() { Player::getInstance()->getPlayerState()->setSpeed(0.0f); Player::getInstance()->resetPosition(); ((LazyCameraManipulator *)viewer.getCameraManipulator())->resetCamera(); _headUpDisplay->resetTimer(); _numDeaths++; }
void InitWindowsSystem (osgViewer::Viewer& viewer, const char* const title, int x, int y, int width, int height) { viewer.setUpViewInWindow(x, y, width, height); //Get the traits of the current window osg::ref_ptr< osg::GraphicsContext::Traits > traits = new osg::GraphicsContext::Traits( *viewer.getCamera()->getGraphicsContext()->getTraits()); //Set the title traits->windowName = title; // disable vertical sync traits->vsync = false; //Create a new graphics context with the modified traits osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); gc->realize(); gc->makeCurrent(); // set the vertical black off by default osgViewer::Viewer::Windows windows; viewer.getWindows(windows); for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr != windows.end(); ++itr) { osgViewer::GraphicsWindow* const graphicsWindow = (*itr); graphicsWindow->setSyncToVBlank (false); } //Create the new camera which is a copy of the current camera in the viewer osg::ref_ptr<osg::Camera> cam = new osg::Camera( *viewer.getCamera() ); //Set the cameras graphics context to the gc we made above cam->setGraphicsContext( gc ); //assign the viewer the new camera viewer.setCamera( cam.get() ); // int the camera default perspective matrix SetCameraProjectionMatrix (viewer, 60.0f, dFloat (width) / height, 0.01, 1000.0f); // set the file find callback osg::ref_ptr<DemosFindFileCallback> filecallback = new DemosFindFileCallback; osgDB::Registry::instance()->setFindFileCallback (filecallback.get()); }
void build_world(osg::Group* root, osg::Node* scene, osgViewer::Viewer& viewer) { osg::ref_ptr<EffectPanel> effect_panel = build_gui(root); effect_panel->setScene(scene); effect_panel->rebuild(); viewer.addEventHandler(new EffectPanel::KeyboardHandler(effect_panel.get())); root->addChild(effect_panel->getRoot()); }
LevelMenu::LevelMenu() : _currentLevel(NULL), _currentItemIndex(0) { _menuPat = new osg::PositionAttitudeTransform(); _menuPat->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); _keyboardHandler = new MenuKeyboardHandler(this); viewer.addEventHandler(_keyboardHandler); initializeCamera(); initializeHeader(); initializeBackgroundAnimation(); initializeSelector(); loadLevels(); updateDetails(); viewer.getCamera()->setUpdateCallback(new LevelMenuUpdater(this)); Sound::getInstance()->playInLoop(MENU_MUSIC_FILE); }
void LevelMenu::initializeHeader() { osg::PositionAttitudeTransform *headerPat = new osg::PositionAttitudeTransform(); osg::Geode *headerGeode = new osg::Geode(); osg::Geometry *textureDrawable = new osg::Geometry(); osg::Texture2D *texture; osg::Vec3Array *vertices = new osg::Vec3Array(); { vertices->push_back(osg::Vec3(0, 0, 0)); vertices->push_back(osg::Vec3(436, 0, 0)); vertices->push_back(osg::Vec3(436, 75, 0)); vertices->push_back(osg::Vec3(0, 75, 0)); } textureDrawable->setVertexArray( vertices ); osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0); face->push_back(0); face->push_back(1); face->push_back(2); face->push_back(3); textureDrawable->addPrimitiveSet(face); osg::Vec2Array* texcoords = new osg::Vec2Array(4); { (*texcoords)[0].set(0.0f, 0.0f); (*texcoords)[1].set(1.0f, 0.0f); (*texcoords)[2].set(1.0f, 1.0f); (*texcoords)[3].set(0.0f, 1.0f); textureDrawable->setTexCoordArray(0, texcoords); } texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); osg::StateSet* stateSet = new osg::StateSet(); stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); textureDrawable->setStateSet(stateSet); headerGeode->addDrawable(textureDrawable); headerPat->addChild(headerGeode); _menuPat->addChild(headerPat); headerPat->setPosition(osg::Vec3(100, viewer.getCamera()->getViewport()->height() - 125, -0.01)); osg::Image *image = osgDB::readImageFile(LEVEL_HEADER_TEXTURE); texture->setImage(image); }
int main(int argc, char* argv[]) { ref_ptr<Group> root = new Group; viewer.setUpViewInWindow(0, 0, 640, 480); viewer.realize(); ref_ptr<Camera> cam = viewer.getCamera(); ref_ptr<Geode> geode = new Geode; root->addChild(geode.get()); for (int i=0; i < 10; i++) { osg::Sphere* sphere = new osg::Sphere( Vec3f(i+1,10,0), .1*i); osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere); geode->addDrawable(sphereDrawable); } // osg::Sphere* sphere = new osg::Sphere( Vec3f(10,10,0), .2); // osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere); // sphereDrawable->setColor(osg::Vec4f(1,0,0,1)); // geode->addDrawable(sphereDrawable); ref_ptr<osgGA::TrackballManipulator> manip = new osgGA::TrackballManipulator(); viewer.setCameraManipulator(manip); viewer.setSceneData(root.get()); cam->setViewMatrixAsLookAt(Vec3f(10,0,0), Vec3f(10,1,0), Vec3f(0,0,1)); //manip->setHomePosition(Vec3f(10,0,0), Vec3f(11,1,0), Vec3f(10,0,1)); // cam->setProjectionMatrixAsPerspective(49,640/480., .1, 10); viewer.run(); }
virtual void run() { helper::PerformanceMeasurer PM; PM.tic(); while(!is->done()) { _mutex.lock(); is->get(frame); if(frame.empty()) { loglni("[TrackThread] no valid frame, exit!!!"); OpenCVneedQuit = true; _mutex.unlock(); break; } cvtColor(frame, gray, CV_BGR2GRAY); double rms, ncc; if( needToInit ) { loglni("[TrackThread] INITing..."); Mat tmpH; if( findAprilTag(frame, 0, tmpH, true) ) { #if !USE_INTERNAL_DETECTOR Mat initH = tmpH * iHI; needToInit = !tracker.init(gray, initH, rms, ncc); #else needToInit=!tracker.init(gray,rms,ncc); #endif if(!needToInit) loglni("[TrackThread] ...INITed"); if(!needToInit) tracker.draw3D(frame); } } else { needToInit=!tracker(gray, rms, ncc, opencvDraw?&frame:0); if(!needToInit) tracker.GetCameraPose(camR,camT,false,true); } ++BkgModifyCnt; loglni("[TrackThread] fps="<<1.0/PM.toctic()); _mutex.unlock(); if(OpenCVneedQuit) { break; } ++framecnt; } OpenThreads::Thread::YieldCurrentThread(); loglni("[TrackThread] OpenCV quited..."); if(!videoFromWebcam) { loglni("[TrackThread] OpenCV notify OSG to quit..."); viewer.setDone(true); } }
void Sky::initializeCamera() { _camera = new osg::Camera(); _camera->setProjectionMatrix(osg::Matrix::ortho2D(0, viewer.getCamera()->getViewport()->width(), 0, viewer.getCamera()->getViewport()->height())); _camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); _camera->setViewMatrix(osg::Matrix::identity()); _camera->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); _camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _camera->setRenderOrder(osg::Camera::PRE_RENDER); _camera->addChild(_skyPat); }
void startApplication() { startMenu->hideAll(); osg::ref_ptr<osg::Node> groundRoot = genWorld(filename); root->addChild(groundRoot); osg::ref_ptr<FirstPersonController> controller = new FirstPersonController(&viewer); viewer.setCameraManipulator(controller); // Add main HUD mainHud = new hud(&viewer); root->addChild(mainHud->_camera); // Set user position (aka camera) osg::Vec3d eye( 0.0, -1.0, 0.0 ); osg::Vec3d center( 0.0, 0.0, 0.0 ); osg::Vec3d up( 0.0, 0.0, 90.0 ); viewer.getCameraManipulator()->setHomePosition(eye, center, up); viewer.home(); }
LevelUpdater::LevelUpdater(Level *level) : _level(level), _previousStepTime(viewer.getFrameStamp()->getSimulationTime()) { _blendColor = new osg::BlendColor(osg::Vec4(1, 1, 1, 1)); /* _level->getShadowedScene()->getOrCreateStateSet()->setAttributeAndModes(_blendColor, osg::StateAttribute::ON); _level->getShadowedScene()->getOrCreateStateSet()->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); _level->getShadowedScene()->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); _level->getShadowedScene()->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); */ }
void showNodeNames() { osgViewer::ViewerBase::Scenes viewerScenes; osgViewer::Scene* scene; ShowNodeNamesVisitor snnv( true ); viewer.getScenes(viewerScenes, true); for (osgViewer::ViewerBase::Scenes::iterator it = viewerScenes.begin(); it!=viewerScenes.end(); ++it) { scene = *it; osg::Node* node = scene->getSceneData(); node->accept( snnv ); } }
void singleWindowMultipleCameras(osgViewer::Viewer& viewer) { osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); if (!wsi) { osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; return; } unsigned int width, height; wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = 0; traits->y = 0; traits->width = width; traits->height = height; traits->windowDecoration = true; traits->doubleBuffer = true; traits->sharedContext = 0; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); if (gc.valid()) { osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl; // need to ensure that the window is cleared make sure that the complete window is set the correct colour // rather than just the parts of the window that are under the camera's viewports gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f)); gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } else { osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl; } unsigned int numCameras = 2; double aspectRatioScale = 1.0;///(double)numCameras; for(unsigned int i=0; i<numCameras;++i) { osg::ref_ptr<osg::Camera> camera = new osg::Camera; camera->setGraphicsContext(gc.get()); camera->setViewport(new osg::Viewport((i*width)/numCameras,(i*height)/numCameras, width/numCameras, height/numCameras)); GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; camera->setDrawBuffer(buffer); camera->setReadBuffer(buffer); viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::scale(aspectRatioScale,1.0,1.0)); } }