5 #include "OSGClusterServer.h"
6 #include "OSGGLUTWindow.h"
7 #include "OSGRenderAction.h"
8 #include "OSGSceneFileHandler.h"
9 #include "OSGViewport.h"
12 OSG::ClusterServer
*server
;
13 OSG::GLUTWindowRecPtr window
;
14 OSG::RenderActionRefPtr ract
;
16 bool exitOnError
=false;
17 OSG::UInt32 servicePort
=8437;
18 std::string serviceGroup
="224.245.211.234";
19 int winWidth
=0,winHeight
=0;
42 /*! ignore rendering in zero sized windows */
43 if(!winWidth
|| !winHeight
)
49 // clear changelist from prototypes
50 OSG::Thread::getCurrentChangeList()->clear();
52 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
56 SLOG
<< e
.what() << std::endl
;
57 printf("Exit on error %s",e
.what());
72 // try to restart server
86 void reshape( int width
, int height
)
90 std::cout
<< "reshape " << width
<< " " << height
<< std::endl
;
91 window
->resize( width
, height
);
94 void key(unsigned char key
, int /*x*/, int /*y*/)
99 window
->getPort(0)->getRoot()->dump();
102 OSG::SceneFileHandler::the()->write(
103 window
->getPort(0)->getRoot(),"server.osg");
110 int main(int argc
,char **argv
)
112 const char *name
="ClusterServer";
113 const char *connectionType
="StreamSock";
114 // const char *connectionType="Multicast";
115 bool fullscreen
=true;
116 std::string address
="";
117 int width
=-1,height
=300,x
=0,y
=0;
121 for(int i
= 1 ; i
< argc
; ++i
)
123 if(argv
[i
][0] == '-')
128 connectionType
="Multicast";
140 address
=&(argv
[i
][2]);
143 if(argv
[i
][2] != '\0')
147 if(sscanf(str
,"%d,%d,%d,%d",
148 &width
,&height
,&x
,&y
)!=4)
150 SWARNING
<< "Wrong args in -g. Use -gw,h,x,y"
157 if(argv
[i
][2] != '\0')
158 servicePort
=atoi(argv
[i
]+2);
160 servicePort
=atoi(argv
[++i
]);
163 if(argv
[i
][2] != '\0')
164 serviceGroup
=argv
[i
]+2;
166 serviceGroup
=argv
[++i
];
179 std::cout
<< "-m use multicast" << std::endl
;
180 std::cout
<< "-s enable stereo" << std::endl
;
181 std::cout
<< "-w no fullscreen" << std::endl
;
182 std::cout
<< "-e exit after closed connection"
184 std::cout
<< "-g geometry" << std::endl
;
185 std::cout
<< "-a Address Server network address"
187 std::cout
<< "-m Address wait for requests on "
188 << "multicast group" << std::endl
;
189 std::cout
<< "-p port wait for requests on port"
202 OSG::osgInit(argc
, argv
);
203 glutInit(&argc
, argv
);
205 glutInitDisplayMode( GLUT_STEREO
|
210 glutInitDisplayMode( GLUT_RGB
|
213 glutInitWindowPosition(x
,y
);
215 glutInitWindowSize(width
,height
);
216 winid
= glutCreateWindow("OpenSG Cluster Client");
221 glutReshapeWindow(300,300);
224 glutReshapeWindow(width
,height
);
225 glutPositionWindow(x
, y
);
228 glutDisplayFunc(display
);
229 glutIdleFunc(display
);
230 glutKeyboardFunc(key
);
231 glutReshapeFunc(reshape
);
232 glutSetWindowTitle(name
);
234 glutSetCursor(GLUT_CURSOR_NONE
);
235 glEnable( GL_LIGHTING
);
236 glEnable( GL_LIGHT0
);
237 glEnable( GL_DEPTH_TEST
);
238 glEnable( GL_NORMALIZE
);
239 ract
=OSG::RenderAction::create();
240 // ract->setFrustumCulling(false);
241 window
= OSG::GLUTWindow::create();
242 window
->setGlutId(winid
);
244 server
= new OSG::ClusterServer(window
,
254 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
256 SLOG
<< e
.what() << std::endl
;