Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / OpenGL / GlutStuff.cpp
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose, 
8 including commercial applications, and to alter it and redistribute it freely, 
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 #ifndef _WINDOWS
17
18 #include "DemoApplication.h"
19
20 //glut is C code, this global gDemoApplication links glut to the C++ demo
21 static DemoApplication* gDemoApplication = 0;
22
23
24 #include "GlutStuff.h"
25
26 static  void glutKeyboardCallback(unsigned char key, int x, int y)
27 {
28         gDemoApplication->keyboardCallback(key,x,y);
29 }
30
31 static  void glutKeyboardUpCallback(unsigned char key, int x, int y)
32 {
33   gDemoApplication->keyboardUpCallback(key,x,y);
34 }
35
36 static void glutSpecialKeyboardCallback(int key, int x, int y)
37 {
38         gDemoApplication->specialKeyboard(key,x,y);
39 }
40
41 static void glutSpecialKeyboardUpCallback(int key, int x, int y)
42 {
43         gDemoApplication->specialKeyboardUp(key,x,y);
44 }
45
46
47 static void glutReshapeCallback(int w, int h)
48 {
49         gDemoApplication->reshape(w,h);
50 }
51
52 static void glutMoveAndDisplayCallback()
53 {
54         gDemoApplication->moveAndDisplay();
55 }
56
57 static void glutMouseFuncCallback(int button, int state, int x, int y)
58 {
59         gDemoApplication->mouseFunc(button,state,x,y);
60 }
61
62
63 static void     glutMotionFuncCallback(int x,int y)
64 {
65         gDemoApplication->mouseMotionFunc(x,y);
66 }
67
68
69 static void glutDisplayCallback(void)
70 {
71         gDemoApplication->displayCallback();
72 }
73
74
75 int glutmain(int argc, char **argv,int width,int height,const char* title,DemoApplication* demoApp) {
76     
77         gDemoApplication = demoApp;
78
79         glutInit(&argc, argv);
80     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
81     glutInitWindowPosition(0, 0);
82     glutInitWindowSize(width, height);
83     glutCreateWindow(title);
84 #ifdef BT_USE_FREEGLUT
85         glutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
86 #endif
87
88     gDemoApplication->myinit();
89
90         glutKeyboardFunc(glutKeyboardCallback);
91         glutKeyboardUpFunc(glutKeyboardUpCallback);
92         glutSpecialFunc(glutSpecialKeyboardCallback);
93         glutSpecialUpFunc(glutSpecialKeyboardUpCallback);
94
95         glutReshapeFunc(glutReshapeCallback);
96     //createMenu();
97         glutIdleFunc(glutMoveAndDisplayCallback);
98         glutMouseFunc(glutMouseFuncCallback);
99         glutPassiveMotionFunc(glutMotionFuncCallback);
100         glutMotionFunc(glutMotionFuncCallback);
101         glutDisplayFunc( glutDisplayCallback );
102
103         glutMoveAndDisplayCallback();
104
105 //enable vsync to avoid tearing on Apple (todo: for Windows)
106
107 #if defined(__APPLE__) && !defined (VMDMESA)
108 int swap_interval = 1;
109 CGLContextObj cgl_context = CGLGetCurrentContext();
110 CGLSetParameter(cgl_context, kCGLCPSwapInterval, &swap_interval);
111 #endif
112
113
114         
115     glutMainLoop();
116     return 0;
117 }
118
119
120 #endif //_WINDOWS