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
9 #include <OSGSimpleGeometry.h>
10 #include <OSGGLUTWindow.h>
11 #include <OSGSimpleSceneManager.h>
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>
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
);
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
);
51 // Give Control to the GLUT Main Loop
57 // react to size changes
58 void reshape(int w
, int h
)
64 // just redraw our scene if this GLUT callback is invoked
70 // react to mouse button presses
71 void mouse(int button
, int state
, int x
, int y
)
74 mgr
->mouseButtonRelease(button
, x
, y
);
76 mgr
->mouseButtonPress(button
, x
, y
);
81 // react to mouse motions with pressed buttons
82 void motion(int x
, int y
)
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
[])
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
);