| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
#include <OpenSG/OSGGLUT.h> |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
#include <OpenSG/OSGConfig.h> |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
#include <OpenSG/OSGSimpleGeometry.h> |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
#include <OpenSG/OSGGLUTWindow.h> |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
#include <OpenSG/OSGSimpleSceneManager.h> |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
#include <OpenSG/OSGSortLastWindow.h> |
|---|
| 46 |
#include <OpenSG/OSGPipelineComposer.h> |
|---|
| 47 |
#include <OpenSG/OSGBinarySwapComposer.h> |
|---|
| 48 |
#include <OpenSG/OSGParallelComposer.h> |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
#include <OpenSG/OSGSceneFileHandler.h> |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
OSG_USING_NAMESPACE |
|---|
| 55 |
|
|---|
| 56 |
using namespace std; |
|---|
| 57 |
|
|---|
| 58 |
SimpleSceneManager *mgr; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
int setupGLUT( int *argc, char *argv[] ); |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
int main(int argc, char **argv) |
|---|
| 65 |
{ |
|---|
| 66 |
char *opt; |
|---|
| 67 |
NodeGlobalRefPtr scene; |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
osgInit(argc,argv); |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
int winid = setupGLUT(&argc, argv); |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
SortLastWindowGlobalRefPtr mwin = SortLastWindow::create(); |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
for(int a=1 ; a<argc ; ++a) |
|---|
| 80 |
{ |
|---|
| 81 |
if(argv[a][0] == '-') |
|---|
| 82 |
{ |
|---|
| 83 |
switch(argv[a][1]) |
|---|
| 84 |
{ |
|---|
| 85 |
case 'm': mwin->setConnectionType("Multicast"); |
|---|
| 86 |
cout << "Connection type set to Multicast" << endl; |
|---|
| 87 |
break; |
|---|
| 88 |
case 'p': mwin->setConnectionType("SockPipeline"); |
|---|
| 89 |
cout << "Connection type set to SockPipeline" << endl; |
|---|
| 90 |
break; |
|---|
| 91 |
case 'i': opt = argv[a][2] ? argv[a]+2 : argv[++a]; |
|---|
| 92 |
if(opt != argv[argc]) |
|---|
| 93 |
mwin->setConnectionInterface(opt); |
|---|
| 94 |
break; |
|---|
| 95 |
case 'a': opt = argv[a][2] ? argv[a]+2 : argv[++a]; |
|---|
| 96 |
if(opt != argv[argc]) |
|---|
| 97 |
mwin->setServiceAddress(opt); |
|---|
| 98 |
break; |
|---|
| 99 |
case 'f': opt = argv[a][2] ? argv[a]+2 : argv[++a]; |
|---|
| 100 |
if(opt != argv[argc]) |
|---|
| 101 |
scene = SceneFileHandler::the()->read( |
|---|
| 102 |
opt,0); |
|---|
| 103 |
break; |
|---|
| 104 |
case 'L': |
|---|
| 105 |
mwin->setComposer(ImageComposerRefPtr(PipelineComposer::create())); |
|---|
| 106 |
break; |
|---|
| 107 |
case 'B': |
|---|
| 108 |
mwin->setComposer(ImageComposerRefPtr(BinarySwapComposer::create())); |
|---|
| 109 |
break; |
|---|
| 110 |
case 'P': |
|---|
| 111 |
mwin->setComposer(ImageComposerRefPtr(ParallelComposer::create())); |
|---|
| 112 |
break; |
|---|
| 113 |
default: std::cout << argv[0] |
|---|
| 114 |
<< " -m" |
|---|
| 115 |
<< " -p" |
|---|
| 116 |
<< " -i interface" |
|---|
| 117 |
<< " -f file" |
|---|
| 118 |
<< endLog; |
|---|
| 119 |
return 0; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
else |
|---|
| 123 |
{ |
|---|
| 124 |
printf("%s\n",argv[a]); |
|---|
| 125 |
mwin->editServers().push_back(argv[a]); |
|---|
| 126 |
} |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
if(mwin->getComposer() == NullFC) |
|---|
| 132 |
{ |
|---|
| 133 |
mwin->setComposer(ImageComposerRefPtr(PipelineComposer::create())); |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
fprintf(stderr, "Using : %s\n", mwin->getComposer()->getType().getCName()); |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
mwin->setSize(300,300); |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
GLUTWindowGlobalRefPtr clientWindow = GLUTWindow::create(); |
|---|
| 144 |
|
|---|
| 145 |
glutReshapeWindow(300,300); |
|---|
| 146 |
clientWindow->setGlutId(winid); |
|---|
| 147 |
clientWindow->init(); |
|---|
| 148 |
|
|---|
| 149 |
clientWindow->resize(300,300); |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
mwin->setClientWindow(clientWindow); |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
if(scene == NullFC) |
|---|
| 158 |
{ |
|---|
| 159 |
scene = makeNodeFor(GroupRefPtr(Group::create())); |
|---|
| 160 |
|
|---|
| 161 |
scene->addChild(NodeRefPtr(makeTorus(.5, 2, 16, 16))); |
|---|
| 162 |
scene->addChild(NodeRefPtr(makeCylinder(1, .3, 8, true, true, true))); |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
mgr = new SimpleSceneManager; |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
mgr->setWindow(mwin ); |
|---|
| 170 |
mgr->setRoot (scene); |
|---|
| 171 |
mgr->setUseTraversalAction(false); |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
mgr->showAll(); |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
mwin->init(); |
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
glutMainLoop(); |
|---|
| 181 |
|
|---|
| 182 |
return 0; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
void display(void) |
|---|
| 191 |
{ |
|---|
| 192 |
|
|---|
| 193 |
mgr->redraw(); |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
OSG::Thread::getCurrentChangeList()->clear(); |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
void reshape(int w, int h) |
|---|
| 202 |
{ |
|---|
| 203 |
glutPostRedisplay(); |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
void mouse(int button, int state, int x, int y) |
|---|
| 208 |
{ |
|---|
| 209 |
if (state) |
|---|
| 210 |
mgr->mouseButtonRelease(button, x, y); |
|---|
| 211 |
else |
|---|
| 212 |
mgr->mouseButtonPress(button, x, y); |
|---|
| 213 |
glutPostRedisplay(); |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
void motion(int x, int y) |
|---|
| 218 |
{ |
|---|
| 219 |
mgr->mouseMove(x, y); |
|---|
| 220 |
glutPostRedisplay(); |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
void keyboard(unsigned char k, int x, int y) |
|---|
| 225 |
{ |
|---|
| 226 |
switch(k) |
|---|
| 227 |
{ |
|---|
| 228 |
case 27: |
|---|
| 229 |
{ |
|---|
| 230 |
delete mgr; |
|---|
| 231 |
|
|---|
| 232 |
OSG::osgExit(); |
|---|
| 233 |
exit(0); |
|---|
| 234 |
} |
|---|
| 235 |
break; |
|---|
| 236 |
} |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
int setupGLUT(int *argc, char *argv[]) |
|---|
| 241 |
{ |
|---|
| 242 |
glutInit(argc, argv); |
|---|
| 243 |
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); |
|---|
| 244 |
|
|---|
| 245 |
int winid = glutCreateWindow("OpenSG"); |
|---|
| 246 |
|
|---|
| 247 |
glutReshapeFunc(reshape); |
|---|
| 248 |
glutDisplayFunc(display); |
|---|
| 249 |
glutMouseFunc(mouse); |
|---|
| 250 |
glutMotionFunc(motion); |
|---|
| 251 |
glutKeyboardFunc(keyboard); |
|---|
| 252 |
|
|---|
| 253 |
return winid; |
|---|
| 254 |
} |
|---|