5 #include "OSGClusterServer.h"
6 #include "OSGGLUTWindow.h"
7 #include "OSGRenderAction.h"
8 #include "OSGSceneFileHandler.h"
9 #include "OSGViewport.h"
10 #include "OSGFrameHandler.h"
13 OSG::ClusterServer
*server
;
14 OSG::GLUTWindowRecPtr window
;
15 OSG::RenderActionRefPtr ract
;
17 bool exitOnError
=false;
18 OSG::UInt32 servicePort
=8437;
19 std::string serviceGroup
="224.245.211.234";
20 int winWidth
=0,winHeight
=0;
43 /*! ignore rendering in zero sized windows */
44 if(!winWidth
|| !winHeight
)
48 OSG::FrameHandler::the()->frame();
51 // clear changelist from prototypes
52 OSG::Thread::getCurrentChangeList()->clear();
54 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
58 SLOG
<< e
.what() << std::endl
;
59 printf("Exit on error %s",e
.what());
74 // try to restart server
88 void reshape( int width
, int height
)
92 std::cout
<< "reshape " << width
<< " " << height
<< std::endl
;
93 window
->resize( width
, height
);
96 void key(unsigned char key
, int /*x*/, int /*y*/)
101 window
->getPort(0)->getRoot()->dump();
104 OSG::SceneFileHandler::the()->write(
105 window
->getPort(0)->getRoot(),"server.osg");
112 int main(int argc
,char **argv
)
114 const char *name
="ClusterServer";
115 const char *connectionType
="StreamSock";
116 // const char *connectionType="Multicast";
117 bool fullscreen
=true;
118 std::string address
="";
119 int width
=-1,height
=300,x
=0,y
=0;
123 for(int i
= 1 ; i
< argc
; ++i
)
125 if(argv
[i
][0] == '-')
130 connectionType
="Multicast";
142 address
=&(argv
[i
][2]);
145 if(argv
[i
][2] != '\0')
149 if(sscanf(str
,"%d,%d,%d,%d",
150 &width
,&height
,&x
,&y
)!=4)
152 SWARNING
<< "Wrong args in -g. Use -gw,h,x,y"
159 if(argv
[i
][2] != '\0')
160 servicePort
=atoi(argv
[i
]+2);
162 servicePort
=atoi(argv
[++i
]);
165 if(argv
[i
][2] != '\0')
166 serviceGroup
=argv
[i
]+2;
168 serviceGroup
=argv
[++i
];
181 std::cout
<< "-m use multicast" << std::endl
;
182 std::cout
<< "-s enable stereo" << std::endl
;
183 std::cout
<< "-w no fullscreen" << std::endl
;
184 std::cout
<< "-e exit after closed connection"
186 std::cout
<< "-g geometry" << std::endl
;
187 std::cout
<< "-a Address Server network address"
189 std::cout
<< "-m Address wait for requests on "
190 << "multicast group" << std::endl
;
191 std::cout
<< "-p port wait for requests on port"
204 OSG::osgInit (argc
, argv
);
205 OSG::ClusterServer::init(argc
, argv
);
207 glutInit(&argc
, argv
);
210 glutInitDisplayMode( GLUT_STEREO
|
215 glutInitDisplayMode( GLUT_RGB
|
218 glutInitWindowPosition(x
,y
);
220 glutInitWindowSize(width
,height
);
221 winid
= glutCreateWindow("OpenSG Cluster Client");
226 glutReshapeWindow(300,300);
229 glutReshapeWindow(width
,height
);
230 glutPositionWindow(x
, y
);
233 glutDisplayFunc(display
);
234 glutIdleFunc(display
);
235 glutKeyboardFunc(key
);
236 glutReshapeFunc(reshape
);
237 glutSetWindowTitle(name
);
239 glutSetCursor(GLUT_CURSOR_NONE
);
240 glEnable( GL_LIGHTING
);
241 glEnable( GL_LIGHT0
);
242 glEnable( GL_DEPTH_TEST
);
243 glEnable( GL_NORMALIZE
);
244 ract
= OSG::RenderAction::create();
245 // ract->setFrustumCulling(false);
246 window
= OSG::GLUTWindow::create();
247 window
->setGlutId(winid
);
249 server
= new OSG::ClusterServer(window
,
259 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
261 SLOG
<< e
.what() << std::endl
;