fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / Rhino3DLoader / testRhino3DRender.cpp
blobcd0c76c8a38952cc4805fa94597b548f50fbf05c
2 // This is not actually a special Rhino3D test program, as the Rhino3D loader
3 // integrated itself into the SceneFileHandler, but I needed an example program
4 // here.
6 // It does show however, how to use the extra options that the Rhino3D loader
7 // supports.
9 #include <OSGGLUT.h>
10 #include <OSGConfig.h>
11 #include <OSGSimpleGeometry.h>
12 #include <OSGPassiveWindow.h>
13 #include <OSGSimpleSceneManager.h>
14 #include <OSGSceneFileHandler.h>
16 #include <OSGDrawable.h>
17 #include <OSGSimpleStatisticsForeground.h>
18 #include <OSGStatElemTypes.h>
19 #include <OSGStatCollector.h>
20 #include <OSGGradientBackground.h>
21 #include <OSGRhinoSceneFileType.h>
23 OSG_USING_NAMESPACE
25 SimpleSceneManagerRefPtr mgr;
27 // redraw the window
28 void display(void)
30 mgr->redraw();
32 // all done, swap
33 glutSwapBuffers();
36 // react to size changes
37 void reshape(int w, int h)
39 mgr->resize(w,h);
40 glutPostRedisplay();
43 // react to mouse button presses
44 void mouse(int button, int state, int x, int y)
46 if (state)
47 mgr->mouseButtonRelease(button, x, y);
48 else
49 mgr->mouseButtonPress(button, x, y);
51 glutPostRedisplay();
54 // react to mouse motions with pressed buttons
55 void motion(int x, int y)
57 mgr->mouseMove(x, y);
58 glutPostRedisplay();
61 // react to keys
62 void keyboard(unsigned char k, int, int)
64 switch(k)
66 case 27:
68 mgr = NULL;
70 osgExit();
71 exit(0);
74 case 'v':
76 mgr->getRenderAction()->setVolumeDrawing(
77 !mgr->getRenderAction()->getVolumeDrawing());
78 std::cerr << "Volume Drawing: "
79 << (mgr->getRenderAction()->getVolumeDrawing()?"on":"off")
80 << std::endl;
82 break;
84 case 'w':
86 std::cerr << "Writing osb...";
87 SceneFileHandler::the()->write(mgr->getRoot(), "test.osb");
88 std::cerr << "done." << std::endl;
91 break;
93 case 'W':
95 std::cerr << "Writing osg...";
96 SceneFileHandler::the()->write(mgr->getRoot(), "test.osg");
97 std::cerr << "done." << std::endl;
100 break;
105 int doMain(int argc, char **argv)
107 osgInit(argc,argv);
109 // GLUT init
110 glutInit(&argc, argv);
112 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
114 glutInitWindowSize(500, 500);
115 glutCreateWindow("OpenSG");
117 glutReshapeFunc(reshape);
118 glutDisplayFunc(display);
119 glutIdleFunc(display);
120 glutMouseFunc(mouse);
121 glutMotionFunc(motion);
122 glutKeyboardFunc(keyboard);
124 PassiveWindowUnrecPtr pwin=PassiveWindow::create();
125 pwin->init();
127 // we do want a tessellation
128 SceneFileHandler::the()->setOption("3dm", "doTessellation", "1");
129 // import rendermeshes too
130 SceneFileHandler::the()->setOption("3dm", "importRenderMeshes", "0");
131 // let's set the number of interpolation steps curves are approximated with
132 SceneFileHandler::the()->setOption("3dm", "curveInterpolationSteps", "101");
134 if(argc > 1 && !strncmp(argv[1], "-e=", 3))
136 // the user supplied a tessellation error, let's that too
137 float tessError = TypeTraits<Real32>::getFromCString(argv[1] + 3);
138 if(tessError > 0)
140 SceneFileHandler::the()->setOption("3dm",
141 "tesselationError",
142 argv[1] + 3);
145 argc--;
146 argv++;
149 // create the scene
150 NodeUnrecPtr scene;
152 if(argc > 1)
154 scene = Node::create();
155 GroupUnrecPtr g = Group::create();
157 scene->setCore(g);
159 for(UInt16 i = 1; i < argc; ++i)
160 scene->addChild(SceneFileHandler::the()->read(argv[i]));
162 else
164 scene = makeTorus(.5, 3, 16, 16);
167 // create the SimpleSceneManager helper
168 mgr = SimpleSceneManager::create();
170 // create the window and initial camera/viewport
171 mgr->setWindow(pwin );
172 // tell the manager what to manage
173 mgr->setRoot (scene);
175 /* set twosided light model */
176 glLightModelf( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
178 // Background
179 GradientBackgroundUnrecPtr gbkgnd = GradientBackground::create();
181 gbkgnd->addLine( Color3f(.7,.7,1.), 0.0 );
182 gbkgnd->addLine( Color3f(0, 0, 1), 0.5 );
183 gbkgnd->addLine( Color3f(0, 0, .2), 1.0 );
185 mgr->getWindow()->getPort(0)->setBackground(gbkgnd);
187 // show the whole scene
188 mgr->showAll();
190 mgr->setStatistics(true);
192 return 0;
195 int main(int argc, char **argv)
197 doMain(argc, argv);
199 // GLUT main loop
200 glutMainLoop();
202 return 0;