1 // OpenSG Tutorial Example: Minimalistic OpenSG cluster client program
4 // ./clusterserver -geometry 300x300+200+100 -m -w test1 &
5 // ./clusterserver -geometry 300x300+500+100 -m -w test2 &
6 // ./clusterclient -m -fData/tie.wrl test1 test2
8 // If you have trouble with multicasting, you can alternatively try
9 // ./clusterserver -geometry 300x300+200+100 -w 127.0.0.1:30000 &
10 // ./clusterserver -geometry 300x300+500+100 -w 127.0.0.1:30001 &
11 // ./clusterclient -m -fData/tie.wrl 127.0.0.1:30000 127.0.0.1:30001
13 // The client will open an empty window that you can use to navigate. The
14 // display is shown in the server windows.
16 // This will run all three on the same machine, but you can also start the
17 // servers anywhere else, as long as you can reach them via multicast.
19 // Note: This will run two VERY active OpenGL programs on one screen. Not all
20 // OpenGL drivers are happy with that, so if it crashes your X, it's not our
25 #ifdef OSG_BUILD_ACTIVE
26 // GLUT is used for window handling
29 // General OpenSG configuration, needed everywhere
30 #include <OSGConfig.h>
32 // Methods to create simple geometry: boxes, spheres, tori etc.
33 #include <OSGSimpleGeometry.h>
35 // The GLUT-OpenSG connection class
36 #include <OSGGLUTWindow.h>
38 // A little helper to simplify scene management and interaction
39 #include <OSGSimpleSceneManager.h>
41 // A little helper to simplify scene management and interaction
42 #include <OSGMultiDisplayWindow.h>
44 // Scene file handler for loading geometry files
45 #include <OSGSceneFileHandler.h>
47 // GLUT is used for window handling
48 #include <OpenSG/OSGGLUT.h>
50 // General OpenSG configuration, needed everywhere
51 #include <OpenSG/OSGConfig.h>
53 // Methods to create simple geometry: boxes, spheres, tori etc.
54 #include <OpenSG/OSGSimpleGeometry.h>
56 // The GLUT-OpenSG connection class
57 #include <OpenSG/OSGGLUTWindow.h>
59 // A little helper to simplify scene management and interaction
60 #include <OpenSG/OSGSimpleSceneManager.h>
62 // A little helper to simplify scene management and interaction
63 #include <OpenSG/OSGMultiDisplayWindow.h>
65 // Scene file handler for loading geometry files
66 #include <OpenSG/OSGSceneFileHandler.h>
69 // The SimpleSceneManager to manage simple applications
70 OSG::SimpleSceneManagerRefPtr mgr
;
72 // forward declaration so we can have the interesting stuff upfront
73 int setupGLUT( int *argc
, char *argv
[] );
75 // Initialize GLUT & OpenSG and set up the scene
76 int main(int argc
, char **argv
)
81 OSG::osgInit(argc
,argv
);
84 /*int winid =*/ setupGLUT(&argc
, argv
);
86 // open a new scope, because the pointers below should go out of scope
87 // before entering glutMainLoop.
88 // Otherwise OpenSG will complain about objects being alive after shutdown.
90 // the connection between this client and the servers
91 OSG::MultiDisplayWindowRefPtr mwin
= OSG::MultiDisplayWindow::create();
92 OSG::NodeRefPtr scene
;
95 for(int a
=1 ; a
<argc
; ++a
)
101 case 'm': mwin
->setConnectionType("Multicast");
102 std::cout
<< "Connection type set to Multicast"
105 case 'p': mwin
->setConnectionType("SockPipeline");
106 std::cout
<< "Connection type set to SockPipeline"
109 case 'i': opt
= argv
[a
][2] ? argv
[a
]+2 : argv
[++a
];
110 if(opt
!= argv
[argc
])
111 mwin
->setConnectionInterface(opt
);
113 case 'a': opt
= argv
[a
][2] ? argv
[a
]+2 : argv
[++a
];
114 if(opt
!= argv
[argc
])
115 mwin
->setServiceAddress(opt
);
117 case 'f': opt
= argv
[a
][2] ? argv
[a
]+2 : argv
[++a
];
118 if(opt
!= argv
[argc
])
119 scene
= OSG::SceneFileHandler::the()->read(opt
,
122 case 'x': opt
= argv
[a
][2] ? argv
[a
]+2 : argv
[++a
];
123 if(opt
!= argv
[argc
])
124 mwin
->setHServers(atoi(opt
));
126 case 'y': opt
= argv
[a
][2] ? argv
[a
]+2 : argv
[++a
];
127 if(opt
!= argv
[argc
])
128 mwin
->setVServers(atoi(opt
));
130 default: std::cout
<< argv
[0]
135 << " -x horizontal server cnt"
136 << " -y vertical server cnt"
143 printf("%s\n",argv
[a
]);
144 mwin
->editMFServers()->push_back(argv
[a
]);
148 // dummy size for navigator
149 mwin
->setSize(300,300);
151 // create default scene
153 scene
= OSG::makeTorus(.5, 2, 16, 16);
155 OSG::commitChanges();
157 // create the SimpleSceneManager helper
158 mgr
= OSG::SimpleSceneManager::create();
160 // tell the manager what to manage
161 mgr
->setWindow(mwin
);
162 mgr
->setRoot (scene
);
164 // show the whole scene
178 // GLUT callback functions
184 // redraw the cluster window
186 // clear change list. If you don't clear the changelist,
187 // then the same changes will be transmitted a second time
188 // in the next frame.
189 OSG::Thread::getCurrentChangeList()->clear();
190 // clear local navigation window
191 glClear(GL_COLOR_BUFFER_BIT
);
195 // react to size changes
196 void reshape(int w
, int h
)
201 // react to mouse button presses
202 void mouse(int button
, int state
, int x
, int y
)
205 mgr
->mouseButtonRelease(button
, x
, y
);
207 mgr
->mouseButtonPress(button
, x
, y
);
211 // react to mouse motions with pressed buttons
212 void motion(int x
, int y
)
214 mgr
->mouseMove(x
, y
);
219 void keyboard(unsigned char k
, int x
, int y
)
225 // clean up global variables
235 // setup the GLUT library which handles the windows for us
236 int setupGLUT(int *argc
, char *argv
[])
238 glutInit(argc
, argv
);
239 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
241 int winid
= glutCreateWindow("OpenSG");
243 glutReshapeFunc(reshape
);
244 glutDisplayFunc(display
);
245 glutMouseFunc(mouse
);
246 glutMotionFunc(motion
);
247 glutKeyboardFunc(keyboard
);