fixed: gcc8 compile issues
[opensg.git] / Examples / Tutorial / 03MoreThanATorus.cpp
blob00bbb51c6573a6fbeadb02e8d8c9bb3a7b721d3b
1 //what follows here is the smallest OpenSG programm possible
2 //most things used here are explained now or on the next few pages, so don't
3 //worry if not everythings clear right at the beginning...
5 //Some needed inlcude files - these will become more, believe me ;)
6 #ifdef OSG_BUILD_ACTIVE
7 #include <OSGGLUT.h>
8 #include <OSGConfig.h>
9 #include <OSGSimpleGeometry.h>
10 #include <OSGGLUTWindow.h>
11 #include <OSGSimpleSceneManager.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>
18 #endif
20 //The SimpleSceneManager is a little usefull class which helps us to
21 //manage little scenes. It will be discussed in detail later on
22 OSG::SimpleSceneManagerRefPtr mgr;
23 OSG::NodeRecPtr scene;
25 //we have a forward declarion here, just to sort the code
26 int setupGLUT( int *argc, char *argv[] );
28 //This function will create our scenegraph
29 OSG::NodeTransitPtr createScenegraph(void)
31 // First we will create all needed geometry
32 // the body of the house
33 OSG::NodeRecPtr houseMain = OSG::makeBox(20,20,20,1,1,1);
35 // now the roof
36 OSG::NodeRecPtr roof = OSG::makeBox(14.14, 14.14, 20, 1, 1, 1);
38 // and the chimney - we have the top and sides generated
39 // but we have no need for the bottom (it is inside the house)
40 OSG::NodeRecPtr chimney = OSG::makeCylinder(10,1,8,true,true,false);
42 // Now we create the root node and attach the geometry nodes to it
43 OSG::NodeRecPtr n = OSG::Node::create();
44 n->setCore(OSG::Group::create());
45 n->addChild(houseMain);
46 n->addChild(roof);
47 n->addChild(chimney);
49 return OSG::NodeTransitPtr(n);
52 int main(int argc, char **argv)
54 // Init the OpenSG subsystem
55 OSG::osgInit(argc,argv);
58 // We create a GLUT Window (that is almost the same for most applications)
59 int winid = setupGLUT(&argc, argv);
60 OSG::GLUTWindowRecPtr gwin = OSG::GLUTWindow::create();
61 gwin->setGlutId(winid);
62 gwin->init();
64 // That will be our whole scene for now : an incredible Torus
65 scene = createScenegraph();
67 // Create and setup our little friend - the SSM
68 mgr = OSG::SimpleSceneManager::create();
69 mgr->setWindow(gwin );
70 mgr->setRoot (scene);
71 mgr->showAll();
73 OSG::commitChanges();
76 // Give Control to the GLUT Main Loop
77 glutMainLoop();
79 return 0;
82 // react to size changes
83 void reshape(int w, int h)
85 mgr->resize(w, h);
86 glutPostRedisplay();
89 // just redraw our scene if this GLUT callback is invoked
90 void display(void)
92 mgr->redraw();
95 // react to mouse button presses
96 void mouse(int button, int state, int x, int y)
98 if (state)
99 mgr->mouseButtonRelease(button, x, y);
100 else
101 mgr->mouseButtonPress(button, x, y);
103 glutPostRedisplay();
106 // react to mouse motions with pressed buttons
107 void motion(int x, int y)
109 mgr->mouseMove(x, y);
110 glutPostRedisplay();
113 //The GLUT subsystem is set up here. This is very similar to other GLUT applications
114 //If you have worked with GLUT before, you may have the feeling of meeting old friends again,
115 //if you have not used GLUT before that is no problem. GLUT will be introduced shortly on the
116 //next section
118 int setupGLUT(int *argc, char *argv[])
120 glutInit(argc, argv);
121 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
123 int winid = glutCreateWindow("OpenSG First Application");
125 glutDisplayFunc(display);
126 glutMouseFunc(mouse);
127 glutMotionFunc(motion);
128 glutReshapeFunc(reshape);
129 glutIdleFunc(display);
131 return winid;