fixed: compile issue
[opensg.git] / Examples / Tutorial / 01firstapp2.cpp
blobfaa3f5b336ab909e979f3f487a7863f90c99511f
1 // what follows here is probably 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 <OSGConfig.h>
8 #include <OSGGLUT.h>
9 #include <OSGSimpleGeometry.h>
10 #include <OSGGLUTWindow.h>
11 #include <OSGSimpleSceneManager.h>
12 #else
13 #include <OpenSG/OSGConfig.h>
14 #include <OpenSG/OSGGLUT.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;
24 // we have a forward declarion here, just to sort the code
25 int setupGLUT( int *argc, char *argv[] );
27 int main(int argc, char **argv)
29 // Init the OpenSG subsystem
30 OSG::osgInit(argc,argv);
33 // We create a GLUT Window (that is almost the same for most applications)
34 int winid = setupGLUT(&argc, argv);
35 OSG::GLUTWindowRecPtr gwin= OSG::GLUTWindow::create();
36 gwin->setGlutId(winid);
37 gwin->init();
39 // That will be our whole scene for now : an incredible Torus
40 OSG::NodeRecPtr scene = OSG::makeTorus(.5, 2, 16, 16);
42 // Create and setup our little friend - the SSM
43 mgr = OSG::SimpleSceneManager::create();
44 mgr->setWindow(gwin );
45 mgr->setRoot (scene);
46 mgr->showAll();
48 OSG::commitChanges();
51 // Give Control to the GLUT Main Loop
52 glutMainLoop();
54 return 0;
57 // react to size changes
58 void reshape(int w, int h)
60 mgr->resize(w, h);
61 glutPostRedisplay();
64 // just redraw our scene if this GLUT callback is invoked
65 void display(void)
67 mgr->redraw();
70 // react to mouse button presses
71 void mouse(int button, int state, int x, int y)
73 if (state)
74 mgr->mouseButtonRelease(button, x, y);
75 else
76 mgr->mouseButtonPress(button, x, y);
78 glutPostRedisplay();
81 // react to mouse motions with pressed buttons
82 void motion(int x, int y)
84 mgr->mouseMove(x, y);
85 glutPostRedisplay();
88 //The GLUT subsystem is set up here. This is very similar to other GLUT
89 //applications If you have worked with GLUT before, you may have the feeling
90 //of meeting old friends again, if you have not used GLUT before that is no
91 //problem. GLUT will be introduced briefly in the next section.
93 int setupGLUT(int *argc, char *argv[])
95 glutInit(argc, argv);
96 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
98 int winid = glutCreateWindow("OpenSG First Application");
100 glutDisplayFunc(display);
101 glutMouseFunc(mouse);
102 glutMotionFunc(motion);
103 glutReshapeFunc(reshape);
104 glutIdleFunc(display);
106 return winid;