Hi Brian,

On Tue, 2006-04-11 at 10:31 -0700, Brian Sowers wrote:
> Hi,
> We're trying to write a clustering application which
> displays a scene on multiple viewports.  Each viewport
> may potentially show the scene at a different angle or
> with different properties (ie: multiple resolutions). 
> Our thoughts are to use multiple scene graphs, or
> something to that extent.  Does anyone have any good
> suggestions on how to approach the problem?
> Barring that, does anyone have any good example
> clustering applications that use OpenSG that we could
> look at for reference?

The core philosophy of OpenSG clustering is that it should be invisible.
It's possible to get down deeper, but as far as possible you shouldn't
have to worry about clustering at all.

Therefore you should be able to prototype your application on a desktop
with a window that shows the different viewports you want to show on the
cluster and then for cluster mode switch to a large cluster window and
just have it work. That's why very few people write their own cluster
servers, they just use the testClusterServer or the one from the
Tutorials. Similarly for the cluster client application. Whatever you
can render in a single desktop window, put it into a cluster window and
be done.

Concerning the multiple viewports and multiple graphs: if your scenes
are really totally separate multiple graphs are a good solution.
However, if some objects are the same in both graphs it is better to
just put all scenes in one graph and use traversal masks
(Node::setTravMask, Viewport::setTravMask) to decide which objects show
up in which viewport.

There are no well-documented examples for multiple viewports, because
the SSM doesn't really work well with them. I attached one that show how
to do it in general, I hope that helps get you going.

Yours

        Dirk



// OpenSG Tutorial Example: Hello World
//
// Minimalistic OpenSG program
// 
// This is the shortest useful OpenSG program 
// (if you remove all the comments ;)
//
// It shows how to use OpenSG together with GLUT to create a little
// interactive scene viewer.
//

// GLUT is used for window handling
#include <OpenSG/OSGGLUT.h>

// General OpenSG configuration, needed everywhere
#include <OpenSG/OSGConfig.h>

// Methods to create simple geometry: boxes, spheres, tori etc.
#include <OpenSG/OSGSimpleGeometry.h>

// The GLUT-OpenSG connection class
#include <OpenSG/OSGGLUTWindow.h>

// A little helper to simplify scene management and interaction
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGBaseFunctions.h>
#include <OpenSG/OSGGradientBackground.h>

// Activate the OpenSG namespace
// This is not strictly necessary, you can also prefix all OpenSG symbols
// with OSG::, but that would be a bit tedious for this example
OSG_USING_NAMESPACE

// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;

// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );



ViewportPtr vp2; // Need that in key()

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();
    
    // create the scene
    NodePtr torus = makeTorus(.5, 2, 16, 16);

    beginEditCP(torus);
    torus->setTravMask(0x1);
    endEditCP(torus);
    

    // create the scene for the second viewport
    NodePtr cone = makeCone(2, 2, 8, true, true);

    beginEditCP(cone);
    cone->setTravMask(0x2);
    endEditCP(cone);
  
  
    NodePtr scene = makeNodeFor(Group::create());
    
    beginEditCP(scene);
    scene->addChild(torus);
    scene->addChild(cone);
    endEditCP(scene);
    
    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);

//I  use the viewport created by the SSM here and modify it.

   ViewportPtr vp1 = gwin->getPort(0);
    beginEditCP(vp1);
        vp1->setLeft(0);
        vp1->setRight(0.5);
        vp1->setTop(1);
        vp1->setBottom(0);
        vp1->setTravMask(0x1);
    endEditCP(vp1);

//Create a second viewport with a different background and scene

    GradientBackgroundPtr grad = GradientBackground::create();
    beginEditCP(grad);
    grad->addLine(Color3f(0.7, 0.7, 0.8), 0);
    grad->addLine(Color3f(0.0, 0.1, 0.3), 1);  
    endEditCP(grad);
    
    
    vp2 = Viewport::create();
    beginEditCP(vp2);
        vp2->setLeft(0.5);
        vp2->setRight(1);
        vp2->setTop(1);
        vp2->setBottom(0);
        vp2->setBackground(grad);
        vp2->setCamera(vp1->getCamera());   // use the same Camera
        vp2->setRoot(vp1->getRoot());       // Use the same scene
        vp2->setTravMask(0x2);              // ...but a different travmask
    endEditCP(vp2);

    //Adding the new viewport

    beginEditCP(gwin);
        gwin->addPort(vp2);
    beginEditCP(gwin);


    // show the whole scene
    mgr->showAll();
    
    // GLUT main loop
    glutMainLoop();

    return 0;
}

//
// GLUT callback functions
//

// redraw the window
void display(void)
{
    mgr->redraw();
}

// react to size changes
void reshape(int w, int h)
{
    mgr->resize(w, h);
    glutPostRedisplay();
}

// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
    if (state)
        mgr->mouseButtonRelease(button, x, y);
    else
        mgr->mouseButtonPress(button, x, y);
        
    glutPostRedisplay();
}

// react to mouse motions with pressed buttons
void motion(int x, int y)
{
    mgr->mouseMove(x, y);
    glutPostRedisplay();
}

// react to keys
void keyboard(unsigned char k, int x, int y)
{
    switch(k)
    {
        case ' ':
        {
        beginEditCP(vp2);
        vp2->setTravMask(vp2->getTravMask() ^ 0x3);
        endEditCP(vp2);
        }
        break;
        
        case 27:        
        {
            OSG::osgExit();
            exit(0);
        }
        break;
    }
    
    glutPostRedisplay();
}

// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    
    int winid = glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);

    return winid;
}

Reply via email to