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
6 // It does show however, how to use the extra options that the Rhino3D loader
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>
25 SimpleSceneManagerRefPtr mgr
;
36 // react to size changes
37 void reshape(int w
, int h
)
43 // react to mouse button presses
44 void mouse(int button
, int state
, int x
, int y
)
47 mgr
->mouseButtonRelease(button
, x
, y
);
49 mgr
->mouseButtonPress(button
, x
, y
);
54 // react to mouse motions with pressed buttons
55 void motion(int x
, int y
)
62 void keyboard(unsigned char k
, int, int)
76 mgr
->getRenderAction()->setVolumeDrawing(
77 !mgr
->getRenderAction()->getVolumeDrawing());
78 std::cerr
<< "Volume Drawing: "
79 << (mgr
->getRenderAction()->getVolumeDrawing()?"on":"off")
86 std::cerr
<< "Writing osb...";
87 SceneFileHandler::the()->write(mgr
->getRoot(), "test.osb");
88 std::cerr
<< "done." << std::endl
;
95 std::cerr
<< "Writing osg...";
96 SceneFileHandler::the()->write(mgr
->getRoot(), "test.osg");
97 std::cerr
<< "done." << std::endl
;
105 int doMain(int argc
, char **argv
)
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();
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);
140 SceneFileHandler::the()->setOption("3dm",
154 scene
= Node::create();
155 GroupUnrecPtr g
= Group::create();
159 for(UInt16 i
= 1; i
< argc
; ++i
)
160 scene
->addChild(SceneFileHandler::the()->read(argv
[i
]));
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
);
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
190 mgr
->setStatistics(true);
195 int main(int argc
, char **argv
)