fixed: compile issue
[opensg.git] / Examples / Tutorial / 01firstapp.cpp
blob76a0328561fd1ebecf9381ecb569ebfb53f075ea
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 simple configurations. 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 //The GLUT subsystem is set up here. This is very similar to other GLUT
71 //applications If you have worked with GLUT before, you may have the feeling
72 //of meeting old friends again, if you have not used GLUT before that is no
73 //problem. GLUT will be introduced briefly in the next section.
76 int setupGLUT(int *argc, char *argv[])
78 glutInit(argc, argv);
79 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
81 int winid = glutCreateWindow("OpenSG First Application");
83 glutDisplayFunc(display);
84 glutReshapeFunc(reshape);
86 return winid;