1 // all needed include files
2 #ifdef OSG_BUILD_ACTIVE
5 #include <OSGSimpleGeometry.h>
6 #include <OSGGLUTWindow.h>
7 #include <OSGSimpleSceneManager.h>
9 #include <OSGSceneFileHandler.h>
10 #include <OSGNameAttachment.h>
12 #include <OpenSG/OSGGLUT.h>
13 #include <OpenSG/OSGConfig.h>
14 #include <OpenSG/OSGSimpleGeometry.h>
15 #include <OpenSG/OSGGLUTWindow.h>
16 #include <OpenSG/OSGSimpleSceneManager.h>
18 #include <OpenSG/OSGSceneFileHandler.h>
19 #include <OpenSG/OSGNameAttachment.h>
22 OSG::SimpleSceneManagerRefPtr mgr
;
23 OSG::NodeRecPtr scene
;
25 int setupGLUT(int *argc
, char *argv
[]);
27 //This is the function that will be called when a node
28 //is entered during traversal.
29 OSG::Action::ResultE
enter(OSG::Node
* const node
)
33 std::cout
<< getName(node
) << std::endl
;
37 std::cout
<< "No name was set!" << std::endl
;
40 return OSG::Action::Continue
;
43 //This function will test if the core is of type
44 //geometry and if it is, it will print the node's
46 OSG::Action::ResultE
isGeometry(OSG::Node
* const node
)
48 // this tests if the core is derived from geometry
49 if (node
->getCore()->getType().isDerivedFrom(OSG::Geometry::getClassType()))
53 std::cout
<< "Found a geometry core stored in " << getName(node
)
58 std::cout
<< "Found a geometry core but node has no name"
63 return OSG::Action::Continue
;
67 OSG::NodeTransitPtr
createScenegraph(void)
69 // the scene must be created here
71 OSG::SceneFileHandler::the()->read("Data/torus_sphere_cone.wrl");
76 std::cout
<< "Loading the specified file was not possible!"
78 return OSG::NodeTransitPtr();
81 return OSG::NodeTransitPtr(n
);
84 int main(int argc
, char **argv
)
86 OSG::osgInit(argc
,argv
);
89 int winid
= setupGLUT(&argc
, argv
);
90 OSG::GLUTWindowRecPtr gwin
= OSG::GLUTWindow::create();
91 gwin
->setGlutId(winid
);
94 scene
= createScenegraph();
96 mgr
= OSG::SimpleSceneManager::create();
97 mgr
->setWindow(gwin
);
101 OSG::commitChanges();
109 void reshape(int w
, int h
)
120 void mouse(int button
, int state
, int x
, int y
)
123 mgr
->mouseButtonRelease(button
, x
, y
);
125 mgr
->mouseButtonPress(button
, x
, y
);
130 void motion(int x
, int y
)
132 mgr
->mouseMove(x
, y
);
136 void keyboard(unsigned char k
, int x
, int y
){
141 // clean up global variables
150 // this will print the names of all nodes
151 // in the whole graph
154 std::cout
<< std::endl
<< std::endl
;
155 std::cout
<< "Printing all node names";
156 std::cout
<< "---------------------------------------";
157 std::cout
<< std::endl
<< std::endl
;
159 // now we invoke the traversal
160 traverse(scene
, enter
);
164 // this will only print the names of nodes
165 // which have a geometry core
168 std::cout
<< std::endl
<< std::endl
;
169 std::cout
<< "Printing all geometry nodes";
170 std::cout
<< "---------------------------------------";
171 std::cout
<< std::endl
<< std::endl
;
173 // traverse the graph
174 traverse(scene
, isGeometry
);
180 int setupGLUT(int *argc
, char *argv
[])
182 glutInit(argc
, argv
);
183 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
185 int winid
= glutCreateWindow("OpenSG First Application");
187 glutDisplayFunc(display
);
188 glutMouseFunc(mouse
);
189 glutMotionFunc(motion
);
190 glutReshapeFunc(reshape
);
191 glutIdleFunc(display
);
192 glutKeyboardFunc(keyboard
);