1 // all needed include files
2 #ifdef OSG_BUILD_ACTIVE
5 #include <OSGSimpleGeometry.h>
6 #include <OSGGLUTWindow.h>
7 #include <OSGSimpleSceneManager.h>
9 //additional headder files
10 #include <OSGSceneFileHandler.h>
11 #include <OSGDistanceLOD.h>
13 #include <OpenSG/OSGGLUT.h>
14 #include <OpenSG/OSGConfig.h>
15 #include <OpenSG/OSGSimpleGeometry.h>
16 #include <OpenSG/OSGGLUTWindow.h>
17 #include <OpenSG/OSGSimpleSceneManager.h>
19 //additional headder files
20 #include <OpenSG/OSGSceneFileHandler.h>
21 #include <OpenSG/OSGDistanceLOD.h>
24 OSG::SimpleSceneManagerRefPtr mgr
;
25 OSG::NodeRecPtr scene
;
27 int setupGLUT(int *argc
, char *argv
[]);
29 OSG::NodeTransitPtr
createScenegraph(void)
31 //At first we load all needed models from file
32 OSG::NodeRecPtr w_high
=
33 OSG::SceneFileHandler::the()->read("Data/woman_high.wrl");
35 OSG::NodeRecPtr w_medium
=
36 OSG::SceneFileHandler::the()->read("Data/woman_medium.wrl");
38 OSG::NodeRecPtr w_low
= OSG::
39 SceneFileHandler::the()->read("Data/woman_low.wrl");
42 if((w_high
== NULL
) || (w_medium
== NULL
)|| (w_low
== NULL
))
44 std::cout
<< "It was not possible to load all needed models from file"
46 return OSG::NodeTransitPtr();
50 OSG::DistanceLODRecPtr lod
= OSG::DistanceLOD::create();
51 lod
->editSFCenter()->setValue(OSG::Pnt3f(0,0,0));
52 lod
->editMFRange()->push_back(200);
53 lod
->editMFRange()->push_back(500);
55 //the node containing the LOD core. The three models will be
56 //added as its children
57 OSG::NodeRecPtr lodNode
= OSG::Node::create();
58 lodNode
->setCore(lod
);
59 lodNode
->addChild(w_high
);
60 lodNode
->addChild(w_medium
);
61 lodNode
->addChild(w_low
);
63 OSG::NodeRecPtr root
= OSG::Node::create();
64 root
->setCore (OSG::Group::create());
65 root
->addChild(lodNode
);
67 return OSG::NodeTransitPtr(root
);
70 int main(int argc
, char **argv
)
72 OSG::osgInit(argc
,argv
);
75 int winid
= setupGLUT(&argc
, argv
);
76 OSG::GLUTWindowRecPtr gwin
= OSG::GLUTWindow::create();
77 gwin
->setGlutId(winid
);
80 scene
= createScenegraph();
82 mgr
= OSG::SimpleSceneManager::create();
83 mgr
->setWindow(gwin
);
95 void reshape(int w
, int h
)
106 void mouse(int button
, int state
, int x
, int y
)
109 mgr
->mouseButtonRelease(button
, x
, y
);
111 mgr
->mouseButtonPress(button
, x
, y
);
116 void motion(int x
, int y
)
118 mgr
->mouseMove(x
, y
);
122 int setupGLUT(int *argc
, char *argv
[])
124 glutInit(argc
, argv
);
125 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
127 int winid
= glutCreateWindow("OpenSG First Application");
129 glutDisplayFunc(display
);
130 glutMouseFunc(mouse
);
131 glutMotionFunc(motion
);
132 glutReshapeFunc(reshape
);
133 glutIdleFunc(display
);