1 // OpenSG Tutorial Example: Loading
3 // This example shows how to load a scene file using OpenSG.
4 // The supported formats right now are VRML97, OBJ, OFF and RAW, so just
5 // calling this program with a scene file as a parameter should load the scene
11 #include "OSGConfig.h"
12 #include "OSGSimpleGeometry.h"
13 #include "OSGGLUTWindow.h"
14 #include "OSGSimpleSceneManager.h"
15 #include "OSGAction.h"
19 // the general scene file loading handler
20 #include "OSGSceneFileHandler.h"
22 #include "OSGFieldContainerUtils.h"
25 // The SimpleSceneManager to manage simple applications
26 OSG::SimpleSceneManagerRefPtr mgr
;
28 // forward declaration so we can have the interesting stuff upfront
29 int setupGLUT( int *argc
, char *argv
[] );
31 // Initialize GLUT & OpenSG and set up the scene
32 int main(int argc
, char **argv
)
35 OSG::osgInit(argc
,argv
);
38 int winid
= setupGLUT(&argc
, argv
);
41 // the connection between GLUT and OpenSG
42 OSG::GLUTWindowUnrecPtr gwin
= OSG::GLUTWindow::create();
43 gwin
->setGlutId(winid
);
48 OSG::NodeUnrecPtr scene
;
52 FWARNING(("No file given!\n"));
53 FWARNING(("Supported file formats:\n"));
55 OSG::SceneFileHandler::the()->print();
56 scene
= OSG::makeTorus(.5, 2, 16, 16);
61 All scene file loading is handled via the SceneFileHandler.
63 scene
= OSG::SceneFileHandler::the()->read(argv
[1]);
70 // create the SimpleSceneManager helper
71 mgr
= OSG::SimpleSceneManager::create();
72 mgr
->setUseTraversalAction(true);
74 // tell the manager what to manage
75 mgr
->setWindow(gwin
);
78 // show the whole scene
90 // GLUT callback functions
98 OSG::Thread::getCurrentChangeList()->clear();
101 // react to size changes
102 void reshape(int w
, int h
)
108 // react to mouse button presses
109 void mouse(int button
, int state
, int x
, int y
)
113 mgr
->mouseButtonRelease(button
, x
, y
);
115 mgr
->mouseButtonPress(button
, x
, y
);
120 // react to mouse motions with pressed buttons
121 void motion(int x
, int y
)
124 mgr
->mouseMove(x
, y
);
129 void keyboard(unsigned char k
, int , int )
140 mgr
->setNavigationMode(OSG::Navigator::FLY
);
143 mgr
->setNavigationMode(OSG::Navigator::TRACKBALL
);
146 mgr
->setStatistics(true);
149 mgr
->setStatistics(false);
152 mgr
->setHeadlight(!mgr
->getHeadlightState());
156 bool useTrav
= !mgr
->getUseTraversalAction();
157 mgr
->setUseTraversalAction(useTrav
);
158 printf("Using %s action.\n", useTrav
? "render traversal" : "render");
164 std::cout
<< "Scanning memory consumption." << std::endl
;
165 OSG::MemoryConsumption mc
;
173 // setup the GLUT library which handles the windows for us
174 int setupGLUT(int *argc
, char *argv
[])
176 glutInit(argc
, argv
);
177 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
179 int winid
= glutCreateWindow("OpenSG");
181 glutReshapeFunc(reshape
);
182 glutDisplayFunc(display
);
183 glutIdleFunc(display
);
184 glutMouseFunc(mouse
);
185 glutMotionFunc(motion
);
186 glutKeyboardFunc(keyboard
);