changed: deal with dxt1 compressed dds volumes
[opensg.git] / Examples / Tutorial / 13multithreading.cpp
blob157dc6064df7e96ec0870649f9ebcbaa7d1db953
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 #include <OSGThreadManager.h>
10 #else
11 #include <OpenSG/OSGGLUT.h>
12 #include <OpenSG/OSGConfig.h>
13 #include <OpenSG/OSGSimpleGeometry.h>
14 #include <OpenSG/OSGGLUTWindow.h>
15 #include <OpenSG/OSGSimpleSceneManager.h>
17 #include <OpenSG/OSGThreadManager.h>
18 #endif
20 OSG::SimpleSceneManagerRefPtr mgr;
21 OSG::NodeRecPtr scene;
23 int setupGLUT(int *argc, char *argv[]);
25 OSG::NodeTransitPtr createScenegraph(void)
27 // the scene must be created here
28 OSG::NodeRecPtr n = OSG::makeSphere(2,2);
29 return OSG::NodeTransitPtr(n);
32 void printA(void *args)
34 while (true)
35 SLOG << "Thread One 11111" << std::endl;
38 void printB(void *args)
40 while (true)
41 SLOG << "Thread Two 22222" << std::endl;
44 int main(int argc, char **argv)
46 OSG::osgInit(argc,argv);
49 int winid = setupGLUT(&argc, argv);
50 OSG::GLUTWindowRecPtr gwin= OSG::GLUTWindow::create();
51 gwin->setGlutId(winid);
52 gwin->init();
54 scene = createScenegraph();
56 mgr = OSG::SimpleSceneManager::create();
57 mgr->setWindow(gwin );
58 mgr->setRoot (scene);
59 mgr->showAll();
61 OSG::ThreadRefPtr threadOne =
62 OSG::dynamic_pointer_cast<OSG::Thread>(
63 OSG::ThreadManager::the()->getThread("One", false));
65 OSG::ThreadRefPtr threadTwo =
66 OSG::dynamic_pointer_cast<OSG::Thread>(
67 OSG::ThreadManager::the()->getThread("Two", false));
69 threadOne->runFunction(printA, 1, NULL);
70 threadTwo->runFunction(printB, 1, NULL);
72 OSG::commitChanges();
75 glutMainLoop();
77 return 0;
80 void reshape(int w, int h)
82 mgr->resize(w, h);
83 glutPostRedisplay();
86 void display(void)
88 mgr->redraw();
91 void mouse(int button, int state, int x, int y)
93 if (state)
94 mgr->mouseButtonRelease(button, x, y);
95 else
96 mgr->mouseButtonPress(button, x, y);
98 glutPostRedisplay();
101 void motion(int x, int y)
103 mgr->mouseMove(x, y);
104 glutPostRedisplay();
107 int setupGLUT(int *argc, char *argv[])
109 glutInit(argc, argv);
110 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
112 int winid = glutCreateWindow("OpenSG First Application");
114 glutDisplayFunc(display);
115 glutMouseFunc(mouse);
116 glutMotionFunc(motion);
117 glutReshapeFunc(reshape);
118 glutIdleFunc(display);
120 return winid;