fixed: auto_ptr -> unique_ptr
[opensg.git] / Examples / Tutorial / 08coresdemo.cpp
blob9bed3dbf647ea0f2e516cfc9ba05700695530bb2
1 // all needed include files
2 #ifdef OSG_BUILD_ACTIVE
3 #include <OSGGLUT.h>
4 #include <OSGConfig.h>
5 #include <OSGSimpleGeometry.h>
6 #include <OSGGLUTWindow.h>
7 #include <OSGSimpleSceneManager.h>
9 //additional headder files
10 #include <OSGSceneFileHandler.h>
11 #include <OSGDistanceLOD.h>
12 #else
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>
22 #endif
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");
41 //we check the result
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"
45 << std::endl;
46 return OSG::NodeTransitPtr();
49 //now the LOD core
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);
78 gwin->init();
80 scene = createScenegraph();
82 mgr = OSG::SimpleSceneManager::create();
83 mgr->setWindow(gwin );
84 mgr->setRoot (scene);
85 mgr->showAll();
87 OSG::commitChanges();
90 glutMainLoop();
92 return 0;
95 void reshape(int w, int h)
97 mgr->resize(w, h);
98 glutPostRedisplay();
101 void display(void)
103 mgr->redraw();
106 void mouse(int button, int state, int x, int y)
108 if (state)
109 mgr->mouseButtonRelease(button, x, y);
110 else
111 mgr->mouseButtonPress(button, x, y);
113 glutPostRedisplay();
116 void motion(int x, int y)
118 mgr->mouseMove(x, y);
119 glutPostRedisplay();
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);
135 return winid;