Exemplo n.º 1
0
static void connectCluster(void)
{
    if(_cluster_win != NULL)
        return;

    OSG::Viewport *clientvp = _client_win->getPort(0);
    
    // create the viewports for the cluster just a simple one ...
    OSG::ViewportUnrecPtr vp = OSG::Viewport::create();

    vp->setCamera    (_mgr->getCamera());
    vp->setBackground(clientvp->getBackground());
    vp->setRoot      (clientvp->getRoot());
    vp->setSize      (0,0, 1,1);

    // the connection between this client and the servers
    _cluster_win = OSG::MultiDisplayWindow::create();

    // all changes must be enclosed in beginEditCP and endEditCP
    // otherwise the changes will not be transfered over the network.

    for(OSG::UInt32 i=0;i<_pipenames.size();++i)
        _cluster_win->editMFServers()->push_back(_pipenames[i]);
    // dummy size for navigator
    _cluster_win->setSize(300,300);
    _cluster_win->addPort(vp);

    OSG::Thread::getCurrentChangeList()->commitChangesAndClear();
    OSG::Thread::getCurrentChangeList()->fillFromCurrentState();
    OSG::Thread::getCurrentChangeList()->dump();
    // create from the current state a changelist.

    // initialize window
    _cluster_win->init();

    // apply changelist to the servers
    _cluster_win->render((OSG::RenderAction *) _mgr->getRenderAction());

    // clear changelist
    OSG::Thread::getCurrentChangeList()->clear();

    glutPostRedisplay();
}
int main(int argc, char **argv)
{
    OSG::osgInit(argc,argv);

    {
        int winid = setupGLUT(&argc, argv);
        
        //this time we'll have not a GLUTWindow here, but this one
        OSG::MultiDisplayWindowRecPtr multiWindow = 
            OSG::MultiDisplayWindow::create();
        
        //set some necessary values
        // we connect via multicast
        multiWindow->setConnectionType("Multicast");
        //multiWindow->setServiceAddress("192.168.2.142");
        // we want to rendering servers... 
        multiWindow->editMFServers()->push_back("Server1");
        multiWindow->editMFServers()->push_back("Server2");	
        
        //any scene here
        scene = OSG::makeTorus(.5, 2, 16, 16);
        
        // and the ssm as always
        mgr = new OSG::SimpleSceneManager;
        
        mgr->setWindow(multiWindow);
        mgr->setRoot  (scene);
        mgr->showAll();
        
        multiWindow->init();
        
        OSG::commitChanges();
    }
    
    glutMainLoop();
    
    return 0;
}