root/branches/Dirk_CPtr/Tutorials/12ClusterServer.cpp

Revision 619, 4.2 kB (checked in by dirk, 2 years ago)

Added support for local libs for individual Tuts
Added Cluster tuts (thanks to Patrick hartling!)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 // OpenSG Tutorial Example: Cluster Server
2 //
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.
7 //
8 // See the ClusterClient.cpp for an example of how to use them.
9 //
10 // Libs: Cluster
11
12 #include <iostream>
13
14 // GLUT is used for window handling
15 #include <OpenSG/OSGGLUT.h>
16 // General OpenSG configuration, needed everywhere
17 #include <OpenSG/OSGConfig.h>
18 // The Cluster server definition
19 #include <OpenSG/OSGClusterServer.h>
20 // The GLUT-OpenSG connection class
21 #include <OpenSG/OSGGLUTWindow.h>
22 // Render action definition.
23 #include <OpenSG/OSGRenderAction.h>
24
25 OSG_USING_NAMESPACE
26
27 // local glut window
28 GLUTWindowPtr   window;
29 // render action
30 RenderAction   *ract;
31 // pointer the the cluster server instance
32 ClusterServer  *server;
33
34 // forward declaration so we can have the interesting stuff upfront
35 void display();
36 void update();
37 void reshape( int width, int height );
38
39 // Initialize GLUT & OpenSG and start the cluster server
40 int main(int argc,char **argv)
41 {
42     int             winid;
43     char           *name          ="ClusterServer";
44     char           *connectionType="StreamSock";
45     bool            fullscreen     =true;
46     std::string     address        ="";
47     char           *opt;
48
49     // initialize Glut
50     glutInit(&argc, argv);
51     glutInitDisplayMode( GLUT_RGB |
52                          GLUT_DEPTH |
53                          GLUT_DOUBLE);
54
55     // evaluate params
56     for(int a=1 ; a<argc ; ++a)
57     {
58         if(argv[a][0] == '-')
59         {
60             switch(argv[a][1])
61             {
62                 case 'm': connectionType="Multicast";
63                           break;
64                 case 'p': connectionType="SockPipeline";
65                           break;
66                 case 'w': fullscreen=false;
67                           break;
68                 case 'a': address = argv[a][2] ? argv[a]+2 : argv[++a];
69                           if(address == argv[argc])
70                           {
71                               SLOG << "address missing" << endLog;
72                               return 0;
73                           }
74                           std::cout << address << endLog;
75                           break;
76                 default:  std::cout << argv[0]
77                                     << "-m "
78                                     << "-p "
79                                     << "-w "
80                                     << "-a address "
81                                     << endLog;
82                           return 0;
83             }
84         }
85         else
86         {
87             name=argv[a];
88         }
89     }
90     try
91     {
92         // init OpenSG
93         osgInit(argc, argv);
94
95         winid = glutCreateWindow(name);
96         if(fullscreen)
97             glutFullScreen();
98         glutDisplayFunc(display);
99         glutIdleFunc(update);
100         glutReshapeFunc(reshape);
101
102         glEnable( GL_LIGHTING );
103         glEnable( GL_LIGHT0 );
104         glEnable( GL_NORMALIZE );
105         glutSetCursor(GLUT_CURSOR_NONE);
106
107         // create the render action
108         ract=RenderAction::create();
109
110         // setup the OpenSG Glut window
111         window     = GLUTWindow::create();
112         window->setId(winid);
113         window->init();
114
115         // create the cluster server
116         server     = new ClusterServer(window,name,connectionType,address);
117         // start the server
118         server->start();
119
120         // enter glut main loop
121         glutMainLoop();
122     }
123     catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
124     {
125         SLOG << e.what() << endLog;
126         delete server;
127         osgExit();
128     }
129     return 0;
130 }
131
132 /* render loop */
133 void display()
134 {
135     try
136     {
137         // receive scenegraph and do rendering
138         server->render(ract);
139         // clear changelist
140         OSG::Thread::getCurrentChangeList()->clear();
141     }
142     catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
143     {
144         SLOG << e.what() << endLog;
145         // try to restart server
146         server->stop();
147         // start server, wait for client to connect
148         server->start();
149     }
150 }
151
152 void update(void)
153 {
154     glutPostRedisplay();
155 }
156
157 /* window reshape */
158 void reshape( int width, int height )
159 {
160     // set new window size
161         window->resize( width, height );
162 }
Note: See TracBrowser for help on using the browser.