ruby-glfw 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. data/README +1 -0
  2. data/README.API +73 -0
  3. data/Rakefile +120 -0
  4. data/examples/boing.rb +519 -0
  5. data/examples/gears.rb +327 -0
  6. data/examples/keytest.rb +117 -0
  7. data/examples/listmodes.rb +20 -0
  8. data/examples/mipmaps.rb +104 -0
  9. data/examples/mipmaps.tga +0 -0
  10. data/examples/particles.rb +837 -0
  11. data/examples/pong3d.rb +741 -0
  12. data/examples/pong3d_field.tga +0 -0
  13. data/examples/pong3d_instr.tga +0 -0
  14. data/examples/pong3d_menu.tga +0 -0
  15. data/examples/pong3d_title.tga +0 -0
  16. data/examples/pong3d_winner1.tga +0 -0
  17. data/examples/pong3d_winner2.tga +0 -0
  18. data/examples/splitview.rb +432 -0
  19. data/examples/triangle.rb +89 -0
  20. data/examples/wave.rb +294 -0
  21. data/ext/glfw/glfw.c +1094 -0
  22. data/ext/glfw/mkrf_conf.rb +70 -0
  23. data/glfw-src/Makefile +220 -0
  24. data/glfw-src/compile.ami +61 -0
  25. data/glfw-src/compile.bat +217 -0
  26. data/glfw-src/compile.sh +607 -0
  27. data/glfw-src/docs/Makefile +57 -0
  28. data/glfw-src/docs/Reference.pdf +0 -0
  29. data/glfw-src/docs/UsersGuide.pdf +0 -0
  30. data/glfw-src/docs/cleanup.bat +22 -0
  31. data/glfw-src/docs/glfwdoc.sty +80 -0
  32. data/glfw-src/docs/glfwrm.tex +3034 -0
  33. data/glfw-src/docs/glfwug.tex +2024 -0
  34. data/glfw-src/docs/readme.txt +80 -0
  35. data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
  36. data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
  37. data/glfw-src/examples/Makefile.dos.djgpp +71 -0
  38. data/glfw-src/examples/Makefile.macosx.gcc +96 -0
  39. data/glfw-src/examples/Makefile.win32.bcc +75 -0
  40. data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
  41. data/glfw-src/examples/Makefile.win32.cygwin +79 -0
  42. data/glfw-src/examples/Makefile.win32.lcc +74 -0
  43. data/glfw-src/examples/Makefile.win32.mgw +75 -0
  44. data/glfw-src/examples/Makefile.win32.msvc +74 -0
  45. data/glfw-src/examples/Makefile.win32.ow +74 -0
  46. data/glfw-src/examples/Makefile.win32.pellesc +74 -0
  47. data/glfw-src/examples/Makefile.x11.in +54 -0
  48. data/glfw-src/examples/boing.c +606 -0
  49. data/glfw-src/examples/bundle.sh +46 -0
  50. data/glfw-src/examples/gears.c +382 -0
  51. data/glfw-src/examples/keytest.c +264 -0
  52. data/glfw-src/examples/listmodes.c +48 -0
  53. data/glfw-src/examples/mipmaps.c +126 -0
  54. data/glfw-src/examples/mipmaps.tga +0 -0
  55. data/glfw-src/examples/mtbench.c +301 -0
  56. data/glfw-src/examples/mthello.c +48 -0
  57. data/glfw-src/examples/particles.c +1148 -0
  58. data/glfw-src/examples/pong3d.c +839 -0
  59. data/glfw-src/examples/pong3d_field.tga +0 -0
  60. data/glfw-src/examples/pong3d_instr.tga +0 -0
  61. data/glfw-src/examples/pong3d_menu.tga +0 -0
  62. data/glfw-src/examples/pong3d_title.tga +0 -0
  63. data/glfw-src/examples/pong3d_winner1.tga +0 -0
  64. data/glfw-src/examples/pong3d_winner2.tga +0 -0
  65. data/glfw-src/examples/splitview.c +506 -0
  66. data/glfw-src/examples/triangle.c +108 -0
  67. data/glfw-src/examples/wave.c +397 -0
  68. data/glfw-src/images/opengl.gif +0 -0
  69. data/glfw-src/images/osicert.gif +0 -0
  70. data/glfw-src/include/GL/glfw.h +486 -0
  71. data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
  72. data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
  73. data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
  74. data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
  75. data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
  76. data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
  77. data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
  78. data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
  79. data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
  80. data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
  81. data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
  82. data/glfw-src/lib/amigaos/platform.h +337 -0
  83. data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
  84. data/glfw-src/lib/dos/dos_enable.c +51 -0
  85. data/glfw-src/lib/dos/dos_events.c +173 -0
  86. data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
  87. data/glfw-src/lib/dos/dos_glext.c +59 -0
  88. data/glfw-src/lib/dos/dos_init.c +105 -0
  89. data/glfw-src/lib/dos/dos_irq.s +246 -0
  90. data/glfw-src/lib/dos/dos_joystick.c +94 -0
  91. data/glfw-src/lib/dos/dos_keyboard.c +694 -0
  92. data/glfw-src/lib/dos/dos_mouse.c +337 -0
  93. data/glfw-src/lib/dos/dos_thread.c +267 -0
  94. data/glfw-src/lib/dos/dos_time.c +309 -0
  95. data/glfw-src/lib/dos/dos_window.c +563 -0
  96. data/glfw-src/lib/dos/platform.h +341 -0
  97. data/glfw-src/lib/enable.c +295 -0
  98. data/glfw-src/lib/fullscreen.c +95 -0
  99. data/glfw-src/lib/glext.c +201 -0
  100. data/glfw-src/lib/image.c +629 -0
  101. data/glfw-src/lib/init.c +108 -0
  102. data/glfw-src/lib/input.c +280 -0
  103. data/glfw-src/lib/internal.h +210 -0
  104. data/glfw-src/lib/joystick.c +101 -0
  105. data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
  106. data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
  107. data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
  108. data/glfw-src/lib/macosx/macosx_enable.c +42 -0
  109. data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
  110. data/glfw-src/lib/macosx/macosx_glext.c +52 -0
  111. data/glfw-src/lib/macosx/macosx_init.c +194 -0
  112. data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
  113. data/glfw-src/lib/macosx/macosx_thread.c +414 -0
  114. data/glfw-src/lib/macosx/macosx_time.c +112 -0
  115. data/glfw-src/lib/macosx/macosx_window.c +1279 -0
  116. data/glfw-src/lib/macosx/platform.h +349 -0
  117. data/glfw-src/lib/stream.c +194 -0
  118. data/glfw-src/lib/tga.c +405 -0
  119. data/glfw-src/lib/thread.c +340 -0
  120. data/glfw-src/lib/time.c +83 -0
  121. data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
  122. data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
  123. data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
  124. data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
  125. data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
  126. data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
  127. data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
  128. data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
  129. data/glfw-src/lib/win32/glfwdll.def +67 -0
  130. data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
  131. data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
  132. data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
  133. data/glfw-src/lib/win32/libglfw.pc.in +11 -0
  134. data/glfw-src/lib/win32/platform.h +474 -0
  135. data/glfw-src/lib/win32/win32_dllmain.c +60 -0
  136. data/glfw-src/lib/win32/win32_enable.c +155 -0
  137. data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
  138. data/glfw-src/lib/win32/win32_glext.c +85 -0
  139. data/glfw-src/lib/win32/win32_init.c +356 -0
  140. data/glfw-src/lib/win32/win32_joystick.c +234 -0
  141. data/glfw-src/lib/win32/win32_thread.c +511 -0
  142. data/glfw-src/lib/win32/win32_time.c +146 -0
  143. data/glfw-src/lib/win32/win32_window.c +1714 -0
  144. data/glfw-src/lib/window.c +727 -0
  145. data/glfw-src/lib/x11/Makefile.x11.in +243 -0
  146. data/glfw-src/lib/x11/platform.h +415 -0
  147. data/glfw-src/lib/x11/x11_enable.c +51 -0
  148. data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
  149. data/glfw-src/lib/x11/x11_glext.c +69 -0
  150. data/glfw-src/lib/x11/x11_init.c +275 -0
  151. data/glfw-src/lib/x11/x11_joystick.c +371 -0
  152. data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
  153. data/glfw-src/lib/x11/x11_thread.c +507 -0
  154. data/glfw-src/lib/x11/x11_time.c +154 -0
  155. data/glfw-src/lib/x11/x11_window.c +1746 -0
  156. data/glfw-src/license.txt +21 -0
  157. data/glfw-src/readme.html +927 -0
  158. data/glfw-src/support/d/examples/Makefile +59 -0
  159. data/glfw-src/support/d/examples/boing.d +610 -0
  160. data/glfw-src/support/d/examples/gears.d +379 -0
  161. data/glfw-src/support/d/examples/keytest.d +272 -0
  162. data/glfw-src/support/d/examples/listmodes.d +48 -0
  163. data/glfw-src/support/d/examples/mipmaps.d +126 -0
  164. data/glfw-src/support/d/examples/mtbench.d +304 -0
  165. data/glfw-src/support/d/examples/mthello.d +54 -0
  166. data/glfw-src/support/d/examples/particles.d +1150 -0
  167. data/glfw-src/support/d/examples/pong3d.d +840 -0
  168. data/glfw-src/support/d/examples/splitview.d +486 -0
  169. data/glfw-src/support/d/examples/triangle.d +108 -0
  170. data/glfw-src/support/d/examples/wave.d +400 -0
  171. data/glfw-src/support/d/imports/gl.d +4539 -0
  172. data/glfw-src/support/d/imports/glfw.d +349 -0
  173. data/glfw-src/support/d/imports/glu.d +328 -0
  174. data/glfw-src/support/d/lib/glfwdll.def +64 -0
  175. data/glfw-src/support/d/lib/glu32.def +56 -0
  176. data/glfw-src/support/d/lib/makefile +12 -0
  177. data/glfw-src/support/d/lib/opengl32.def +372 -0
  178. data/glfw-src/support/d/readme.html +83 -0
  179. data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
  180. data/glfw-src/support/delphi/lib/glfw.pas +437 -0
  181. data/glfw-src/support/delphi/readme.html +97 -0
  182. data/glfw-src/support/lua/examples/gears.lua +383 -0
  183. data/glfw-src/support/lua/examples/test1.lua +68 -0
  184. data/glfw-src/support/lua/readme.html +128 -0
  185. data/glfw-src/support/lua/src/luaglfw.c +1179 -0
  186. data/glfw-src/support/lua/src/luaglfw.h +48 -0
  187. data/glfw-src/support/lua/src/runlua.c +82 -0
  188. data/glfw-src/support/masm/examples/fpc.mac +47 -0
  189. data/glfw-src/support/masm/examples/makeit.bat +66 -0
  190. data/glfw-src/support/masm/examples/triangle.asm +232 -0
  191. data/glfw-src/support/masm/include/glfw.inc +326 -0
  192. data/glfw-src/support/masm/include/glu32.inc +55 -0
  193. data/glfw-src/support/masm/include/opengl32.inc +372 -0
  194. data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
  195. data/glfw-src/support/masm/readme.html +170 -0
  196. data/glfw-src/support/msvc80/GLFW.sln +26 -0
  197. data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
  198. data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
  199. data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
  200. data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
  201. data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
  202. data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
  203. data/glfw-src/support/visualbasic/readme.html +164 -0
  204. data/website/index.html +84 -0
  205. data/website/style.css +110 -0
  206. metadata +301 -0
