1 // OpenSG Tutorial Example: Cluster Server
3 // This is a full functional OpenSG cluster server. In OpenSG
4 // the terms server and client are used similar to X11. The
5 // application is the client. Instances that are used for
6 // rendering are called server.
8 // See the clusterclient.cpp for an example of how to use them.
14 #ifdef OSG_BUILD_ACTIVE
15 // GLUT is used for window handling
17 // General OpenSG configuration, needed everywhere
18 #include <OSGConfig.h>
19 // The Cluster server definition
20 #include <OSGClusterServer.h>
21 // The GLUT-OpenSG connection class
22 #include <OSGGLUTWindow.h>
23 // Render action definition.
24 #include <OSGRenderAction.h>
26 // GLUT is used for window handling
27 #include <OpenSG/OSGGLUT.h>
28 // General OpenSG configuration, needed everywhere
29 #include <OpenSG/OSGConfig.h>
30 // The Cluster server defini2tion
31 #include <OpenSG/OSGClusterServer.h>
32 // The GLUT-OpenSG connection class
33 #include <OpenSG/OSGGLUTWindow.h>
34 // Render action definition.
35 #include <OpenSG/OSGRenderAction.h>
39 OSG::GLUTWindowRefPtr window
;
41 OSG::RenderActionRefPtr ract
;
42 // pointer the the cluster server instance
43 OSG::ClusterServer
*server
;
45 // forward declaration so we can have the interesting stuff upfront
48 void reshape(int width
, int height
);
50 // Initialize GLUT & OpenSG and start the cluster server
51 int main(int argc
, char **argv
)
54 const char *name
= "ClusterServer";
55 const char *connectionType
= "StreamSock";
56 bool fullscreen
= true;
57 std::string address
= "";
60 glutInit(&argc
, argv
);
61 glutInitDisplayMode( GLUT_RGB
|
66 for(int a
=1 ; a
<argc
; ++a
)
72 case 'm': connectionType
="Multicast";
74 case 'p': connectionType
="SockPipeline";
76 case 'w': fullscreen
=false;
78 case 'a': address
= argv
[a
][2] ? argv
[a
]+2 : argv
[++a
];
81 SLOG
<< "address missing" << OSG::endLog
;
84 std::cout
<< address
<< OSG::endLog
;
86 default: std::cout
<< argv
[0]
103 OSG::osgInit(argc
, argv
);
105 winid
= glutCreateWindow(name
);
108 glutDisplayFunc(display
);
109 glutIdleFunc(update
);
110 glutReshapeFunc(reshape
);
112 glEnable( GL_LIGHTING
);
113 glEnable( GL_LIGHT0
);
114 glEnable( GL_NORMALIZE
);
115 glutSetCursor(GLUT_CURSOR_NONE
);
117 // create the render action
118 ract
= OSG::RenderAction::create();
120 // setup the OpenSG Glut window
121 window
= OSG::GLUTWindow::create();
122 window
->setGlutId(winid
);
125 // create the cluster server
126 server
= new OSG::ClusterServer(window
,name
,connectionType
,address
);
130 // enter glut main loop
133 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
135 SLOG
<< e
.what() << OSG::endLog
;
137 // clean up global variables
153 // receive scenegraph and do rendering
154 server
->render(ract
);
156 OSG::Thread::getCurrentChangeList()->clear();
158 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
160 SLOG
<< e
.what() << OSG::endLog
;
162 window
->clearPorts();
164 // try to restart server
166 // start server, wait for client to connect
177 void reshape( int width
, int height
)
179 // set new window size
180 window
->resize( width
, height
);