ruby-glfw 0.9

Sign up to get free protection for your applications and to get access to all the features.
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,294 @@
1
+ # *****************************************************************************
2
+ # * Wave Simulation in OpenGL
3
+ # * (C) 2002 Jakob Thomsen
4
+ # * http://home.in.tum.de/~thomsen
5
+ # * Modified for GLFW by Sylvain Hellegouarch - sh@programmationworld.com
6
+ # * Modified for variable frame rate by Marcus Geelnard
7
+ # * 2003-Jan-31: Minor cleanups and speedups / MG
8
+ # *****************************************************************************/
9
+ # Converted to ruby from GLFW example wave.c
10
+ # Changed parameters to accomodate for ruby slowness
11
+
12
+ require 'opengl'
13
+ require 'glfw'
14
+ include Gl,Glu,Glfw,Math
15
+
16
+ # Maximum delta T to allow for differential calculations
17
+ MAX_DELTA_T = 0.5
18
+
19
+ # Animation speed (10.0 looks good)
20
+ ANIMATION_SPEED = 10.0
21
+
22
+ $alpha = 210.0
23
+ $beta = -70.0
24
+ $zoom = 2.0
25
+
26
+ $running = true
27
+
28
+ class Vertex
29
+ attr_accessor :x,:y,:z,:r,:g,:b
30
+ end
31
+
32
+ GRIDW = 50
33
+ GRIDH = 50
34
+ VERTEXNUM = GRIDW * GRIDH
35
+
36
+ QUADW = GRIDW - 1
37
+ QUADH = GRIDH - 1
38
+ QUADNUM = QUADW * QUADH
39
+
40
+ $quad = Array.new(4*QUADNUM,0)
41
+ $vertex = Array.new(VERTEXNUM).collect {Vertex.new}
42
+
43
+ # The grid will look like this:
44
+ #
45
+ # 3 4 5
46
+ # *---*---*
47
+ # | | |
48
+ # | 0 | 1 |
49
+ # | | |
50
+ # *---*---*
51
+ # 0 1 2
52
+ #
53
+
54
+ def initVertices
55
+ # place the vertices in a grid
56
+ GRIDH.times do |y|
57
+ GRIDW.times do |x|
58
+ p = y*GRIDW + x
59
+ $vertex[p].x = (x-GRIDW/2).to_f/(GRIDW/2).to_f
60
+ $vertex[p].y = (y-GRIDH/2).to_f/(GRIDH/2).to_f
61
+ $vertex[p].z = 0
62
+
63
+ if((x%4<2)^(y%4<2))
64
+ $vertex[p].r = 0.0
65
+ else
66
+ $vertex[p].r = 1.0
67
+ end
68
+ $vertex[p].g = y.to_f / GRIDH.to_f
69
+ $vertex[p].b = 1.0 -(x.to_f/GRIDW.to_f + y.to_f/GRIDH.to_f)/2.0
70
+ end
71
+ end
72
+
73
+ QUADH.times do |y|
74
+ QUADW.times do |x|
75
+ p = 4*(y*QUADW + x)
76
+
77
+ # first quad
78
+ $quad[p+0] = y * GRIDW+x # some point
79
+ $quad[p+1] = y * GRIDW+x+1 # neighbor at the right side
80
+ $quad[p+2] = (y+1) * GRIDW+x+1 # upper right neighbor
81
+ $quad[p+3] = (y+1) * GRIDW+x # upper neighbor
82
+ end
83
+ end
84
+ end
85
+
86
+ $dt = 0
87
+ $p = Array.new(GRIDW).collect {Array.new(GRIDH,0.0)} # 2d array
88
+ $vx = Array.new(GRIDW).collect {Array.new(GRIDH,0.0)}
89
+ $vy = Array.new(GRIDW).collect {Array.new(GRIDH,0.0)}
90
+ $ax = Array.new(GRIDW).collect {Array.new(GRIDH,0.0)}
91
+ $ay = Array.new(GRIDW).collect {Array.new(GRIDH,0.0)}
92
+
93
+ def initSurface
94
+ GRIDH.times do |y|
95
+ GRIDW.times do |x|
96
+ dx = (x-GRIDW/2).to_f
97
+ dy = (y-GRIDH/2).to_f
98
+ d = sqrt(dx*dx + dy*dy)
99
+ if (d < 0.1 * (GRIDW/2).to_f)
100
+ d = d * 10.0
101
+ $p[x][y] = -cos(d * (PI / (GRIDW * 4).to_f)) * 100.0
102
+ else
103
+ $p[x][y] = 0.0
104
+ end
105
+ $vx[x][y] = 0.0
106
+ $vy[x][y] = 0.0
107
+ end
108
+ end
109
+ end
110
+
111
+ # Draw view
112
+ def draw_screen
113
+ # Clear the color and depth buffers.
114
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
115
+
116
+ # We don't want to modify the projection matrix.
117
+ glMatrixMode(GL_MODELVIEW)
118
+ glLoadIdentity()
119
+
120
+ # Move back.
121
+ glTranslatef(0.0, 0.0, -$zoom)
122
+ # Rotate the view
123
+ glRotatef($beta, 1.0, 0.0, 0.0)
124
+ glRotatef($alpha, 0.0, 0.0, 1.0)
125
+
126
+ glBegin(GL_QUADS)
127
+ $quad.each do |q|
128
+ v = $vertex[q]
129
+ glColor3f(v.r,v.g,v.b)
130
+ glVertex3f(v.x,v.y,v.z)
131
+ end
132
+ glEnd()
133
+
134
+ glfwSwapBuffers()
135
+ end
136
+
137
+ # Initialize OpenGL
138
+ def setup_opengl
139
+ # Our shading model--Gouraud (smooth).
140
+ glShadeModel(GL_SMOOTH)
141
+
142
+ # Switch on the z-buffer.
143
+ glEnable(GL_DEPTH_TEST)
144
+
145
+ glEnableClientState(GL_VERTEX_ARRAY)
146
+ glEnableClientState(GL_COLOR_ARRAY)
147
+ glPointSize(2.0)
148
+
149
+ # Background color is black.
150
+ glClearColor(0, 0, 0, 0)
151
+ end
152
+
153
+ # Modify the height of each vertex according to the pressure.
154
+ def adjustGrid
155
+ GRIDH.times do |y|
156
+ GRIDW.times do |x|
157
+ pos = y * GRIDW + x
158
+ $vertex[pos].z = ($p[x][y]*(1.0/50.0)).to_f
159
+ end
160
+ end
161
+ end
162
+
163
+ # Calculate wave propagation
164
+ def calc
165
+ time_step = $dt * ANIMATION_SPEED
166
+
167
+ # compute accelerations
168
+ GRIDW.times do |x|
169
+ x2 = (x + 1) % GRIDW
170
+ GRIDH.times do |y|
171
+ $ax[x][y] = $p[x][y] - $p[x2][y]
172
+ end
173
+ end
174
+
175
+ GRIDH.times do |y|
176
+ y2 = (y + 1) % GRIDH
177
+ GRIDW.times do |x|
178
+ $ay[x][y] = $p[x][y] - $p[x][y2]
179
+ end
180
+ end
181
+
182
+ # compute speeds
183
+ GRIDW.times do |x|
184
+ GRIDH.times do |y|
185
+ $vx[x][y] = $vx[x][y] + $ax[x][y] * time_step
186
+ $vy[x][y] = $vy[x][y] + $ay[x][y] * time_step
187
+ end
188
+ end
189
+
190
+ # compute pressure
191
+ GRIDW.times do |x|
192
+ x2 = x - 1
193
+ GRIDH.times do |y|
194
+ y2 = y - 1
195
+ $p[x][y] = $p[x][y] + ($vx[x2][y] - $vx[x][y] + $vy[x][y2] - $vy[x][y]) * time_step
196
+ end
197
+ end
198
+ end
199
+
200
+ # Handle key strokes
201
+ handle_key_down = lambda do |key,action|
202
+ if (action != GLFW_PRESS)
203
+ next
204
+ end
205
+
206
+ case key
207
+ when GLFW_KEY_ESC: $running = false
208
+ when GLFW_KEY_SPACE: initSurface()
209
+ when GLFW_KEY_LEFT: $alpha += 5
210
+ when GLFW_KEY_RIGHT: $alpha -= 5
211
+ when GLFW_KEY_UP: $beta -= 5
212
+ when GLFW_KEY_DOWN: $beta += 5
213
+ when GLFW_KEY_PAGEUP: $zoom -= 1 if $zoom > 1
214
+ when GLFW_KEY_PAGEDOWN: $zoom += 1
215
+ end
216
+ end
217
+
218
+ # Callback function for window resize events
219
+ handle_resize = lambda do |width,height|
220
+ ratio = 1.0
221
+
222
+ if ( height > 0 )
223
+ ratio = width.to_f / height.to_f
224
+ end
225
+
226
+ # Setup viewport (Place where the stuff will appear in the main window).
227
+ glViewport(0, 0, width, height)
228
+
229
+ # Change to the projection matrix and set
230
+ # our viewing volume.
231
+ glMatrixMode(GL_PROJECTION)
232
+ glLoadIdentity()
233
+ gluPerspective(60.0, ratio, 1.0, 1024.0)
234
+ end
235
+
236
+ # Program entry point
237
+ width = 640
238
+ height = 480
239
+ mode = GLFW_WINDOW
240
+
241
+ # Open window */
242
+ if( glfwOpenWindow(width,height,0,0,0,0,16,0,mode) == false )
243
+ puts "Could not open window"
244
+ exit
245
+ end
246
+
247
+ # Set title
248
+ glfwSetWindowTitle( "Wave Simulation" )
249
+
250
+ # Keyboard handler
251
+ glfwSetKeyCallback( handle_key_down )
252
+ glfwEnable( GLFW_KEY_REPEAT )
253
+
254
+ # Window resize handler
255
+ glfwSetWindowSizeCallback( handle_resize )
256
+
257
+
258
+ # Initialize OpenGL
259
+ setup_opengl()
260
+
261
+ # Initialize simulation
262
+ initVertices()
263
+ initSurface()
264
+ adjustGrid()
265
+
266
+ # Initialize timer
267
+ t_old = glfwGetTime() - 0.01
268
+
269
+ # Main loop
270
+ while $running
271
+ # Timing
272
+ t = glfwGetTime()
273
+ dt_total = t - t_old
274
+ t_old = t
275
+
276
+ # Safety - iterate if dt_total is too large
277
+ while( dt_total > 0.0 )
278
+ # Select iteration time step
279
+ $dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total
280
+ dt_total -= $dt
281
+
282
+ # Calculate wave propagation
283
+ calc()
284
+ end
285
+
286
+ # Compute height of each vertex
287
+ adjustGrid()
288
+
289
+ # Draw wave grid to OpenGL display
290
+ draw_screen()
291
+
292
+ # Still running?
293
+ $running = $running && glfwGetWindowParam( GLFW_OPENED )
294
+ end
@@ -0,0 +1,1094 @@
1
+ /*
2
+ Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
3
+
4
+ This software is provided 'as-is', without any express or implied
5
+ warranty. In no event will the authors be held liable for any damages
6
+ arising from the use of this software.
7
+
8
+ Permission is granted to anyone to use this software for any purpose,
9
+ including commercial applications, and to alter it and redistribute it
10
+ freely, subject to the following restrictions:
11
+
12
+ 1. The origin of this software must not be misrepresented; you must not
13
+ claim that you wrote the original software. If you use this software
14
+ in a product, an acknowledgment in the product documentation would be
15
+ appreciated but is not required.
16
+
17
+ 2. Altered source versions must be plainly marked as such, and must not be
18
+ misrepresented as being the original software.
19
+
20
+ 3. This notice may not be removed or altered from any source distribution.
21
+ */
22
+
23
+ #include <ruby.h>
24
+ #include <GL/glfw.h>
25
+
26
+ #ifdef WIN32
27
+ #define DLLEXPORT __declspec(dllexport)
28
+ #else
29
+ #define DLLEXPORT
30
+ #endif
31
+
32
+ #define MAGIC 256
33
+
34
+ static VALUE module;
35
+ static int call_id; /* internal ruby id for method 'call' */
36
+
37
+ #define GLFW_SET_CALLBACK_FUNC(_name_) \
38
+ static VALUE glfw_Set##_name_##Callback(VALUE obj,VALUE arg1) \
39
+ { \
40
+ if (!rb_obj_is_kind_of(arg1,rb_cProc) && !NIL_P(arg1)) \
41
+ rb_raise(rb_eTypeError, "need Proc object as argument"); \
42
+ \
43
+ if (NIL_P(arg1)) { \
44
+ _name_##_cb_ruby_func = Qnil; \
45
+ glfwSet##_name_##Callback(NULL); \
46
+ } else { \
47
+ _name_##_cb_ruby_func = arg1; \
48
+ glfwSet##_name_##Callback(_name_##_cb); \
49
+ } \
50
+ \
51
+ return Qnil; \
52
+ }
53
+
54
+ #define GL_BOOL_TO_RUBY_BOOL(x) x == GL_TRUE ? Qtrue : Qfalse
55
+ #define RUBY_BOOL_TO_GL_BOOL_INT(x) x == Qtrue ? GL_TRUE : (x == Qfalse ? GL_FALSE : NUM2INT(x))
56
+
57
+ /* API ref section 3.1 */
58
+
59
+ /* Initializes GLFW library. This function is called automatically on module load */
60
+
61
+ static VALUE glfw_Init(VALUE obj)
62
+ {
63
+ /* no-op, initialized at module load */
64
+ return Qtrue;
65
+ }
66
+
67
+ /* Terminates GLFW library. This function is called automatically on program exit */
68
+
69
+ static VALUE glfw_Terminate(VALUE obj)
70
+ {
71
+ glfwTerminate();
72
+ return Qnil;
73
+ }
74
+
75
+ /*
76
+ * call-seq:
77
+ * glfwGetVersion() => [major,minor,revision]
78
+ *
79
+ * Returns GLFW library version
80
+ */
81
+ static VALUE glfw_GetVersion(VALUE obj)
82
+ {
83
+ int major = 0;
84
+ int minor = 0;
85
+ int rev = 0;
86
+ glfwGetVersion(&major,&minor,&rev);
87
+ return rb_ary_new3(3,INT2NUM(major),INT2NUM(minor),INT2NUM(rev));
88
+ }
89
+
90
+ /* API ref section 3.2 */
91
+
92
+ /*
93
+ * call-seq:
94
+ * glfwOpenWindow(width,height,redbits,greenbits,bluebits,alphabits,depthbits,stencilbits,mode) => true/false
95
+ *
96
+ * Opens GLFW window, returns true on success
97
+ */
98
+ static VALUE glfw_OpenWindow(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
99
+ VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9;
100
+ {
101
+ int ret;
102
+
103
+ ret = glfwOpenWindow(NUM2INT(arg1),NUM2INT(arg2),NUM2INT(arg3),NUM2INT(arg4),NUM2INT(arg5),
104
+ NUM2INT(arg6),NUM2INT(arg7),NUM2INT(arg8),NUM2INT(arg9));
105
+ return GL_BOOL_TO_RUBY_BOOL(ret);
106
+ }
107
+
108
+ /*
109
+ * call-seq:
110
+ * glfwOpenWindowHint(target,hint)
111
+ *
112
+ * Sets additional properties for yet to be opened window
113
+ */
114
+ static VALUE glfw_OpenWindowHint(obj,arg1,arg2)
115
+ VALUE obj,arg1,arg2;
116
+ {
117
+ glfwOpenWindowHint(NUM2INT(arg1),RUBY_BOOL_TO_GL_BOOL_INT(arg2));
118
+ return Qnil;
119
+ }
120
+
121
+ /* Closes window */
122
+ static VALUE glfw_CloseWindow(VALUE obj)
123
+ {
124
+ glfwCloseWindow();
125
+ return Qnil;
126
+ }
127
+
128
+ static VALUE WindowClose_cb_ruby_func = Qnil;
129
+ int GLFWCALL WindowClose_cb(void)
130
+ {
131
+ int ret;
132
+ ret = rb_funcall(WindowClose_cb_ruby_func,call_id,0);
133
+ return RUBY_BOOL_TO_GL_BOOL_INT(ret);
134
+ }
135
+ GLFW_SET_CALLBACK_FUNC(WindowClose)
136
+
137
+ /*
138
+ * call-seq:
139
+ * glfwSetWindowTitle(title)
140
+ *
141
+ * Sets window title
142
+ */
143
+ static VALUE glfw_SetWindowTitle(obj,arg1)
144
+ VALUE obj,arg1;
145
+ {
146
+ Check_Type(arg1,T_STRING);
147
+ glfwSetWindowTitle(RSTRING(arg1)->ptr);
148
+ return Qnil;
149
+ }
150
+
151
+ /*
152
+ * call-seq:
153
+ * glfwSetWindowSize(width,height)
154
+ *
155
+ * Sets window size
156
+ */
157
+ static VALUE glfw_SetWindowSize(obj,arg1,arg2)
158
+ VALUE obj,arg1,arg2;
159
+ {
160
+ glfwSetWindowSize(NUM2INT(arg1),NUM2INT(arg2));
161
+ return Qnil;
162
+ }
163
+
164
+ /*
165
+ * call-seq:
166
+ * glfwSetWindowPos(x,y)
167
+ *
168
+ * Sets window position
169
+ */
170
+ static VALUE glfw_SetWindowPos(obj,arg1,arg2)
171
+ VALUE obj,arg1,arg2;
172
+ {
173
+ glfwSetWindowPos(NUM2INT(arg1),NUM2INT(arg2));
174
+ return Qnil;
175
+ }
176
+
177
+ /*
178
+ * call-seq:
179
+ * glfwGetWindowSize() => [width, height]
180
+ *
181
+ * Returns current window size
182
+ */
183
+ static VALUE glfw_GetWindowSize(VALUE obj)
184
+ {
185
+ int width=0;
186
+ int height=0;
187
+ glfwGetWindowSize(&width,&height);
188
+ return rb_ary_new3(2,INT2NUM(width),INT2NUM(height));
189
+ }
190
+
191
+ static VALUE WindowSize_cb_ruby_func = Qnil;
192
+ void GLFWCALL WindowSize_cb(int width, int height)
193
+ {
194
+ rb_funcall(WindowSize_cb_ruby_func,call_id,2,INT2NUM(width),INT2NUM(height));
195
+ }
196
+ GLFW_SET_CALLBACK_FUNC(WindowSize)
197
+
198
+ /* Iconifies window */
199
+ static VALUE glfw_IconifyWindow(VALUE obj)
200
+ {
201
+ glfwIconifyWindow();
202
+ return Qnil;
203
+ }
204
+
205
+ /* Restores window */
206
+ static VALUE glfw_RestoreWindow(VALUE obj)
207
+ {
208
+ glfwRestoreWindow();
209
+ return Qnil;
210
+ }
211
+
212
+ /*
213
+ * call-seq:
214
+ * glfwGetWindowParam(param) => Fixnum or true/false
215
+ *
216
+ * Returns value of window parameter 'param' , either as integer or boolean
217
+ */
218
+ static VALUE glfw_GetWindowParam(VALUE obj,VALUE arg1)
219
+ {
220
+ int param;
221
+ int ret;
222
+ param = NUM2INT(arg1);
223
+ ret = glfwGetWindowParam(param);
224
+
225
+ switch(param) {
226
+ case GLFW_OPENED:
227
+ case GLFW_ACTIVE:
228
+ case GLFW_ICONIFIED:
229
+ case GLFW_ACCELERATED:
230
+ case GLFW_STEREO:
231
+ case GLFW_WINDOW_NO_RESIZE:
232
+ return GL_BOOL_TO_RUBY_BOOL(ret);
233
+ default:
234
+ return INT2NUM(ret);
235
+ }
236
+ /* not reached */
237
+ }
238
+
239
+ /* Swaps OpenGL buffers in double-buffering mode */
240
+ static VALUE glfw_SwapBuffers(VALUE obj)
241
+ {
242
+ glfwSwapBuffers();
243
+ return Qnil;
244
+ }
245
+
246
+ /*
247
+ * call-seq:
248
+ * glfwSwapInterval(interval)
249
+ *
250
+ * Sets minimal number of monitor frame retraces before buffers can be swapped (a.k.a Vertical sync), 0 = off
251
+ */
252
+ static VALUE glfw_SwapInterval(VALUE obj,VALUE arg1)
253
+ {
254
+ glfwSwapInterval(NUM2INT(arg1));
255
+ return Qnil;
256
+ }
257
+
258
+ static VALUE WindowRefresh_cb_ruby_func = Qnil;
259
+ void GLFWCALL WindowRefresh_cb(void)
260
+ {
261
+ rb_funcall(WindowRefresh_cb_ruby_func,call_id,0);
262
+ }
263
+ GLFW_SET_CALLBACK_FUNC(WindowRefresh)
264
+
265
+ /* API ref section 3.3 */
266
+
267
+ static VALUE Vidmode_class = Qnil;
268
+
269
+ VALUE vidmode_to_ruby(GLFWvidmode vm)
270
+ {
271
+ VALUE vm_r;
272
+
273
+ if (Vidmode_class==Qnil)
274
+ Vidmode_class = rb_eval_string("Struct.new('Vidmode', :Width,:Height,:RedBits,:GreenBits,:BlueBits)");
275
+
276
+ vm_r = rb_funcall(Vidmode_class,rb_intern("new"),5,
277
+ INT2NUM(vm.Width),INT2NUM(vm.Height),
278
+ INT2NUM(vm.RedBits),INT2NUM(vm.GreenBits),INT2NUM(vm.BlueBits) );
279
+ return vm_r;
280
+ }
281
+
282
+ /*
283
+ * call-seq:
284
+ * glfwGetVideoModes() => [Vidmode,...]
285
+ *
286
+ * Returns all supported video modes in form of array of instances of Vidmode class
287
+ *
288
+ * Vidmode class has following attributes:
289
+ * * Width - screen width
290
+ * * Height - screen height
291
+ * * Redbits - number of bits per red channel
292
+ * * GreenBits - number of bits per green channel
293
+ * * BlueBits - number of bits per blue channel
294
+ *
295
+ * BPP = Redbits + GreenBits + BlueBits
296
+ */
297
+ static VALUE glfw_GetVideoModes(VALUE obj)
298
+ {
299
+ GLFWvidmode modes[MAGIC];
300
+ int count;
301
+ int i;
302
+ VALUE ret;
303
+
304
+ count = glfwGetVideoModes(modes,MAGIC);
305
+ ret = rb_ary_new2(count);
306
+ for(i=0;i<count;++i)
307
+ rb_ary_push(ret,vidmode_to_ruby(modes[i]));
308
+
309
+ return ret;
310
+ }
311
+
312
+ /*
313
+ * call-seq:
314
+ * glfwGetDesktopMode() => Vidmode
315
+ *
316
+ * Returns current desktop mode in form of instance of Vidmode class - see glfwGetVideoModes for details.
317
+ */
318
+ static VALUE glfw_GetDesktopMode(VALUE obj)
319
+ {
320
+ GLFWvidmode vm;
321
+ glfwGetDesktopMode(&vm);
322
+ return vidmode_to_ruby(vm);
323
+ }
324
+
325
+ /* API ref section 3.4 */
326
+
327
+ /* Polls events */
328
+ static VALUE glfw_PollEvents(VALUE obj)
329
+ {
330
+ glfwPollEvents();
331
+ return Qnil;
332
+ }
333
+
334
+ /* Waits for events */
335
+ static VALUE glfw_WaitEvents(VALUE obj)
336
+ {
337
+ glfwWaitEvents();
338
+ return Qnil;
339
+ }
340
+
341
+ /*
342
+ * call-seq:
343
+ * glfwGetKey(key) => GLFW_PRESS/GLFW_RELEASE
344
+ *
345
+ * Queries status of key 'key'
346
+ */
347
+ static VALUE glfw_GetKey(VALUE obj,VALUE arg1)
348
+ {
349
+ int ret;
350
+ ret = glfwGetKey(NUM2INT(arg1));
351
+ return INT2NUM(ret);
352
+ }
353
+
354
+
355
+ /*
356
+ * call-seq:
357
+ * glfwGetMouseButton(button) => GLFW_PRESS/GLFW_RELEASE
358
+ *
359
+ * Queries status of mouse button 'button'
360
+ */
361
+ static VALUE glfw_GetMouseButton(VALUE obj,VALUE arg1)
362
+ {
363
+ int ret;
364
+ ret = glfwGetMouseButton(NUM2INT(arg1));
365
+ return INT2NUM(ret);
366
+ }
367
+
368
+ /*
369
+ * call-seq:
370
+ * glfwGetMousePos() => [xpos,ypos]
371
+ *
372
+ * Returns current mouse position
373
+ */
374
+ static VALUE glfw_GetMousePos(VALUE obj)
375
+ {
376
+ int xpos=0;
377
+ int ypos=0;
378
+ glfwGetMousePos(&xpos,&ypos);
379
+ return rb_ary_new3(2,INT2NUM(xpos),INT2NUM(ypos));
380
+ }
381
+
382
+ /*
383
+ * call-seq:
384
+ * glfwSetMousePos(xpos,ypos)
385
+ *
386
+ * Sets mouse position
387
+ */
388
+ static VALUE glfw_SetMousePos(obj,arg1,arg2)
389
+ VALUE obj,arg1,arg2;
390
+ {
391
+ glfwSetMousePos(NUM2INT(arg1),NUM2INT(arg2));
392
+ return Qnil;
393
+ }
394
+
395
+ /*
396
+ * call-seq:
397
+ * glfwGetMouseWheel() => wheelpos
398
+ *
399
+ * Returns current mouse wheel position
400
+ */
401
+ static VALUE glfw_GetMouseWheel(VALUE obj)
402
+ {
403
+ int ret;
404
+ ret = glfwGetMouseWheel();
405
+ return INT2NUM(ret);
406
+ }
407
+
408
+ /*
409
+ * call-seq:
410
+ * glfwSetMouseWheelPos(wheelpos)
411
+ *
412
+ * Sets mouse wheel position
413
+ */
414
+ static VALUE glfw_SetMouseWheel(VALUE obj,VALUE arg1)
415
+ {
416
+ glfwSetMouseWheel(NUM2INT(arg1));
417
+ return Qnil;
418
+ }
419
+
420
+ /*
421
+ * call-seq:
422
+ * glfwGetJoystickPos(joystick) => [axis_0_pos, axis_1_pos, ...]
423
+ *
424
+ * Returns joystick axes positions or nil if given joystick is not present
425
+ */
426
+ static VALUE glfw_GetJoystickPos(VALUE obj,VALUE arg1)
427
+ {
428
+ float *pos;
429
+ int numaxes;
430
+ int count;
431
+ int i;
432
+ VALUE ret;
433
+
434
+ numaxes = glfwGetJoystickParam(NUM2INT(arg1),GLFW_AXES);
435
+ if (numaxes<=0)
436
+ return Qnil;
437
+
438
+ pos = ALLOC_N(float,numaxes);
439
+ count = glfwGetJoystickPos(NUM2INT(arg1),pos,numaxes);
440
+ ret = rb_ary_new2(count);
441
+ for(i=0;i<count;++i)
442
+ rb_ary_push(ret,rb_float_new(pos[i]));
443
+ xfree(pos);
444
+ return ret;
445
+ }
446
+
447
+ /*
448
+ * call-seq:
449
+ * glfwGetJoystickButtons(joystick) => [button_0_state, button_1_state, ...]
450
+ *
451
+ * Returns joystick button states (which are either GLFW_PRESS or GLFW_RELEASE) or nil if given joystick is not present
452
+ */
453
+ static VALUE glfw_GetJoystickButtons(VALUE obj,VALUE arg1)
454
+ {
455
+ unsigned char *buttons;
456
+ int numbuttons;
457
+ int count;
458
+ int i;
459
+ VALUE ret;
460
+
461
+ numbuttons = glfwGetJoystickParam(NUM2INT(arg1),GLFW_BUTTONS);
462
+ if (numbuttons<=0)
463
+ return Qnil;
464
+
465
+ buttons = ALLOC_N(unsigned char,numbuttons);
466
+ count = glfwGetJoystickButtons(NUM2INT(arg1),buttons,numbuttons);
467
+ ret = rb_ary_new2(count);
468
+ for(i=0;i<count;++i)
469
+ rb_ary_push(ret,INT2NUM(buttons[i]));
470
+ xfree(buttons);
471
+ return ret;
472
+ }
473
+
474
+ static VALUE Key_cb_ruby_func = Qnil;
475
+ void GLFWCALL Key_cb(int key, int action)
476
+ {
477
+ rb_funcall(Key_cb_ruby_func,call_id,2,INT2NUM(key),INT2NUM(action));
478
+ }
479
+ GLFW_SET_CALLBACK_FUNC(Key)
480
+
481
+ static VALUE Char_cb_ruby_func = Qnil;
482
+ void GLFWCALL Char_cb(int character, int action)
483
+ {
484
+ rb_funcall(Char_cb_ruby_func,call_id,2,INT2NUM(character),INT2NUM(action));
485
+ }
486
+ GLFW_SET_CALLBACK_FUNC(Char)
487
+
488
+ static VALUE MouseButton_cb_ruby_func = Qnil;
489
+ void GLFWCALL MouseButton_cb(int button, int action)
490
+ {
491
+ rb_funcall(MouseButton_cb_ruby_func,call_id,2,INT2NUM(button),INT2NUM(action));
492
+ }
493
+ GLFW_SET_CALLBACK_FUNC(MouseButton)
494
+
495
+ static VALUE MousePos_cb_ruby_func = Qnil;
496
+ void GLFWCALL MousePos_cb(int x, int y)
497
+ {
498
+ rb_funcall(MousePos_cb_ruby_func,call_id,2,INT2NUM(x),INT2NUM(y));
499
+ }
500
+ GLFW_SET_CALLBACK_FUNC(MousePos)
501
+
502
+ static VALUE MouseWheel_cb_ruby_func = Qnil;
503
+ void GLFWCALL MouseWheel_cb(int pos)
504
+ {
505
+ rb_funcall(MouseWheel_cb_ruby_func,call_id,1,INT2NUM(pos));
506
+ }
507
+ GLFW_SET_CALLBACK_FUNC(MouseWheel)
508
+
509
+
510
+ /*
511
+ * call-seq:
512
+ * glfwGetJoystickParam(joystick,param) => value or true/false
513
+ *
514
+ * Queries joystick parameters
515
+ */
516
+ static VALUE glfw_GetJoystickParam(obj,arg1,arg2)
517
+ VALUE obj,arg1,arg2;
518
+ {
519
+ int param;
520
+ int ret;
521
+ param = NUM2INT(arg2);
522
+ ret = glfwGetJoystickParam(NUM2INT(arg1),NUM2INT(arg2));
523
+ if (param==GLFW_PRESENT)
524
+ return GL_BOOL_TO_RUBY_BOOL(ret);
525
+ else
526
+ return INT2NUM(ret);
527
+ }
528
+
529
+ /* API ref section 3.5 */
530
+
531
+ /*
532
+ * call-seq:
533
+ * glfwGetTime() => Float
534
+ *
535
+ * Returns time (as Float) passed since last call to glfwInit or glfwSetTime
536
+ */
537
+ static VALUE glfw_GetTime(VALUE obj)
538
+ {
539
+ double time;
540
+ time = glfwGetTime();
541
+ return rb_float_new(time);
542
+ }
543
+
544
+ /*
545
+ * call-seq:
546
+ * glfwSetTime(time)
547
+ *
548
+ * Sets timer to given time (Float)
549
+ */
550
+ static VALUE glfw_SetTime(VALUE obj,VALUE arg1)
551
+ {
552
+ glfwSetTime(NUM2DBL(arg1));
553
+ return Qnil;
554
+ }
555
+
556
+ /*
557
+ * call-seq:
558
+ * glfwSleep(time)
559
+ *
560
+ * Sleeps for given amount of time (Float)
561
+ */
562
+ static VALUE glfw_Sleep(VALUE obj,VALUE arg1)
563
+ {
564
+ glfwSleep(NUM2DBL(arg1));
565
+ return Qnil;
566
+ }
567
+
568
+ /* API ref section 3.6 */
569
+
570
+ VALUE GLFWimage_class; /* GLFWimage class */
571
+
572
+ void GLFWimage_free(void *p)
573
+ {
574
+ if (p) {
575
+ glfwFreeImage((GLFWimage *)p);
576
+ xfree(p);
577
+ }
578
+ }
579
+
580
+ /* Returns width of the image */
581
+ static VALUE GLFWimage_width(VALUE obj)
582
+ {
583
+ GLFWimage *img;
584
+ Data_Get_Struct(obj,GLFWimage,img);
585
+ return INT2NUM(img->Width);
586
+ }
587
+
588
+ /* Returns height of the image */
589
+ static VALUE GLFWimage_height(VALUE obj)
590
+ {
591
+ GLFWimage *img;
592
+ Data_Get_Struct(obj,GLFWimage,img);
593
+ return INT2NUM(img->Height);
594
+ }
595
+
596
+ /* Returns OpenGL format of the image (GL_RGB, GL_LUMINANCE etc.) */
597
+ static VALUE GLFWimage_format(VALUE obj)
598
+ {
599
+ GLFWimage *img;
600
+ Data_Get_Struct(obj,GLFWimage,img);
601
+ return INT2NUM(img->Format);
602
+ }
603
+
604
+ /* Returns number of bytes per pixel for the image */
605
+ static VALUE GLFWimage_BPP(VALUE obj)
606
+ {
607
+ GLFWimage *img;
608
+ Data_Get_Struct(obj,GLFWimage,img);
609
+ return INT2NUM(img->BytesPerPixel);
610
+ }
611
+
612
+ /*
613
+ * call-seq:
614
+ * glfwReadImage(filename, flags) => GLFWimage or nil
615
+ *
616
+ * Reads image from file and stores it as GLFWimage object
617
+ */
618
+ static VALUE glfw_ReadImage(obj,arg1,arg2)
619
+ VALUE obj,arg1,arg2;
620
+ {
621
+ GLFWimage *img;
622
+ int ret;
623
+
624
+ Check_Type(arg1,T_STRING);
625
+ img = ALLOC(GLFWimage);
626
+ ret = glfwReadImage(RSTRING(arg1)->ptr,img,NUM2INT(arg2));
627
+ if (ret==GL_FALSE) {
628
+ xfree(img);
629
+ return Qnil;
630
+ }
631
+ return Data_Wrap_Struct(GLFWimage_class,0,GLFWimage_free,img);
632
+ }
633
+
634
+ /*
635
+ * call-seq:
636
+ * glfwReadMemoryImage(string, flags) => GLFWimage or nil
637
+ *
638
+ * Reads image from string (containing raw image data) and stores it as GLFWimage object
639
+ */
640
+ static VALUE glfw_ReadMemoryImage(obj,arg1,arg2)
641
+ VALUE obj,arg1,arg2;
642
+ {
643
+ GLFWimage *img;
644
+ int ret;
645
+
646
+ Check_Type(arg1,T_STRING);
647
+ img = ALLOC(GLFWimage);
648
+ ret = glfwReadMemoryImage(RSTRING(arg1)->ptr,RSTRING(arg1)->len,img,NUM2INT(arg2));
649
+ if (ret==GL_FALSE) {
650
+ xfree(img);
651
+ return Qnil;
652
+ }
653
+ return Data_Wrap_Struct(GLFWimage_class,0,GLFWimage_free,img);
654
+ }
655
+
656
+ /*
657
+ * call-seq:
658
+ * glfwFreeImage(GLFWimage)
659
+ *
660
+ * Frees data in GLFWimage object and marks it for deletion.
661
+ */
662
+ static VALUE glfw_FreeImage(VALUE obj,VALUE arg1)
663
+ {
664
+ GLFWimage *img;
665
+ Data_Get_Struct(arg1, GLFWimage, img);
666
+ glfwFreeImage(img);
667
+ return Qnil;
668
+ }
669
+
670
+ /*
671
+ * call-seq:
672
+ * glfwLoadTexture2D(filename,flags) => true or false
673
+ *
674
+ * Reads image from file and loads it as texture to current texturing unit
675
+ */
676
+ static VALUE glfw_LoadTexture2D(obj,arg1,arg2)
677
+ VALUE obj,arg1,arg2;
678
+ {
679
+ int ret;
680
+ Check_Type(arg1,T_STRING);
681
+ ret = glfwLoadTexture2D(RSTRING(arg1)->ptr,NUM2INT(arg2));
682
+ return GL_BOOL_TO_RUBY_BOOL(ret);
683
+ }
684
+
685
+ /*
686
+ * call-seq:
687
+ * glfwLoadMemoryTexture2D(string,flags) => true or false
688
+ *
689
+ * Reads raw image data from string and loads it as texture to current texturing unit
690
+ */
691
+ static VALUE glfw_LoadMemoryTexture2D(obj,arg1,arg2)
692
+ VALUE obj,arg1,arg2;
693
+ {
694
+ int ret;
695
+ Check_Type(arg1,T_STRING);
696
+ ret = glfwLoadMemoryTexture2D(RSTRING(arg1)->ptr,RSTRING(arg1)->len,NUM2INT(arg2));
697
+ return GL_BOOL_TO_RUBY_BOOL(ret);
698
+ }
699
+
700
+ /*
701
+ * call-seq:
702
+ * glfwLoadTextureImage2D(GLFWimage,flags) => true or false
703
+ *
704
+ * Reads image from GLFWimage object and loads it as texture to current texturing unit
705
+ */
706
+ static VALUE glfw_LoadTextureImage2D(obj,arg1,arg2)
707
+ VALUE obj,arg1,arg2;
708
+ {
709
+ int ret;
710
+ GLFWimage *img;
711
+ Data_Get_Struct(arg1, GLFWimage, img);
712
+ ret = glfwLoadTextureImage2D(img,NUM2INT(arg2));
713
+ return GL_BOOL_TO_RUBY_BOOL(ret);
714
+ }
715
+
716
+ /* API ref section 3.7 */
717
+
718
+ /*
719
+ * call-seq:
720
+ * glfwExtensionSupported(extension_name) => true/false
721
+ *
722
+ * Is given OpenGL extension supported ?
723
+ */
724
+ static VALUE glfw_ExtensionSupported(VALUE obj,VALUE arg1)
725
+ {
726
+ int ret;
727
+ Check_Type(arg1,T_STRING);
728
+ ret = glfwExtensionSupported(RSTRING(arg1)->ptr);
729
+ return GL_BOOL_TO_RUBY_BOOL(ret);
730
+ }
731
+
732
+ /* NOTE: glfwGetProcAddress not implemented, use ruby-opengl functions instead */
733
+
734
+ /*
735
+ * call-seq:
736
+ * glfwGetGLVersion() => [major,minor,revision]
737
+ *
738
+ * Returns installed OpenGL version
739
+ */
740
+ static VALUE glfw_GetGLVersion(VALUE obj)
741
+ {
742
+ int major = 0;
743
+ int minor = 0;
744
+ int rev = 0;
745
+ glfwGetGLVersion(&major,&minor,&rev);
746
+ return rb_ary_new3(3,INT2NUM(major),INT2NUM(minor),INT2NUM(rev));
747
+ }
748
+
749
+ /* API ref section 3.8-3.10
750
+ NOTE: GLFW Threads not implemented as ruby has its own threading */
751
+
752
+ /* API ref section 3.11 */
753
+
754
+ /*
755
+ * call-seq:
756
+ * glfwEnable(feature)
757
+ *
758
+ * Enables certain GLFW feature
759
+ */
760
+ static VALUE glfw_Enable(VALUE obj,VALUE arg1)
761
+ {
762
+ glfwEnable(NUM2INT(arg1));
763
+ return Qnil;
764
+ }
765
+
766
+ /*
767
+ * call-seq:
768
+ * glfwDisable(feature)
769
+ *
770
+ * Disables certain GLFW feature
771
+ */
772
+ static VALUE glfw_Disable(VALUE obj,VALUE arg1)
773
+ {
774
+ glfwDisable(NUM2INT(arg1));
775
+ return Qnil;
776
+ }
777
+
778
+ /* call-seq:
779
+ * glfwGetNumberOfProcessors() => Fixnum
780
+ *
781
+ * Returns current number of logical processors (or cores)
782
+ */
783
+ static VALUE glfw_GetNumberOfProcessors(VALUE obj)
784
+ {
785
+ int ret;
786
+ ret = glfwGetNumberOfProcessors();
787
+ return INT2NUM(ret);
788
+ }
789
+
790
+ /* Hack for RDOC */
791
+ #if 0
792
+ /*
793
+ * call-seq:
794
+ * glfwSetWindowCloseCallback( Proc() => true/false )
795
+ *
796
+ * Sets function to be executed at window close. The supplied function takes no parameters, and
797
+ * should return either true or false, indicating if the window should be closed.
798
+ */
799
+ VALUE glfw_SetWindowCloseCallback()
800
+ /*
801
+ * call-seq:
802
+ * glfwSetWindowSizeCallback( Proc(width,height) )
803
+ *
804
+ * Sets function to be executed at window size change. The supplied function takes two arguments,
805
+ * representing new width and height of the window
806
+ */
807
+ VALUE glfw_SetWindowSizeCallback()
808
+ /*
809
+ * call-seq:
810
+ * glfwSetWindowRefreshCallback( Proc() )
811
+ *
812
+ * Sets function to be executed at window refresh. The supplied function takes no arguments.
813
+ */
814
+ VALUE glfw_SetWindowRefreshCallback()
815
+ /*
816
+ * call-seq:
817
+ * glfwSetKeyCallback( Proc(key,action) )
818
+ *
819
+ * Sets function to be executed at key press or release. The supplied function takes two arguments,
820
+ * key and action, where action is either GLFW_PRESS or GLFW_RELEASE
821
+ */
822
+ VALUE glfw_SetKeyCallback()
823
+ /*
824
+ * call-seq:
825
+ * glfwSetCharCallback( Proc(char,action) )
826
+ *
827
+ * Sets function to be executed every time printable character is generated by the keyboard.
828
+ * The supplied function takes two arguments, char and action, where char is unicode character,
829
+ * and action is either GLFW_PRESS or GLFW_RELEASE
830
+ */
831
+ VALUE glfw_SetCharCallback()
832
+ /*
833
+ * call-seq:
834
+ * glfwSetMouseButtonCallback( Proc(button,action) )
835
+ *
836
+ * Sets function to be executed at mouse button press or release. The supplied function takes two
837
+ * arguments, button and action, where action is either GLFW_PRESS or GLFW_RELEASE
838
+ */
839
+ VALUE glfw_SetMouseButtonCallback()
840
+ /*
841
+ * call-seq:
842
+ * glfwSetMousePosCallback( Proc(xpos,ypos) )
843
+ *
844
+ * Sets function to be executed at mouse movement. The supplied function takes two arguments,
845
+ * representing the new mouse coordinates x and y
846
+ */
847
+ VALUE glfw_SetMousePosCallback()
848
+ /*
849
+ * call-seq:
850
+ * glfwSetMouseWheelCallback( Proc(wheelpos) )
851
+ *
852
+ * Sets function to be executed at mouse wheel movement. The supplied function takes one argument
853
+ * representing the new mouse wheel position
854
+ */
855
+ VALUE glfw_SetMouseWheelCallback()
856
+ #endif
857
+
858
+ DLLEXPORT void Init_glfw()
859
+ {
860
+ /* Let's initialize the GLFW library at module load */
861
+ if (glfwInit()!=GL_TRUE) {
862
+ rb_raise(rb_eRuntimeError, "GLFW library initialization failed");
863
+ /* not reached */
864
+ }
865
+
866
+ /* Glfw module - this module contains all functions and constants in the GLFW bindings */
867
+ module = rb_define_module("Glfw");
868
+
869
+ call_id = rb_intern("call");
870
+
871
+ /*
872
+ GLFWimage is class which instances contains image loaded by GLFW imaging API.
873
+
874
+ Image data can be manually freed by calling glfwFreeImage(object)
875
+ */
876
+ GLFWimage_class = rb_define_class("GLFWimage", rb_cObject);
877
+ rb_define_method(GLFWimage_class, "Width", GLFWimage_width, 0);
878
+ rb_define_method(GLFWimage_class, "Height", GLFWimage_height, 0);
879
+ rb_define_method(GLFWimage_class, "Format", GLFWimage_format, 0);
880
+ rb_define_method(GLFWimage_class, "BytesPerPixel", GLFWimage_BPP, 0);
881
+
882
+ /* register Vidmode struct class to garbage collector */
883
+ rb_gc_register_address(&Vidmode_class);
884
+
885
+ /* register callback handlers to garbage collector */
886
+ rb_gc_register_address(&WindowClose_cb_ruby_func);
887
+ rb_gc_register_address(&WindowSize_cb_ruby_func);
888
+ rb_gc_register_address(&WindowRefresh_cb_ruby_func);
889
+ rb_gc_register_address(&Key_cb_ruby_func);
890
+ rb_gc_register_address(&Char_cb_ruby_func);
891
+ rb_gc_register_address(&MouseButton_cb_ruby_func);
892
+ rb_gc_register_address(&MousePos_cb_ruby_func);
893
+ rb_gc_register_address(&MouseWheel_cb_ruby_func);
894
+
895
+ /* functions */
896
+ rb_define_module_function(module,"glfwInit", glfw_Init, 0);
897
+ rb_define_module_function(module,"glfwTerminate", glfw_Terminate, 0);
898
+ rb_define_module_function(module,"glfwGetVersion", glfw_GetVersion, 0);
899
+
900
+ rb_define_module_function(module,"glfwOpenWindow", glfw_OpenWindow, 9);
901
+ rb_define_module_function(module,"glfwOpenWindowHint", glfw_OpenWindowHint, 2);
902
+ rb_define_module_function(module,"glfwCloseWindow", glfw_CloseWindow, 0);
903
+ rb_define_module_function(module,"glfwSetWindowCloseCallback", glfw_SetWindowCloseCallback, 1);
904
+ rb_define_module_function(module,"glfwSetWindowTitle", glfw_SetWindowTitle, 1);
905
+ rb_define_module_function(module,"glfwSetWindowSize", glfw_SetWindowSize, 2);
906
+ rb_define_module_function(module,"glfwSetWindowPos", glfw_SetWindowPos, 2);
907
+ rb_define_module_function(module,"glfwGetWindowSize", glfw_GetWindowSize, 0);
908
+ rb_define_module_function(module,"glfwSetWindowSizeCallback", glfw_SetWindowSizeCallback, 1);
909
+ rb_define_module_function(module,"glfwIconifyWindow", glfw_IconifyWindow, 0);
910
+ rb_define_module_function(module,"glfwRestoreWindow", glfw_RestoreWindow, 0);
911
+ rb_define_module_function(module,"glfwGetWindowParam", glfw_GetWindowParam, 1);
912
+ rb_define_module_function(module,"glfwSwapBuffers", glfw_SwapBuffers, 0);
913
+ rb_define_module_function(module,"glfwSwapInterval", glfw_SwapInterval, 1);
914
+ rb_define_module_function(module,"glfwSetWindowRefreshCallback", glfw_SetWindowRefreshCallback, 1);
915
+
916
+ rb_define_module_function(module,"glfwGetVideoModes", glfw_GetVideoModes, 0);
917
+ rb_define_module_function(module,"glfwGetDesktopMode", glfw_GetDesktopMode, 0);
918
+
919
+ rb_define_module_function(module,"glfwPollEvents", glfw_PollEvents, 0);
920
+ rb_define_module_function(module,"glfwWaitEvents", glfw_WaitEvents, 0);
921
+ rb_define_module_function(module,"glfwGetKey", glfw_GetKey, 1);
922
+ rb_define_module_function(module,"glfwGetMouseButton", glfw_GetMouseButton, 1);
923
+ rb_define_module_function(module,"glfwGetMousePos", glfw_GetMousePos, 0);
924
+ rb_define_module_function(module,"glfwSetMousePos", glfw_SetMousePos, 2);
925
+ rb_define_module_function(module,"glfwGetMouseWheel", glfw_GetMouseWheel, 0);
926
+ rb_define_module_function(module,"glfwSetMouseWheel", glfw_SetMouseWheel, 1);
927
+ rb_define_module_function(module,"glfwSetKeyCallback", glfw_SetKeyCallback, 1);
928
+ rb_define_module_function(module,"glfwSetCharCallback", glfw_SetCharCallback, 1);
929
+ rb_define_module_function(module,"glfwSetMouseButtonCallback", glfw_SetMouseButtonCallback, 1);
930
+ rb_define_module_function(module,"glfwSetMousePosCallback", glfw_SetMousePosCallback, 1);
931
+ rb_define_module_function(module,"glfwSetMouseWheelCallback", glfw_SetMouseWheelCallback, 1);
932
+ rb_define_module_function(module,"glfwGetJoystickParam", glfw_GetJoystickParam, 2);
933
+ rb_define_module_function(module,"glfwGetJoystickPos", glfw_GetJoystickPos, 1);
934
+ rb_define_module_function(module,"glfwGetJoystickButtons", glfw_GetJoystickButtons, 1);
935
+
936
+ rb_define_module_function(module,"glfwGetTime", glfw_GetTime, 0);
937
+ rb_define_module_function(module,"glfwSetTime", glfw_SetTime, 1);
938
+ rb_define_module_function(module,"glfwSleep", glfw_Sleep, 1);
939
+
940
+ rb_define_module_function(module,"glfwReadImage", glfw_ReadImage, 2);
941
+ rb_define_module_function(module,"glfwReadMemoryImage", glfw_ReadMemoryImage, 2);
942
+ rb_define_module_function(module,"glfwFreeImage", glfw_FreeImage, 1);
943
+ rb_define_module_function(module,"glfwLoadTexture2D", glfw_LoadTexture2D, 2);
944
+ rb_define_module_function(module,"glfwLoadMemoryTexture2D", glfw_LoadMemoryTexture2D, 2);
945
+ rb_define_module_function(module,"glfwLoadTextureImage2D", glfw_LoadTextureImage2D, 2);
946
+
947
+ rb_define_module_function(module,"glfwExtensionSupported", glfw_ExtensionSupported, 1);
948
+ rb_define_module_function(module,"glfwGetGLVersion", glfw_GetGLVersion, 0);
949
+ rb_define_module_function(module,"glfwEnable", glfw_Enable, 1);
950
+ rb_define_module_function(module,"glfwDisable", glfw_Disable, 1);
951
+ rb_define_module_function(module,"glfwGetNumberOfProcessors", glfw_GetNumberOfProcessors, 0);
952
+
953
+ /* constants */
954
+ rb_define_const(module, "GLFW_VERSION_MAJOR", INT2NUM(GLFW_VERSION_MAJOR));
955
+ rb_define_const(module, "GLFW_VERSION_MINOR", INT2NUM(GLFW_VERSION_MINOR));
956
+ rb_define_const(module, "GLFW_VERSION_REVISION", INT2NUM(GLFW_VERSION_REVISION));
957
+ rb_define_const(module, "GLFW_RELEASE", INT2NUM(GLFW_RELEASE));
958
+ rb_define_const(module, "GLFW_PRESS", INT2NUM(GLFW_PRESS));
959
+ rb_define_const(module, "GLFW_KEY_UNKNOWN", INT2NUM(GLFW_KEY_UNKNOWN));
960
+ rb_define_const(module, "GLFW_KEY_SPACE", INT2NUM(GLFW_KEY_SPACE));
961
+ rb_define_const(module, "GLFW_KEY_SPECIAL", INT2NUM(GLFW_KEY_SPECIAL));
962
+ rb_define_const(module, "GLFW_KEY_ESC", INT2NUM(GLFW_KEY_ESC));
963
+ rb_define_const(module, "GLFW_KEY_F1", INT2NUM(GLFW_KEY_F1));
964
+ rb_define_const(module, "GLFW_KEY_F2", INT2NUM(GLFW_KEY_F2));
965
+ rb_define_const(module, "GLFW_KEY_F3", INT2NUM(GLFW_KEY_F3));
966
+ rb_define_const(module, "GLFW_KEY_F4", INT2NUM(GLFW_KEY_F4));
967
+ rb_define_const(module, "GLFW_KEY_F5", INT2NUM(GLFW_KEY_F5));
968
+ rb_define_const(module, "GLFW_KEY_F6", INT2NUM(GLFW_KEY_F6));
969
+ rb_define_const(module, "GLFW_KEY_F7", INT2NUM(GLFW_KEY_F7));
970
+ rb_define_const(module, "GLFW_KEY_F8", INT2NUM(GLFW_KEY_F8));
971
+ rb_define_const(module, "GLFW_KEY_F9", INT2NUM(GLFW_KEY_F9));
972
+ rb_define_const(module, "GLFW_KEY_F10", INT2NUM(GLFW_KEY_F10));
973
+ rb_define_const(module, "GLFW_KEY_F11", INT2NUM(GLFW_KEY_F11));
974
+ rb_define_const(module, "GLFW_KEY_F12", INT2NUM(GLFW_KEY_F12));
975
+ rb_define_const(module, "GLFW_KEY_F13", INT2NUM(GLFW_KEY_F13));
976
+ rb_define_const(module, "GLFW_KEY_F14", INT2NUM(GLFW_KEY_F14));
977
+ rb_define_const(module, "GLFW_KEY_F15", INT2NUM(GLFW_KEY_F15));
978
+ rb_define_const(module, "GLFW_KEY_F16", INT2NUM(GLFW_KEY_F16));
979
+ rb_define_const(module, "GLFW_KEY_F17", INT2NUM(GLFW_KEY_F17));
980
+ rb_define_const(module, "GLFW_KEY_F18", INT2NUM(GLFW_KEY_F18));
981
+ rb_define_const(module, "GLFW_KEY_F19", INT2NUM(GLFW_KEY_F19));
982
+ rb_define_const(module, "GLFW_KEY_F20", INT2NUM(GLFW_KEY_F20));
983
+ rb_define_const(module, "GLFW_KEY_F21", INT2NUM(GLFW_KEY_F21));
984
+ rb_define_const(module, "GLFW_KEY_F22", INT2NUM(GLFW_KEY_F22));
985
+ rb_define_const(module, "GLFW_KEY_F23", INT2NUM(GLFW_KEY_F23));
986
+ rb_define_const(module, "GLFW_KEY_F24", INT2NUM(GLFW_KEY_F24));
987
+ rb_define_const(module, "GLFW_KEY_F25", INT2NUM(GLFW_KEY_F25));
988
+ rb_define_const(module, "GLFW_KEY_UP", INT2NUM(GLFW_KEY_UP));
989
+ rb_define_const(module, "GLFW_KEY_DOWN", INT2NUM(GLFW_KEY_DOWN));
990
+ rb_define_const(module, "GLFW_KEY_LEFT", INT2NUM(GLFW_KEY_LEFT));
991
+ rb_define_const(module, "GLFW_KEY_RIGHT", INT2NUM(GLFW_KEY_RIGHT));
992
+ rb_define_const(module, "GLFW_KEY_LSHIFT", INT2NUM(GLFW_KEY_LSHIFT));
993
+ rb_define_const(module, "GLFW_KEY_RSHIFT", INT2NUM(GLFW_KEY_RSHIFT));
994
+ rb_define_const(module, "GLFW_KEY_LCTRL", INT2NUM(GLFW_KEY_LCTRL));
995
+ rb_define_const(module, "GLFW_KEY_RCTRL", INT2NUM(GLFW_KEY_RCTRL));
996
+ rb_define_const(module, "GLFW_KEY_LALT", INT2NUM(GLFW_KEY_LALT));
997
+ rb_define_const(module, "GLFW_KEY_RALT", INT2NUM(GLFW_KEY_RALT));
998
+ rb_define_const(module, "GLFW_KEY_TAB", INT2NUM(GLFW_KEY_TAB));
999
+ rb_define_const(module, "GLFW_KEY_ENTER", INT2NUM(GLFW_KEY_ENTER));
1000
+ rb_define_const(module, "GLFW_KEY_BACKSPACE", INT2NUM(GLFW_KEY_BACKSPACE));
1001
+ rb_define_const(module, "GLFW_KEY_INSERT", INT2NUM(GLFW_KEY_INSERT));
1002
+ rb_define_const(module, "GLFW_KEY_DEL", INT2NUM(GLFW_KEY_DEL));
1003
+ rb_define_const(module, "GLFW_KEY_PAGEUP", INT2NUM(GLFW_KEY_PAGEUP));
1004
+ rb_define_const(module, "GLFW_KEY_PAGEDOWN", INT2NUM(GLFW_KEY_PAGEDOWN));
1005
+ rb_define_const(module, "GLFW_KEY_HOME", INT2NUM(GLFW_KEY_HOME));
1006
+ rb_define_const(module, "GLFW_KEY_END", INT2NUM(GLFW_KEY_END));
1007
+ rb_define_const(module, "GLFW_KEY_KP_0", INT2NUM(GLFW_KEY_KP_0));
1008
+ rb_define_const(module, "GLFW_KEY_KP_1", INT2NUM(GLFW_KEY_KP_1));
1009
+ rb_define_const(module, "GLFW_KEY_KP_2", INT2NUM(GLFW_KEY_KP_2));
1010
+ rb_define_const(module, "GLFW_KEY_KP_3", INT2NUM(GLFW_KEY_KP_3));
1011
+ rb_define_const(module, "GLFW_KEY_KP_4", INT2NUM(GLFW_KEY_KP_4));
1012
+ rb_define_const(module, "GLFW_KEY_KP_5", INT2NUM(GLFW_KEY_KP_5));
1013
+ rb_define_const(module, "GLFW_KEY_KP_6", INT2NUM(GLFW_KEY_KP_6));
1014
+ rb_define_const(module, "GLFW_KEY_KP_7", INT2NUM(GLFW_KEY_KP_7));
1015
+ rb_define_const(module, "GLFW_KEY_KP_8", INT2NUM(GLFW_KEY_KP_8));
1016
+ rb_define_const(module, "GLFW_KEY_KP_9", INT2NUM(GLFW_KEY_KP_9));
1017
+ rb_define_const(module, "GLFW_KEY_KP_DIVIDE", INT2NUM(GLFW_KEY_KP_DIVIDE));
1018
+ rb_define_const(module, "GLFW_KEY_KP_MULTIPLY", INT2NUM(GLFW_KEY_KP_MULTIPLY));
1019
+ rb_define_const(module, "GLFW_KEY_KP_SUBTRACT", INT2NUM(GLFW_KEY_KP_SUBTRACT));
1020
+ rb_define_const(module, "GLFW_KEY_KP_ADD", INT2NUM(GLFW_KEY_KP_ADD));
1021
+ rb_define_const(module, "GLFW_KEY_KP_DECIMAL", INT2NUM(GLFW_KEY_KP_DECIMAL));
1022
+ rb_define_const(module, "GLFW_KEY_KP_EQUAL", INT2NUM(GLFW_KEY_KP_EQUAL));
1023
+ rb_define_const(module, "GLFW_KEY_KP_ENTER", INT2NUM(GLFW_KEY_KP_ENTER));
1024
+ rb_define_const(module, "GLFW_KEY_LAST", INT2NUM(GLFW_KEY_LAST));
1025
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_1", INT2NUM(GLFW_MOUSE_BUTTON_1));
1026
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_2", INT2NUM(GLFW_MOUSE_BUTTON_2));
1027
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_3", INT2NUM(GLFW_MOUSE_BUTTON_3));
1028
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_4", INT2NUM(GLFW_MOUSE_BUTTON_4));
1029
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_5", INT2NUM(GLFW_MOUSE_BUTTON_5));
1030
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_6", INT2NUM(GLFW_MOUSE_BUTTON_6));
1031
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_7", INT2NUM(GLFW_MOUSE_BUTTON_7));
1032
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_8", INT2NUM(GLFW_MOUSE_BUTTON_8));
1033
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_LAST", INT2NUM(GLFW_MOUSE_BUTTON_LAST));
1034
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_LEFT", INT2NUM(GLFW_MOUSE_BUTTON_LEFT));
1035
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_RIGHT", INT2NUM(GLFW_MOUSE_BUTTON_RIGHT));
1036
+ rb_define_const(module, "GLFW_MOUSE_BUTTON_MIDDLE", INT2NUM(GLFW_MOUSE_BUTTON_MIDDLE));
1037
+ rb_define_const(module, "GLFW_JOYSTICK_1", INT2NUM(GLFW_JOYSTICK_1));
1038
+ rb_define_const(module, "GLFW_JOYSTICK_2", INT2NUM(GLFW_JOYSTICK_2));
1039
+ rb_define_const(module, "GLFW_JOYSTICK_3", INT2NUM(GLFW_JOYSTICK_3));
1040
+ rb_define_const(module, "GLFW_JOYSTICK_4", INT2NUM(GLFW_JOYSTICK_4));
1041
+ rb_define_const(module, "GLFW_JOYSTICK_5", INT2NUM(GLFW_JOYSTICK_5));
1042
+ rb_define_const(module, "GLFW_JOYSTICK_6", INT2NUM(GLFW_JOYSTICK_6));
1043
+ rb_define_const(module, "GLFW_JOYSTICK_7", INT2NUM(GLFW_JOYSTICK_7));
1044
+ rb_define_const(module, "GLFW_JOYSTICK_8", INT2NUM(GLFW_JOYSTICK_8));
1045
+ rb_define_const(module, "GLFW_JOYSTICK_9", INT2NUM(GLFW_JOYSTICK_9));
1046
+ rb_define_const(module, "GLFW_JOYSTICK_10", INT2NUM(GLFW_JOYSTICK_10));
1047
+ rb_define_const(module, "GLFW_JOYSTICK_11", INT2NUM(GLFW_JOYSTICK_11));
1048
+ rb_define_const(module, "GLFW_JOYSTICK_12", INT2NUM(GLFW_JOYSTICK_12));
1049
+ rb_define_const(module, "GLFW_JOYSTICK_13", INT2NUM(GLFW_JOYSTICK_13));
1050
+ rb_define_const(module, "GLFW_JOYSTICK_14", INT2NUM(GLFW_JOYSTICK_14));
1051
+ rb_define_const(module, "GLFW_JOYSTICK_15", INT2NUM(GLFW_JOYSTICK_15));
1052
+ rb_define_const(module, "GLFW_JOYSTICK_16", INT2NUM(GLFW_JOYSTICK_16));
1053
+ rb_define_const(module, "GLFW_JOYSTICK_LAST", INT2NUM(GLFW_JOYSTICK_LAST));
1054
+ rb_define_const(module, "GLFW_WINDOW", INT2NUM(GLFW_WINDOW));
1055
+ rb_define_const(module, "GLFW_FULLSCREEN", INT2NUM(GLFW_FULLSCREEN));
1056
+ rb_define_const(module, "GLFW_OPENED", INT2NUM(GLFW_OPENED));
1057
+ rb_define_const(module, "GLFW_ACTIVE", INT2NUM(GLFW_ACTIVE));
1058
+ rb_define_const(module, "GLFW_ICONIFIED", INT2NUM(GLFW_ICONIFIED));
1059
+ rb_define_const(module, "GLFW_ACCELERATED", INT2NUM(GLFW_ACCELERATED));
1060
+ rb_define_const(module, "GLFW_RED_BITS", INT2NUM(GLFW_RED_BITS));
1061
+ rb_define_const(module, "GLFW_GREEN_BITS", INT2NUM(GLFW_GREEN_BITS));
1062
+ rb_define_const(module, "GLFW_BLUE_BITS", INT2NUM(GLFW_BLUE_BITS));
1063
+ rb_define_const(module, "GLFW_ALPHA_BITS", INT2NUM(GLFW_ALPHA_BITS));
1064
+ rb_define_const(module, "GLFW_DEPTH_BITS", INT2NUM(GLFW_DEPTH_BITS));
1065
+ rb_define_const(module, "GLFW_STENCIL_BITS", INT2NUM(GLFW_STENCIL_BITS));
1066
+ rb_define_const(module, "GLFW_REFRESH_RATE", INT2NUM(GLFW_REFRESH_RATE));
1067
+ rb_define_const(module, "GLFW_ACCUM_RED_BITS", INT2NUM(GLFW_ACCUM_RED_BITS));
1068
+ rb_define_const(module, "GLFW_ACCUM_GREEN_BITS", INT2NUM(GLFW_ACCUM_GREEN_BITS));
1069
+ rb_define_const(module, "GLFW_ACCUM_BLUE_BITS", INT2NUM(GLFW_ACCUM_BLUE_BITS));
1070
+ rb_define_const(module, "GLFW_ACCUM_ALPHA_BITS", INT2NUM(GLFW_ACCUM_ALPHA_BITS));
1071
+ rb_define_const(module, "GLFW_AUX_BUFFERS", INT2NUM(GLFW_AUX_BUFFERS));
1072
+ rb_define_const(module, "GLFW_STEREO", INT2NUM(GLFW_STEREO));
1073
+ rb_define_const(module, "GLFW_WINDOW_NO_RESIZE", INT2NUM(GLFW_WINDOW_NO_RESIZE));
1074
+ rb_define_const(module, "GLFW_FSAA_SAMPLES", INT2NUM(GLFW_FSAA_SAMPLES));
1075
+ rb_define_const(module, "GLFW_MOUSE_CURSOR", INT2NUM(GLFW_MOUSE_CURSOR));
1076
+ rb_define_const(module, "GLFW_STICKY_KEYS", INT2NUM(GLFW_STICKY_KEYS));
1077
+ rb_define_const(module, "GLFW_STICKY_MOUSE_BUTTONS", INT2NUM(GLFW_STICKY_MOUSE_BUTTONS));
1078
+ rb_define_const(module, "GLFW_SYSTEM_KEYS", INT2NUM(GLFW_SYSTEM_KEYS));
1079
+ rb_define_const(module, "GLFW_KEY_REPEAT", INT2NUM(GLFW_KEY_REPEAT));
1080
+ rb_define_const(module, "GLFW_AUTO_POLL_EVENTS", INT2NUM(GLFW_AUTO_POLL_EVENTS));
1081
+ rb_define_const(module, "GLFW_WAIT", INT2NUM(GLFW_WAIT));
1082
+ rb_define_const(module, "GLFW_NOWAIT", INT2NUM(GLFW_NOWAIT));
1083
+ rb_define_const(module, "GLFW_PRESENT", INT2NUM(GLFW_PRESENT));
1084
+ rb_define_const(module, "GLFW_AXES", INT2NUM(GLFW_AXES));
1085
+ rb_define_const(module, "GLFW_BUTTONS", INT2NUM(GLFW_BUTTONS));
1086
+ rb_define_const(module, "GLFW_NO_RESCALE_BIT", INT2NUM(GLFW_NO_RESCALE_BIT));
1087
+ rb_define_const(module, "GLFW_ORIGIN_UL_BIT", INT2NUM(GLFW_ORIGIN_UL_BIT));
1088
+ rb_define_const(module, "GLFW_BUILD_MIPMAPS_BIT", INT2NUM(GLFW_BUILD_MIPMAPS_BIT));
1089
+ rb_define_const(module, "GLFW_ALPHA_MAP_BIT", INT2NUM(GLFW_ALPHA_MAP_BIT));
1090
+ rb_define_const(module, "GLFW_INFINITY", INT2NUM(GLFW_INFINITY));
1091
+
1092
+ /* calls Glfw.glfwTerminate() at ruby exit */
1093
+ rb_eval_string("at_exit do Glfw.glfwTerminate end");
1094
+ }