@@ -0,0 +1,69 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: x11_glext.c
4
+ // Platform: X11 (Unix)
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+ //************************************************************************
35
+ //**** Platform implementation functions ****
36
+ //************************************************************************
37
+
38
+ //========================================================================
39
+ // Check if an OpenGL extension is available at runtime
40
+ //========================================================================
41
+
42
+ int _glfwPlatformExtensionSupported( const char *extension )
43
+ {
44
+ const GLubyte *extensions;
45
+
46
+ // Get list of GLX extensions
47
+ extensions = (const GLubyte*) glXQueryExtensionsString( _glfwLibrary.Dpy,
48
+ _glfwWin.Scrn );
49
+ if( extensions != NULL )
50
+ {
51
+ if( _glfwStringInExtensionString( extension, extensions ) )
52
+ {
53
+ return GL_TRUE;
54
+ }
55
+ }
56
+
57
+ return GL_FALSE;
58
+ }
59
+
60
+
61
+ //========================================================================
62
+ // Get the function pointer to an OpenGL function
63
+ //========================================================================
64
+
65
+ void * _glfwPlatformGetProcAddress( const char *procname )
66
+ {
67
+ return (void *) _glfw_glXGetProcAddress( (const GLubyte *) procname );
68
+ }
69
+
@@ -0,0 +1,275 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: x11_init.c
4
+ // Platform: X11 (Unix)
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+
35
+ //************************************************************************
36
+ //**** GLFW internal functions ****
37
+ //************************************************************************
38
+
39
+ //========================================================================
40
+ // Initialize GLFW thread package
41
+ //========================================================================
42
+
43
+ static void _glfwInitThreads( void )
44
+ {
45
+ // Initialize critical section handle
46
+ #ifdef _GLFW_HAS_PTHREAD
47
+ (void) pthread_mutex_init( &_glfwThrd.CriticalSection, NULL );
48
+ #endif
49
+
50
+ // The first thread (the main thread) has ID 0
51
+ _glfwThrd.NextID = 0;
52
+
53
+ // Fill out information about the main thread (this thread)
54
+ _glfwThrd.First.ID = _glfwThrd.NextID++;
55
+ _glfwThrd.First.Function = NULL;
56
+ _glfwThrd.First.Previous = NULL;
57
+ _glfwThrd.First.Next = NULL;
58
+ #ifdef _GLFW_HAS_PTHREAD
59
+ _glfwThrd.First.PosixID = pthread_self();
60
+ #endif
61
+ }
62
+
63
+
64
+ //========================================================================
65
+ // Terminate GLFW thread package
66
+ //========================================================================
67
+
68
+ static void _glfwTerminateThreads( void )
69
+ {
70
+ #ifdef _GLFW_HAS_PTHREAD
71
+
72
+ _GLFWthread *t, *t_next;
73
+
74
+ // Enter critical section
75
+ ENTER_THREAD_CRITICAL_SECTION
76
+
77
+ // Kill all threads (NOTE: THE USER SHOULD WAIT FOR ALL THREADS TO
78
+ // DIE, _BEFORE_ CALLING glfwTerminate()!!!)
79
+ t = _glfwThrd.First.Next;
80
+ while( t != NULL )
81
+ {
82
+ // Get pointer to next thread
83
+ t_next = t->Next;
84
+
85
+ // Simply murder the process, no mercy!
86
+ pthread_kill( t->PosixID, SIGKILL );
87
+
88
+ // Free memory allocated for this thread
89
+ free( (void *) t );
90
+
91
+ // Select next thread in list
92
+ t = t_next;
93
+ }
94
+
95
+ // Leave critical section
96
+ LEAVE_THREAD_CRITICAL_SECTION
97
+
98
+ // Delete critical section handle
99
+ pthread_mutex_destroy( &_glfwThrd.CriticalSection );
100
+
101
+ #endif // _GLFW_HAS_PTHREAD
102
+ }
103
+
104
+
105
+ //========================================================================
106
+ // Dynamically load libraries
107
+ //========================================================================
108
+
109
+ #ifdef _GLFW_DLOPEN_LIBGL
110
+ static char * _glfw_libGL_name[ ] =
111
+ {
112
+ "libGL.so",
113
+ "libGL.so.1",
114
+ "/usr/lib/libGL.so",
115
+ "/usr/lib/libGL.so.1",
116
+ NULL
117
+ };
118
+ #endif
119
+
120
+ static void _glfwInitLibraries( void )
121
+ {
122
+ #ifdef _GLFW_DLOPEN_LIBGL
123
+ int i;
124
+
125
+ _glfwLibrary.Libs.libGL = NULL;
126
+ for( i = 0; !_glfw_libGL_name[ i ] != NULL; i ++ )
127
+ {
128
+ _glfwLibrary.Libs.libGL = dlopen( _glfw_libGL_name[ i ],
129
+ RTLD_LAZY | RTLD_GLOBAL );
130
+ if( _glfwLibrary.Libs.libGL )
131
+ break;
132
+ }
133
+ #endif
134
+ }
135
+
136
+
137
+ //========================================================================
138
+ // Terminate GLFW when exiting application
139
+ //========================================================================
140
+
141
+ void _glfwTerminate_atexit( void )
142
+ {
143
+ glfwTerminate();
144
+ }
145
+
146
+
147
+ //========================================================================
148
+ // Initialize X11 display
149
+ //========================================================================
150
+
151
+ static int _glfwInitDisplay( void )
152
+ {
153
+ // Open display
154
+ _glfwLibrary.Dpy = XOpenDisplay( 0 );
155
+ if( !_glfwLibrary.Dpy )
156
+ {
157
+ return GL_FALSE;
158
+ }
159
+
160
+ // Check screens
161
+ _glfwLibrary.NumScreens = ScreenCount( _glfwLibrary.Dpy );
162
+ _glfwLibrary.DefaultScreen = DefaultScreen( _glfwLibrary.Dpy );
163
+
164
+ // Check for XF86VidMode extension
165
+ #ifdef _GLFW_HAS_XF86VIDMODE
166
+ _glfwLibrary.XF86VidMode.Available =
167
+ XF86VidModeQueryExtension( _glfwLibrary.Dpy,
168
+ &_glfwLibrary.XF86VidMode.EventBase,
169
+ &_glfwLibrary.XF86VidMode.ErrorBase);
170
+ #else
171
+ _glfwLibrary.XF86VidMode.Available = 0;
172
+ #endif
173
+
174
+ // Check for XRandR extension
175
+ #ifdef _GLFW_HAS_XRANDR
176
+ _glfwLibrary.XRandR.Available =
177
+ XRRQueryExtension( _glfwLibrary.Dpy,
178
+ &_glfwLibrary.XRandR.EventBase,
179
+ &_glfwLibrary.XRandR.ErrorBase );
180
+ #else
181
+ _glfwLibrary.XRandR.Available = 0;
182
+ #endif
183
+
184
+ return GL_TRUE;
185
+ }
186
+
187
+
188
+ //========================================================================
189
+ // Terminate X11 display
190
+ //========================================================================
191
+
192
+ static void _glfwTerminateDisplay( void )
193
+ {
194
+ // Open display
195
+ if( _glfwLibrary.Dpy )
196
+ {
197
+ XCloseDisplay( _glfwLibrary.Dpy );
198
+ _glfwLibrary.Dpy = NULL;
199
+ }
200
+ }
201
+
202
+
203
+ //************************************************************************
204
+ //**** Platform implementation functions ****
205
+ //************************************************************************
206
+
207
+ //========================================================================
208
+ // Initialize various GLFW state
209
+ //========================================================================
210
+
211
+ int _glfwPlatformInit( void )
212
+ {
213
+ // Initialize display
214
+ if( !_glfwInitDisplay() )
215
+ {
216
+ return GL_FALSE;
217
+ }
218
+
219
+ // Initialize thread package
220
+ _glfwInitThreads();
221
+
222
+ // Try to load libGL.so if necessary
223
+ _glfwInitLibraries();
224
+
225
+ // Install atexit() routine
226
+ atexit( _glfwTerminate_atexit );
227
+
228
+ // Initialize joysticks
229
+ _glfwInitJoysticks();
230
+
231
+ // Start the timer
232
+ _glfwInitTimer();
233
+
234
+ return GL_TRUE;
235
+ }
236
+
237
+
238
+ //========================================================================
239
+ // Close window and kill all threads
240
+ //========================================================================
241
+
242
+ int _glfwPlatformTerminate( void )
243
+ {
244
+ #ifdef _GLFW_HAS_PTHREAD
245
+ // Only the main thread is allowed to do this...
246
+ if( pthread_self() != _glfwThrd.First.PosixID )
247
+ {
248
+ return GL_FALSE;
249
+ }
250
+ #endif // _GLFW_HAS_PTHREAD
251
+
252
+ // Close OpenGL window
253
+ glfwCloseWindow();
254
+
255
+ // Kill thread package
256
+ _glfwTerminateThreads();
257
+
258
+ // Terminate display
259
+ _glfwTerminateDisplay();
260
+
261
+ // Terminate joysticks
262
+ _glfwTerminateJoysticks();
263
+
264
+ // Unload libGL.so if necessary
265
+ #ifdef _GLFW_DLOPEN_LIBGL
266
+ if( _glfwLibrary.Libs.libGL != NULL )
267
+ {
268
+ dlclose( _glfwLibrary.Libs.libGL );
269
+ _glfwLibrary.Libs.libGL = NULL;
270
+ }
271
+ #endif
272
+
273
+ return GL_TRUE;
274
+ }
275
+
@@ -0,0 +1,371 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: x11_joystick.c
4
+ // Platform: X11 (Unix)
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+ //========================================================================
35
+ // Note: Only Linux joystick input is supported at the moment. Other
36
+ // systems will behave as if there are no joysticks connected.
37
+ //========================================================================
38
+
39
+ #ifdef linux
40
+ #define _GLFW_USE_LINUX_JOYSTICKS
41
+ #endif // linux
42
+
43
+
44
+
45
+ //************************************************************************
46
+ //**** GLFW internal functions ****
47
+ //************************************************************************
48
+
49
+ #ifdef _GLFW_USE_LINUX_JOYSTICKS
50
+
51
+ //------------------------------------------------------------------------
52
+ // Here are the Linux joystick driver v1.x interface definitions that we
53
+ // use (we do not want to rely on <linux/joystick.h>):
54
+ //------------------------------------------------------------------------
55
+
56
+ #include <sys/ioctl.h>
57
+ #include <fcntl.h>
58
+ #include <errno.h>
59
+
60
+ // Joystick event types
61
+ #define JS_EVENT_BUTTON 0x01 /* button pressed/released */
62
+ #define JS_EVENT_AXIS 0x02 /* joystick moved */
63
+ #define JS_EVENT_INIT 0x80 /* initial state of device */
64
+
65
+ // Joystick event structure
66
+ struct js_event {
67
+ unsigned int time; /* (u32) event timestamp in milliseconds */
68
+ signed short value; /* (s16) value */
69
+ unsigned char type; /* (u8) event type */
70
+ unsigned char number; /* (u8) axis/button number */
71
+ };
72
+
73
+ // Joystick IOCTL commands
74
+ #define JSIOCGVERSION _IOR('j', 0x01, int) /* get driver version (u32) */
75
+ #define JSIOCGAXES _IOR('j', 0x11, char) /* get number of axes (u8) */
76
+ #define JSIOCGBUTTONS _IOR('j', 0x12, char) /* get number of buttons (u8) */
77
+
78
+ #endif // _GLFW_USE_LINUX_JOYSTICKS
79
+
80
+
81
+ //========================================================================
82
+ // _glfwInitJoysticks() - Initialize joystick interface
83
+ //========================================================================
84
+
85
+ void _glfwInitJoysticks( void )
86
+ {
87
+ #ifdef _GLFW_USE_LINUX_JOYSTICKS
88
+ int k, n, fd, joy_count;
89
+ char *joy_base_name, joy_dev_name[ 20 ];
90
+ int driver_version = 0x000800;
91
+ char ret_data;
92
+ #endif // _GLFW_USE_LINUX_JOYSTICKS
93
+ int i;
94
+
95
+ // Start by saying that there are no sticks
96
+ for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i )
97
+ {
98
+ _glfwJoy[ i ].Present = GL_FALSE;
99
+ }
100
+
101
+ #ifdef _GLFW_USE_LINUX_JOYSTICKS
102
+
103
+ // Try to open joysticks (nonblocking)
104
+ joy_count = 0;
105
+ for( k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; ++ k )
106
+ {
107
+ // Pick joystick base name
108
+ switch( k )
109
+ {
110
+ case 0:
111
+ joy_base_name = "/dev/input/js"; // USB sticks
112
+ break;
113
+ case 1:
114
+ joy_base_name = "/dev/js"; // "Legacy" sticks
115
+ break;
116
+ default:
117
+ continue; // (should never happen)
118
+ }
119
+
120
+ // Try to open a few of these sticks
121
+ for( i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; ++ i )
122
+ {
123
+ sprintf( joy_dev_name, "%s%d", joy_base_name, i );
124
+ fd = open( joy_dev_name, O_NONBLOCK );
125
+ if( fd != -1 )
126
+ {
127
+ // Remember fd
128
+ _glfwJoy[ joy_count ].fd = fd;
129
+
130
+ // Check that the joystick driver version is 1.0+
131
+ ioctl( fd, JSIOCGVERSION, &driver_version );
132
+ if( driver_version < 0x010000 )
133
+ {
134
+ // It's an old 0.x interface (we don't support it)
135
+ close( fd );
136
+ continue;
137
+ }
138
+
139
+ // Get number of joystick axes
140
+ ioctl( fd, JSIOCGAXES, &ret_data );
141
+ _glfwJoy[ joy_count ].NumAxes = (int) ret_data;
142
+
143
+ // Get number of joystick buttons
144
+ ioctl( fd, JSIOCGBUTTONS, &ret_data );
145
+ _glfwJoy[ joy_count ].NumButtons = (int) ret_data;
146
+
147
+ // Allocate memory for joystick state
148
+ _glfwJoy[ joy_count ].Axis =
149
+ (float *) malloc( sizeof(float) *
150
+ _glfwJoy[ joy_count ].NumAxes );
151
+ if( _glfwJoy[ joy_count ].Axis == NULL )
152
+ {
153
+ close( fd );
154
+ continue;
155
+ }
156
+ _glfwJoy[ joy_count ].Button =
157
+ (char *) malloc( sizeof(char) *
158
+ _glfwJoy[ joy_count ].NumButtons );
159
+ if( _glfwJoy[ joy_count ].Button == NULL )
160
+ {
161
+ free( _glfwJoy[ joy_count ].Axis );
162
+ close( fd );
163
+ continue;
164
+ }
165
+
166
+ // Clear joystick state
167
+ for( n = 0; n < _glfwJoy[ joy_count ].NumAxes; ++ n )
168
+ {
169
+ _glfwJoy[ joy_count ].Axis[ n ] = 0.0f;
170
+ }
171
+ for( n = 0; n < _glfwJoy[ joy_count ].NumButtons; ++ n )
172
+ {
173
+ _glfwJoy[ joy_count ].Button[ n ] = GLFW_RELEASE;
174
+ }
175
+
176
+ // The joystick is supported and connected
177
+ _glfwJoy[ joy_count ].Present = GL_TRUE;
178
+ joy_count ++;
179
+ }
180
+ }
181
+ }
182
+
183
+ #endif // _GLFW_USE_LINUX_JOYSTICKS
184
+
185
+ }
186
+
187
+
188
+ //========================================================================
189
+ // _glfwTerminateJoysticks() - Close all opened joystick handles
190
+ //========================================================================
191
+
192
+ void _glfwTerminateJoysticks( void )
193
+ {
194
+
195
+ #ifdef _GLFW_USE_LINUX_JOYSTICKS
196
+
197
+ int i;
198
+
199
+ // Close any opened joysticks
200
+ for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i )
201
+ {
202
+ if( _glfwJoy[ i ].Present )
203
+ {
204
+ close( _glfwJoy[ i ].fd );
205
+ free( _glfwJoy[ i ].Axis );
206
+ free( _glfwJoy[ i ].Button );
207
+ _glfwJoy[ i ].Present = GL_FALSE;
208
+ }
209
+ }
210
+
211
+ #endif // _GLFW_USE_LINUX_JOYSTICKS
212
+
213
+ }
214
+
215
+
216
+ //========================================================================
217
+ // _glfwPollJoystickEvents() - Empty joystick event queue
218
+ //========================================================================
219
+
220
+ static void _glfwPollJoystickEvents( void )
221
+ {
222
+
223
+ #ifdef _GLFW_USE_LINUX_JOYSTICKS
224
+
225
+ struct js_event e;
226
+ int i;
227
+
228
+ // Get joystick events for all GLFW joysticks
229
+ for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i )
230
+ {
231
+ // Is the stick present?
232
+ if( _glfwJoy[ i ].Present )
233
+ {
234
+ // Read all queued events (non-blocking)
235
+ while( read(_glfwJoy[i].fd, &e, sizeof(struct js_event)) > 0 )
236
+ {
237
+ // We don't care if it's an init event or not
238
+ e.type &= ~JS_EVENT_INIT;
239
+
240
+ // Check event type
241
+ switch( e.type )
242
+ {
243
+ case JS_EVENT_AXIS:
244
+ _glfwJoy[ i ].Axis[ e.number ] = (float) e.value /
245
+ 32767.0f;
246
+ // We need to change the sign for the Y axes, so that
247
+ // positive = up/forward, according to the GLFW spec.
248
+ if( e.number & 1 )
249
+ {
250
+ _glfwJoy[ i ].Axis[ e.number ] =
251
+ -_glfwJoy[ i ].Axis[ e.number ];
252
+ }
253
+ break;
254
+
255
+ case JS_EVENT_BUTTON:
256
+ _glfwJoy[ i ].Button[ e.number ] =
257
+ e.value ? GLFW_PRESS : GLFW_RELEASE;
258
+ break;
259
+
260
+ default:
261
+ break;
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ #endif // _GLFW_USE_LINUX_JOYSTICKS
268
+
269
+ }
270
+
271
+
272
+ //************************************************************************
273
+ //**** Platform implementation functions ****
274
+ //************************************************************************
275
+
276
+ //========================================================================
277
+ // _glfwPlatformGetJoystickParam() - Determine joystick capabilities
278
+ //========================================================================
279
+
280
+ int _glfwPlatformGetJoystickParam( int joy, int param )
281
+ {
282
+ // Is joystick present?
283
+ if( !_glfwJoy[ joy ].Present )
284
+ {
285
+ return 0;
286
+ }
287
+
288
+ switch( param )
289
+ {
290
+ case GLFW_PRESENT:
291
+ return GL_TRUE;
292
+
293
+ case GLFW_AXES:
294
+ return _glfwJoy[ joy ].NumAxes;
295
+
296
+ case GLFW_BUTTONS:
297
+ return _glfwJoy[ joy ].NumButtons;
298
+
299
+ default:
300
+ break;
301
+ }
302
+
303
+ return 0;
304
+ }
305
+
306
+
307
+ //========================================================================
308
+ // _glfwPlatformGetJoystickPos() - Get joystick axis positions
309
+ //========================================================================
310
+
311
+ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
312
+ {
313
+ int i;
314
+
315
+ // Is joystick present?
316
+ if( !_glfwJoy[ joy ].Present )
317
+ {
318
+ return 0;
319
+ }
320
+
321
+ // Update joystick state
322
+ _glfwPollJoystickEvents();
323
+
324
+ // Does the joystick support less axes than requested?
325
+ if( _glfwJoy[ joy ].NumAxes < numaxes )
326
+ {
327
+ numaxes = _glfwJoy[ joy ].NumAxes;
328
+ }
329
+
330
+ // Copy axis positions from internal state
331
+ for( i = 0; i < numaxes; ++ i )
332
+ {
333
+ pos[ i ] = _glfwJoy[ joy ].Axis[ i ];
334
+ }
335
+
336
+ return numaxes;
337
+ }
338
+
339
+
340
+ //========================================================================
341
+ // _glfwPlatformGetJoystickButtons() - Get joystick button states
342
+ //========================================================================
343
+
344
+ int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,
345
+ int numbuttons )
346
+ {
347
+ int i;
348
+
349
+ // Is joystick present?
350
+ if( !_glfwJoy[ joy ].Present )
351
+ {
352
+ return 0;
353
+ }
354
+
355
+ // Update joystick state
356
+ _glfwPollJoystickEvents();
357
+
358
+ // Does the joystick support less buttons than requested?
359
+ if( _glfwJoy[ joy ].NumButtons < numbuttons )
360
+ {
361
+ numbuttons = _glfwJoy[ joy ].NumButtons;
362
+ }
363
+
364
+ // Copy button states from internal state
365
+ for( i = 0; i < numbuttons; ++ i )
366
+ {
367
+ buttons[ i ] = _glfwJoy[ joy ].Button[ i ];
368
+ }
369
+
370
+ return numbuttons;
371
+ }