opengl-bindings 1.6.10 → 1.6.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/glfw.rb CHANGED
@@ -1,691 +1,711 @@
1
- # -*- coding: utf-8 -*-
2
- # A GLFW wrapper (for version 3.0 - 3.3)
3
- require 'fiddle/import'
4
-
5
- module GLFW
6
-
7
- extend Fiddle::Importer
8
-
9
- #
10
- # Fiddle's default 'extern' stores all methods into local variable '@func_map', that makes difficult to 'include GLFW'.
11
- # So I override it and replace '@func_map' into 'GLFW_FUNCTIONS_MAP'.
12
- # Ref.: /lib/ruby/2.0.0/fiddle/import.rb
13
- #
14
- GLFW_FUNCTIONS_MAP = {}
15
- def self.extern(signature, *opts)
16
- symname, ctype, argtype = parse_signature(signature, @type_alias)
17
- opt = parse_bind_options(opts)
18
- f = import_function(symname, ctype, argtype, opt[:call_type])
19
- name = symname.gsub(/@.+/,'')
20
- GLFW_FUNCTIONS_MAP[name] = f
21
- begin
22
- /^(.+?):(\d+)/ =~ caller.first
23
- file, line = $1, $2.to_i
24
- rescue
25
- file, line = __FILE__, __LINE__+3
26
- end
27
- args_str="*args"
28
- module_eval(<<-EOS, file, line)
29
- def #{name}(*args, &block)
30
- GLFW_FUNCTIONS_MAP['#{name}'].call(*args,&block)
31
- end
32
- EOS
33
- module_function(name)
34
- f
35
- end
36
-
37
- # defines
38
- GLFW_TRUE = 1 # Available since GLFW 3.2
39
- GLFW_FALSE = 0 # Available since GLFW 3.2
40
-
41
- GLFW_RELEASE = 0
42
- GLFW_PRESS = 1
43
- GLFW_REPEAT = 2
44
-
45
- GLFW_HAT_CENTERED = 0 # Available since GLFW 3.3
46
- GLFW_HAT_UP = 1 # Available since GLFW 3.3
47
- GLFW_HAT_RIGHT = 2 # Available since GLFW 3.3
48
- GLFW_HAT_DOWN = 4 # Available since GLFW 3.3
49
- GLFW_HAT_LEFT = 8 # Available since GLFW 3.3
50
- GLFW_HAT_RIGHT_UP = (GLFW_HAT_RIGHT | GLFW_HAT_UP) # Available since GLFW 3.3
51
- GLFW_HAT_RIGHT_DOWN = (GLFW_HAT_RIGHT | GLFW_HAT_DOWN) # Available since GLFW 3.3
52
- GLFW_HAT_LEFT_UP = (GLFW_HAT_LEFT | GLFW_HAT_UP) # Available since GLFW 3.3
53
- GLFW_HAT_LEFT_DOWN = (GLFW_HAT_LEFT | GLFW_HAT_DOWN) # Available since GLFW 3.3
54
-
55
- GLFW_KEY_UNKNOWN = -1
56
-
57
- GLFW_KEY_SPACE = 32
58
- GLFW_KEY_APOSTROPHE = 39 # '
59
- GLFW_KEY_COMMA = 44 # ,
60
- GLFW_KEY_MINUS = 45 # -
61
- GLFW_KEY_PERIOD = 46 # .
62
- GLFW_KEY_SLASH = 47 # /
63
- GLFW_KEY_0 = 48
64
- GLFW_KEY_1 = 49
65
- GLFW_KEY_2 = 50
66
- GLFW_KEY_3 = 51
67
- GLFW_KEY_4 = 52
68
- GLFW_KEY_5 = 53
69
- GLFW_KEY_6 = 54
70
- GLFW_KEY_7 = 55
71
- GLFW_KEY_8 = 56
72
- GLFW_KEY_9 = 57
73
- GLFW_KEY_SEMICOLON = 59 # ;
74
- GLFW_KEY_EQUAL = 61 # =
75
- GLFW_KEY_A = 65
76
- GLFW_KEY_B = 66
77
- GLFW_KEY_C = 67
78
- GLFW_KEY_D = 68
79
- GLFW_KEY_E = 69
80
- GLFW_KEY_F = 70
81
- GLFW_KEY_G = 71
82
- GLFW_KEY_H = 72
83
- GLFW_KEY_I = 73
84
- GLFW_KEY_J = 74
85
- GLFW_KEY_K = 75
86
- GLFW_KEY_L = 76
87
- GLFW_KEY_M = 77
88
- GLFW_KEY_N = 78
89
- GLFW_KEY_O = 79
90
- GLFW_KEY_P = 80
91
- GLFW_KEY_Q = 81
92
- GLFW_KEY_R = 82
93
- GLFW_KEY_S = 83
94
- GLFW_KEY_T = 84
95
- GLFW_KEY_U = 85
96
- GLFW_KEY_V = 86
97
- GLFW_KEY_W = 87
98
- GLFW_KEY_X = 88
99
- GLFW_KEY_Y = 89
100
- GLFW_KEY_Z = 90
101
- GLFW_KEY_LEFT_BRACKET = 91 # [
102
- GLFW_KEY_BACKSLASH = 92 # \
103
- GLFW_KEY_RIGHT_BRACKET = 93 # ]
104
- GLFW_KEY_GRAVE_ACCENT = 96 # `
105
- GLFW_KEY_WORLD_1 = 161 # non-US #1
106
- GLFW_KEY_WORLD_2 = 162 # non-US #2
107
-
108
- GLFW_KEY_ESCAPE = 256
109
- GLFW_KEY_ENTER = 257
110
- GLFW_KEY_TAB = 258
111
- GLFW_KEY_BACKSPACE = 259
112
- GLFW_KEY_INSERT = 260
113
- GLFW_KEY_DELETE = 261
114
- GLFW_KEY_RIGHT = 262
115
- GLFW_KEY_LEFT = 263
116
- GLFW_KEY_DOWN = 264
117
- GLFW_KEY_UP = 265
118
- GLFW_KEY_PAGE_UP = 266
119
- GLFW_KEY_PAGE_DOWN = 267
120
- GLFW_KEY_HOME = 268
121
- GLFW_KEY_END = 269
122
- GLFW_KEY_CAPS_LOCK = 280
123
- GLFW_KEY_SCROLL_LOCK = 281
124
- GLFW_KEY_NUM_LOCK = 282
125
- GLFW_KEY_PRINT_SCREEN = 283
126
- GLFW_KEY_PAUSE = 284
127
- GLFW_KEY_F1 = 290
128
- GLFW_KEY_F2 = 291
129
- GLFW_KEY_F3 = 292
130
- GLFW_KEY_F4 = 293
131
- GLFW_KEY_F5 = 294
132
- GLFW_KEY_F6 = 295
133
- GLFW_KEY_F7 = 296
134
- GLFW_KEY_F8 = 297
135
- GLFW_KEY_F9 = 298
136
- GLFW_KEY_F10 = 299
137
- GLFW_KEY_F11 = 300
138
- GLFW_KEY_F12 = 301
139
- GLFW_KEY_F13 = 302
140
- GLFW_KEY_F14 = 303
141
- GLFW_KEY_F15 = 304
142
- GLFW_KEY_F16 = 305
143
- GLFW_KEY_F17 = 306
144
- GLFW_KEY_F18 = 307
145
- GLFW_KEY_F19 = 308
146
- GLFW_KEY_F20 = 309
147
- GLFW_KEY_F21 = 310
148
- GLFW_KEY_F22 = 311
149
- GLFW_KEY_F23 = 312
150
- GLFW_KEY_F24 = 313
151
- GLFW_KEY_F25 = 314
152
- GLFW_KEY_KP_0 = 320
153
- GLFW_KEY_KP_1 = 321
154
- GLFW_KEY_KP_2 = 322
155
- GLFW_KEY_KP_3 = 323
156
- GLFW_KEY_KP_4 = 324
157
- GLFW_KEY_KP_5 = 325
158
- GLFW_KEY_KP_6 = 326
159
- GLFW_KEY_KP_7 = 327
160
- GLFW_KEY_KP_8 = 328
161
- GLFW_KEY_KP_9 = 329
162
- GLFW_KEY_KP_DECIMAL = 330
163
- GLFW_KEY_KP_DIVIDE = 331
164
- GLFW_KEY_KP_MULTIPLY = 332
165
- GLFW_KEY_KP_SUBTRACT = 333
166
- GLFW_KEY_KP_ADD = 334
167
- GLFW_KEY_KP_ENTER = 335
168
- GLFW_KEY_KP_EQUAL = 336
169
- GLFW_KEY_LEFT_SHIFT = 340
170
- GLFW_KEY_LEFT_CONTROL = 341
171
- GLFW_KEY_LEFT_ALT = 342
172
- GLFW_KEY_LEFT_SUPER = 343
173
- GLFW_KEY_RIGHT_SHIFT = 344
174
- GLFW_KEY_RIGHT_CONTROL = 345
175
- GLFW_KEY_RIGHT_ALT = 346
176
- GLFW_KEY_RIGHT_SUPER = 347
177
- GLFW_KEY_MENU = 348
178
- GLFW_KEY_LAST = GLFW_KEY_MENU
179
-
180
- GLFW_MOD_SHIFT = 0x0001
181
- GLFW_MOD_CONTROL = 0x0002
182
- GLFW_MOD_ALT = 0x0004
183
- GLFW_MOD_SUPER = 0x0008
184
- GLFW_MOD_CAPS_LOCK = 0x0010 # Available since GLFW 3.3
185
- GLFW_MOD_NUM_LOCK = 0x0020 # Available since GLFW 3.3
186
-
187
- GLFW_MOUSE_BUTTON_1 = 0
188
- GLFW_MOUSE_BUTTON_2 = 1
189
- GLFW_MOUSE_BUTTON_3 = 2
190
- GLFW_MOUSE_BUTTON_4 = 3
191
- GLFW_MOUSE_BUTTON_5 = 4
192
- GLFW_MOUSE_BUTTON_6 = 5
193
- GLFW_MOUSE_BUTTON_7 = 6
194
- GLFW_MOUSE_BUTTON_8 = 7
195
- GLFW_MOUSE_BUTTON_LAST = GLFW_MOUSE_BUTTON_8
196
- GLFW_MOUSE_BUTTON_LEFT = GLFW_MOUSE_BUTTON_1
197
- GLFW_MOUSE_BUTTON_RIGHT = GLFW_MOUSE_BUTTON_2
198
- GLFW_MOUSE_BUTTON_MIDDLE = GLFW_MOUSE_BUTTON_3
199
-
200
- GLFW_JOYSTICK_1 = 0
201
- GLFW_JOYSTICK_2 = 1
202
- GLFW_JOYSTICK_3 = 2
203
- GLFW_JOYSTICK_4 = 3
204
- GLFW_JOYSTICK_5 = 4
205
- GLFW_JOYSTICK_6 = 5
206
- GLFW_JOYSTICK_7 = 6
207
- GLFW_JOYSTICK_8 = 7
208
- GLFW_JOYSTICK_9 = 8
209
- GLFW_JOYSTICK_10 = 9
210
- GLFW_JOYSTICK_11 = 10
211
- GLFW_JOYSTICK_12 = 11
212
- GLFW_JOYSTICK_13 = 12
213
- GLFW_JOYSTICK_14 = 13
214
- GLFW_JOYSTICK_15 = 14
215
- GLFW_JOYSTICK_16 = 15
216
- GLFW_JOYSTICK_LAST = GLFW_JOYSTICK_16
217
-
218
- GLFW_GAMEPAD_BUTTON_A = 0 # Available since GLFW 3.3
219
- GLFW_GAMEPAD_BUTTON_B = 1 # Available since GLFW 3.3
220
- GLFW_GAMEPAD_BUTTON_X = 2 # Available since GLFW 3.3
221
- GLFW_GAMEPAD_BUTTON_Y = 3 # Available since GLFW 3.3
222
- GLFW_GAMEPAD_BUTTON_LEFT_BUMPER = 4 # Available since GLFW 3.3
223
- GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER = 5 # Available since GLFW 3.3
224
- GLFW_GAMEPAD_BUTTON_BACK = 6 # Available since GLFW 3.3
225
- GLFW_GAMEPAD_BUTTON_START = 7 # Available since GLFW 3.3
226
- GLFW_GAMEPAD_BUTTON_GUIDE = 8 # Available since GLFW 3.3
227
- GLFW_GAMEPAD_BUTTON_LEFT_THUMB = 9 # Available since GLFW 3.3
228
- GLFW_GAMEPAD_BUTTON_RIGHT_THUMB = 10 # Available since GLFW 3.3
229
- GLFW_GAMEPAD_BUTTON_DPAD_UP = 11 # Available since GLFW 3.3
230
- GLFW_GAMEPAD_BUTTON_DPAD_RIGHT = 12 # Available since GLFW 3.3
231
- GLFW_GAMEPAD_BUTTON_DPAD_DOWN = 13 # Available since GLFW 3.3
232
- GLFW_GAMEPAD_BUTTON_DPAD_LEFT = 14 # Available since GLFW 3.3
233
- GLFW_GAMEPAD_BUTTON_LAST = GLFW_GAMEPAD_BUTTON_DPAD_LEFT # Available since GLFW 3.3
234
-
235
- GLFW_GAMEPAD_BUTTON_CROSS = GLFW_GAMEPAD_BUTTON_A # Available since GLFW 3.3
236
- GLFW_GAMEPAD_BUTTON_CIRCLE = GLFW_GAMEPAD_BUTTON_B # Available since GLFW 3.3
237
- GLFW_GAMEPAD_BUTTON_SQUARE = GLFW_GAMEPAD_BUTTON_X # Available since GLFW 3.3
238
- GLFW_GAMEPAD_BUTTON_TRIANGLE = GLFW_GAMEPAD_BUTTON_Y # Available since GLFW 3.3
239
-
240
- GLFW_GAMEPAD_AXIS_LEFT_X = 0 # Available since GLFW 3.3
241
- GLFW_GAMEPAD_AXIS_LEFT_Y = 1 # Available since GLFW 3.3
242
- GLFW_GAMEPAD_AXIS_RIGHT_X = 2 # Available since GLFW 3.3
243
- GLFW_GAMEPAD_AXIS_RIGHT_Y = 3 # Available since GLFW 3.3
244
- GLFW_GAMEPAD_AXIS_LEFT_TRIGGER = 4 # Available since GLFW 3.3
245
- GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER = 5 # Available since GLFW 3.3
246
- GLFW_GAMEPAD_AXIS_LAST = GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER # Available since GLFW 3.3
247
-
248
- GLFW_NO_ERROR = 0 # Available since GLFW 3.3
249
- GLFW_NOT_INITIALIZED = 0x00010001
250
- GLFW_NO_CURRENT_CONTEXT = 0x00010002
251
- GLFW_INVALID_ENUM = 0x00010003
252
- GLFW_INVALID_VALUE = 0x00010004
253
- GLFW_OUT_OF_MEMORY = 0x00010005
254
- GLFW_API_UNAVAILABLE = 0x00010006
255
- GLFW_VERSION_UNAVAILABLE = 0x00010007
256
- GLFW_PLATFORM_ERROR = 0x00010008
257
- GLFW_FORMAT_UNAVAILABLE = 0x00010009
258
- GLFW_NO_WINDOW_CONTEXT = 0x0001000A # Available since GLFW 3.2
259
-
260
- GLFW_FOCUSED = 0x00020001
261
- GLFW_ICONIFIED = 0x00020002
262
- GLFW_RESIZABLE = 0x00020003
263
- GLFW_VISIBLE = 0x00020004
264
- GLFW_DECORATED = 0x00020005
265
- GLFW_AUTO_ICONIFY = 0x00020006 # Available since GLFW 3.1
266
- GLFW_FLOATING = 0x00020007 # Available since GLFW 3.1
267
- GLFW_MAXIMIZED = 0x00020008 # Available since GLFW 3.2
268
- GLFW_CENTER_CURSOR = 0x00020009 # Available since GLFW 3.3
269
- GLFW_TRANSPARENT_FRAMEBUFFER = 0x0002000A # Available since GLFW 3.3
270
- GLFW_HOVERED = 0x0002000B # Available since GLFW 3.3
271
- GLFW_FOCUS_ON_SHOW = 0x0002000C # Available since GLFW 3.3
272
-
273
- GLFW_RED_BITS = 0x00021001
274
- GLFW_GREEN_BITS = 0x00021002
275
- GLFW_BLUE_BITS = 0x00021003
276
- GLFW_ALPHA_BITS = 0x00021004
277
- GLFW_DEPTH_BITS = 0x00021005
278
- GLFW_STENCIL_BITS = 0x00021006
279
- GLFW_ACCUM_RED_BITS = 0x00021007
280
- GLFW_ACCUM_GREEN_BITS = 0x00021008
281
- GLFW_ACCUM_BLUE_BITS = 0x00021009
282
- GLFW_ACCUM_ALPHA_BITS = 0x0002100A
283
- GLFW_AUX_BUFFERS = 0x0002100B
284
- GLFW_STEREO = 0x0002100C
285
- GLFW_SAMPLES = 0x0002100D
286
- GLFW_SRGB_CAPABLE = 0x0002100E
287
- GLFW_REFRESH_RATE = 0x0002100F
288
- GLFW_DOUBLEBUFFER = 0x00021010
289
-
290
- GLFW_CLIENT_API = 0x00022001
291
- GLFW_CONTEXT_VERSION_MAJOR = 0x00022002
292
- GLFW_CONTEXT_VERSION_MINOR = 0x00022003
293
- GLFW_CONTEXT_REVISION = 0x00022004
294
- GLFW_CONTEXT_ROBUSTNESS = 0x00022005
295
- GLFW_OPENGL_FORWARD_COMPAT = 0x00022006
296
- GLFW_OPENGL_DEBUG_CONTEXT = 0x00022007
297
- GLFW_OPENGL_PROFILE = 0x00022008
298
- GLFW_CONTEXT_RELEASE_BEHAVIOR = 0x00022009
299
- GLFW_CONTEXT_NO_ERROR = 0x0002200A
300
- GLFW_CONTEXT_CREATION_API = 0x0002200B # Available since GLFW 3.2
301
- GLFW_SCALE_TO_MONITOR = 0x0002200C # Available since GLFW 3.3
302
-
303
- GLFW_COCOA_RETINA_FRAMEBUFFER = 0x00023001 # Available since GLFW 3.3
304
- GLFW_COCOA_FRAME_NAME = 0x00023002 # Available since GLFW 3.3
305
- GLFW_COCOA_GRAPHICS_SWITCHING = 0x00023003 # Available since GLFW 3.3
306
-
307
- GLFW_X11_CLASS_NAME = 0x00024001 # Available since GLFW 3.3
308
- GLFW_X11_INSTANCE_NAME = 0x00024002 # Available since GLFW 3.3
309
-
310
- GLFW_NO_API = 0 # Available since GLFW 3.2
311
- GLFW_OPENGL_API = 0x00030001
312
- GLFW_OPENGL_ES_API = 0x00030002
313
-
314
- GLFW_NO_ROBUSTNESS = 0
315
- GLFW_NO_RESET_NOTIFICATION = 0x00031001
316
- GLFW_LOSE_CONTEXT_ON_RESET = 0x00031002
317
-
318
- GLFW_OPENGL_ANY_PROFILE = 0
319
- GLFW_OPENGL_CORE_PROFILE = 0x00032001
320
- GLFW_OPENGL_COMPAT_PROFILE = 0x00032002
321
-
322
- GLFW_CURSOR = 0x00033001
323
- GLFW_STICKY_KEYS = 0x00033002
324
- GLFW_STICKY_MOUSE_BUTTONS = 0x00033003
325
- GLFW_LOCK_KEY_MODS = 0x00033004 # Available since GLFW 3.3
326
- GLFW_RAW_MOUSE_MOTION = 0x00033005 # Available since GLFW 3.3
327
-
328
- GLFW_CURSOR_NORMAL = 0x00034001
329
- GLFW_CURSOR_HIDDEN = 0x00034002
330
- GLFW_CURSOR_DISABLED = 0x00034003
331
-
332
- GLFW_ANY_RELEASE_BEHAVIOR = 0
333
- GLFW_RELEASE_BEHAVIOR_FLUSH = 0x00035001
334
- GLFW_RELEASE_BEHAVIOR_NONE = 0x00035002
335
-
336
- GLFW_NATIVE_CONTEXT_API = 0x00036001 # Available since GLFW 3.2
337
- GLFW_EGL_CONTEXT_API = 0x00036002 # Available since GLFW 3.2
338
- GLFW_OSMESA_CONTEXT_API = 0x00036003 # Available since GLFW 3.3
339
-
340
- GLFW_ARROW_CURSOR = 0x00036001
341
- GLFW_IBEAM_CURSOR = 0x00036002
342
- GLFW_CROSSHAIR_CURSOR = 0x00036003
343
- GLFW_HAND_CURSOR = 0x00036004
344
- GLFW_HRESIZE_CURSOR = 0x00036005
345
- GLFW_VRESIZE_CURSOR = 0x00036006
346
-
347
- GLFW_CONNECTED = 0x00040001
348
- GLFW_DISCONNECTED = 0x00040002
349
-
350
- GLFW_JOYSTICK_HAT_BUTTONS = 0x00050001 # Available since GLFW 3.3
351
-
352
- GLFW_COCOA_CHDIR_RESOURCES = 0x00051001 # Available since GLFW 3.3
353
- GLFW_COCOA_MENUBAR = 0x00051002 # Available since GLFW 3.3
354
-
355
- GLFW_DONT_CARE = -1
356
-
357
- # typedefs
358
- @@glfw_cb_function_signature = {
359
- :GLFWerrorfun => "void GLFWerrorfun(int,const char*)",
360
- :GLFWwindowposfun => "void GLFWwindowposfun(void*,int,int)",
361
- :GLFWwindowsizefun => "void GLFWwindowsizefun(void*,int,int)",
362
- :GLFWwindowclosefun => "void GLFWwindowclosefun(void*)",
363
- :GLFWwindowrefreshfun => "void GLFWwindowrefreshfun(void*)",
364
- :GLFWwindowfocusfun => "void GLFWwindowfocusfun(void*,int)",
365
- :GLFWwindowiconifyfun => "void GLFWwindowiconifyfun(void*,int)",
366
- :GLFWwindowmaximizefun => "void GLFWwindowmaximizefun(void*,int)",
367
- :GLFWframebuffersizefun => "void GLFWframebuffersizefun(void*,int,int)",
368
- :GLFWwindowcontentscalefun => "void GLFWwindowcontentscalefun(void*,float,float)", # Available since GLFW 3.3
369
- :GLFWmousebuttonfun => "void GLFWmousebuttonfun(void*,int,int,int)",
370
- :GLFWcursorposfun => "void GLFWcursorposfun(void*,double,double)",
371
- :GLFWcursorenterfun => "void GLFWcursorenterfun(void*,int)",
372
- :GLFWscrollfun => "void GLFWscrollfun(void*,double,double)",
373
- :GLFWkeyfun => "void GLFWkeyfun(void*,int,int,int,int)",
374
- :GLFWcharfun => "void GLFWcharfun(void*,unsigned int)",
375
- :GLFWcharmodsfun => "void GLFWcharmodsfun(void*,unsigned int,int)", # Available since GLFW 3.1 / Scheduled for removal in version 4.0.
376
- :GLFWdropfun => "void GLFWdropfun(void*,int,const char**)", # Available since GLFW 3.1
377
- :GLFWmonitorfun => "void GLFWmonitorfun(void*,int)", # Available since GLFW 3.0
378
- :GLFWjoystickfun => "void GGLFWjoystickfun(int,int)", # Available since GLFW 3.2
379
- }
380
-
381
- # Creates a callback as an instance of Fiddle::Function
382
- def self.create_callback_function( sym, proc=nil, &blk )
383
- if block_given?
384
- return bind( @@glfw_cb_function_signature[sym], nil, &blk )
385
- else
386
- return bind( @@glfw_cb_function_signature[sym], nil, &proc )
387
- end
388
- end
389
-
390
- GLFWerrorfun_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]
391
- GLFWerrorfun_cb_retval = Fiddle::TYPE_VOID
392
- GLFWwindowposfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
393
- GLFWwindowposfun_cb_retval = Fiddle::TYPE_VOID
394
- GLFWwindowsizefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
395
- GLFWwindowsizefun_cb_retval = Fiddle::TYPE_VOID
396
- GLFWwindowclosefun_cb_args = [Fiddle::TYPE_VOIDP]
397
- GLFWwindowclosefun_cb_retval = Fiddle::TYPE_VOID
398
- GLFWwindowrefreshfun_cb_args = [Fiddle::TYPE_VOIDP]
399
- GLFWwindowrefreshfun_cb_retval = Fiddle::TYPE_VOID
400
- GLFWwindowfocusfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
401
- GLFWwindowfocusfun_cb_retval = Fiddle::TYPE_VOID
402
- GLFWwindowiconifyfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
403
- GLFWwindowiconifyfun_cb_retval = Fiddle::TYPE_VOID
404
- GLFWframebuffersizefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
405
- GLFWframebuffersizefun_cb_retval = Fiddle::TYPE_VOID
406
- GLFWwindowcontentscalefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_FLOAT, Fiddle::TYPE_FLOAT] # Available since GLFW 3.3
407
- GLFWwindowcontentscalefun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.3
408
- GLFWmousebuttonfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
409
- GLFWmousebuttonfun_cb_retval = Fiddle::TYPE_VOID
410
- GLFWcursorposfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]
411
- GLFWcursorposfun_cb_retval = Fiddle::TYPE_VOID
412
- GLFWcursorenterfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
413
- GLFWcursorenterfun_cb_retval = Fiddle::TYPE_VOID
414
- GLFWscrollfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]
415
- GLFWscrollfun_cb_retval = Fiddle::TYPE_VOID
416
- GLFWkeyfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
417
- GLFWkeyfun_cb_retval = Fiddle::TYPE_VOID
418
- GLFWcharfun_cb_args = [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]
419
- GLFWcharfun_cb_retval = Fiddle::TYPE_VOID
420
- GLFWcharmodsfun_cb_args = [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT] # Available since GLFW 3.1
421
- GLFWcharmodsfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.1
422
- GLFWdropfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP] # Available since GLFW 3.1
423
- GLFWdropfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.1
424
- GLFWmonitorfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT] # Available since GLFW 3.0
425
- GLFWmonitorfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.0
426
- GLFWjoystickfun_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT] # Available since GLFW 3.2
427
- GLFWjoystickfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.2
428
-
429
- @@glfw_cb_closure_signature = {
430
- :GLFWerrorfun => [GLFWerrorfun_cb_retval, GLFWerrorfun_cb_args],
431
- :GLFWwindowposfun => [GLFWwindowposfun_cb_retval, GLFWwindowposfun_cb_args],
432
- :GLFWwindowsizefun => [GLFWwindowsizefun_cb_retval, GLFWwindowsizefun_cb_args],
433
- :GLFWwindowclosefun => [GLFWwindowclosefun_cb_retval, GLFWwindowclosefun_cb_args],
434
- :GLFWwindowrefreshfun => [GLFWwindowrefreshfun_cb_retval, GLFWwindowrefreshfun_cb_args],
435
- :GLFWwindowfocusfun => [GLFWwindowfocusfun_cb_retval, GLFWwindowfocusfun_cb_args],
436
- :GLFWwindowiconifyfun => [GLFWwindowiconifyfun_cb_retval, GLFWwindowiconifyfun_cb_args],
437
- :GLFWframebuffersizefun => [GLFWframebuffersizefun_cb_retval, GLFWframebuffersizefun_cb_args],
438
- :GLFWwindowcontentscalefun => [GLFWwindowcontentscalefun_cb_retval, GLFWwindowcontentscalefun_cb_args], # Available since GLFW 3.3
439
- :GLFWmousebuttonfun => [GLFWmousebuttonfun_cb_retval, GLFWmousebuttonfun_cb_args],
440
- :GLFWcursorposfun => [GLFWcursorposfun_cb_retval, GLFWcursorposfun_cb_args],
441
- :GLFWcursorenterfun => [GLFWcursorenterfun_cb_retval, GLFWcursorenterfun_cb_args],
442
- :GLFWscrollfun => [GLFWscrollfun_cb_retval, GLFWscrollfun_cb_args],
443
- :GLFWkeyfun => [GLFWkeyfun_cb_retval, GLFWkeyfun_cb_args],
444
- :GLFWcharfun => [GLFWcharfun_cb_retval, GLFWcharfun_cb_args],
445
- :GLFWcharmodsfun => [GLFWcharmodsfun_cb_retval, GLFWcharmodsfun_cb_args], # Available since GLFW 3.1
446
- :GLFWdropfun => [GLFWdropfun_cb_retval, GLFWdropfun_cb_args], # Available since GLFW 3.1
447
- :GLFWmonitorfun => [GLFWmonitorfun_cb_retval, GLFWmonitorfun_cb_args],
448
- :GLFWjoystickfun => [GLFWjoystickfun_cb_retval, GLFWjoystickfun_cb_args], # Available since GLFW 3.2
449
- }
450
-
451
- # Creates a callback as an instance of Fiddle::Closure::BlockCaller
452
- def self.create_callback_closure( sym, proc=nil, &blk )
453
- cb_retval = @@glfw_cb_closure_signature[sym][0]
454
- cb_args = @@glfw_cb_closure_signature[sym][1]
455
- if block_given?
456
- return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &blk )
457
- else
458
- return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &proc )
459
- end
460
- end
461
-
462
- # NOTE : Use 'create_callback_function' for backward compatibility.
463
- def self.create_callback( sym, proc=nil, &blk )
464
- return self.create_callback_closure( sym, proc, &blk )
465
- end
466
-
467
- # struct
468
- GLFWvidmode = struct(["int width",
469
- "int height",
470
- "int redBits",
471
- "int greenBits",
472
- "int blueBits",
473
- "int refreshRate"])
474
-
475
- GLFWgammaramp = struct(["unsigned short* red",
476
- "unsigned short* green",
477
- "unsigned short* blue",
478
- "unsigned int size"])
479
-
480
- # Available since GLFW 3.1
481
- GLFWimage = struct(["int width",
482
- "int height",
483
- "unsigned char* pixels"])
484
-
485
- # Available since GLFW 3.3
486
- GLFWgamepadstate = struct(["unsigned char buttons[15]",
487
- "float axes[6]"])
488
-
489
- @@glfw_import_done = false
490
-
491
- # Load native library.
492
- def self.load_lib(lib = nil, path = nil, output_error = false)
493
- if lib == nil && path == nil
494
- case OpenGL.get_platform
495
- when :OPENGL_PLATFORM_WINDOWS
496
- lib, path = 'GLFW3.dll', Dir.pwd
497
- when :OPENGL_PLATFORM_MACOSX
498
- lib, path = 'libglfw.dylib', Dir.pwd
499
- else
500
- lib = 'libglfw.so'
501
- end
502
- end
503
-
504
- if path
505
- dlload (path + '/' + lib)
506
- else
507
- dlload (lib)
508
- end
509
- import_symbols(output_error) unless @@glfw_import_done
510
- end
511
-
512
- def self.load_dll(lib = nil, path = nil)
513
- puts "Warning GLFW.load_dll is deprecated, use GLFW.load_lib instead"
514
- self.load_lib(lib, path)
515
- end
516
-
517
- @@lib_signature = [
518
- 'int glfwInit()',
519
- 'void glfwTerminate()',
520
- 'void glfwInitHint(int, int)', # Available since GLFW 3.3
521
- 'void glfwGetVersion(int*, int*, int*)',
522
- 'const char* glfwGetVersionString()',
523
- 'int glfwGetError(const char**)', # Available since GLFW 3.3
524
- 'void* glfwSetErrorCallback(void*)',
525
- 'void** glfwGetMonitors(int*)',
526
- 'void* glfwGetPrimaryMonitor()',
527
- 'void glfwGetMonitorPos(void*, int*, int*)',
528
- 'void glfwGetMonitorWorkarea(void* monitor, int*, int*, int*, int*)', # Available since GLFW 3.3
529
- 'void glfwGetMonitorPhysicalSize(void*, int*, int*)',
530
- 'void glfwGetMonitorContentScale(void*, float*, float*)', # Available since GLFW 3.3
531
- 'const char* glfwGetMonitorName(void*)',
532
- 'const void glfwSetMonitorUserPointer(void*, void*)', # Available since GLFW 3.3
533
- 'const void* glfwGetMonitorUserPointer(void**)', # Available since GLFW 3.3
534
- 'void* glfwSetMonitorCallback(void*)', # Available since GLFW 3.0
535
- 'const void* glfwGetVideoModes(void*, int*)',
536
- 'const void* glfwGetVideoMode(void*)', # Available since GLFW 3.0
537
- 'void glfwSetGamma(void*, float)', # Available since GLFW 3.0
538
- 'const void* glfwGetGammaRamp(void*)', # Available since GLFW 3.0
539
- 'void glfwSetGammaRamp(void*, const void*)', # Available since GLFW 3.0
540
- 'void glfwDefaultWindowHints()', # Available since GLFW 3.0
541
- 'void glfwWindowHint(int, int)', # Available since GLFW 3.0
542
- 'void glfwWindowHintString(int, const char*)', # Available since GLFW 3.3
543
- 'void* glfwCreateWindow(int, int, const char*, void*, void*)', # Available since GLFW 3.0
544
- 'void glfwDestroyWindow(void*)', # Available since GLFW 3.0
545
- 'int glfwWindowShouldClose(void*)', # Available since GLFW 3.0
546
- 'void glfwSetWindowShouldClose(void* window, int)', # Available since GLFW 3.0
547
- 'void glfwSetWindowTitle(void*, const char*)',
548
- 'void glfwSetWindowIcon(void*, int, void*)', # Available since GLFW 3.2
549
- 'void glfwGetWindowPos(void*, int*, int*)', # Available since GLFW 3.0
550
- 'void glfwSetWindowPos(void*, int, int)',
551
- 'void glfwGetWindowSize(void*, int*, int*)',
552
- 'void glfwSetWindowSizeLimits(void*, int, int, int, int)', # Available since GLFW 3.2
553
- 'void glfwSetWindowAspectRatio(void*, int, int)', # Available since GLFW 3.2
554
- 'void glfwSetWindowSize(void*, int, int)',
555
- 'void glfwGetFramebufferSize(void*, int*, int*)', # Available since GLFW 3.0
556
- 'void glfwGetWindowFrameSize(void*, int*, int*, int*, int*)', # Available since GLFW 3.1
557
- 'void glfwGetWindowContentScale(void*, float*, float*)', # Available since GLFW 3.3
558
- 'float glfwGetWindowOpacity(void*)', # Available since GLFW 3.3
559
- 'void glfwSetWindowOpacity(void*, float)', # Available since GLFW 3.3
560
- 'void glfwIconifyWindow(void*)',
561
- 'void glfwRestoreWindow(void*)',
562
- 'void glfwMaximizeWindow(void*)', # Available since GLFW 3.2
563
- 'void glfwShowWindow(void*)', # Available since GLFW 3.0
564
- 'void glfwHideWindow(void*)', # Available since GLFW 3.0
565
- 'void glfwFocusWindow(void*)', # Available since GLFW 3.2
566
- 'void glfwRequestWindowAttention(void*)', # Available since GLFW 3.3
567
- 'void* glfwGetWindowMonitor(void*)', # Available since GLFW 3.0
568
- 'void glfwSetWindowMonitor(void*, void*, int, int, int, int, int)', # Available since GLFW 3.2
569
- 'int glfwGetWindowAttrib(void*, int)', # Available since GLFW 3.0
570
- 'void glfwSetWindowAttrib(void*, int, int)', # Available since GLFW 3.3
571
- 'void glfwSetWindowUserPointer(void*, void*)', # Available since GLFW 3.0
572
- 'void* glfwGetWindowUserPointer(void*)', # Available since GLFW 3.0
573
- 'void* glfwSetWindowPosCallback(void*, void*)', # Available since GLFW 3.0
574
- 'void* glfwSetWindowSizeCallback(void*, void*)',
575
- 'void* glfwSetWindowCloseCallback(void*, void*)',
576
- 'void* glfwSetWindowRefreshCallback(void*, void*)',
577
- 'void* glfwSetWindowFocusCallback(void*, void*)', # Available since GLFW 3.0
578
- 'void* glfwSetWindowIconifyCallback(void*, void*)', # Available since GLFW 3.0
579
- 'void* glfwSetWindowMaximizeCallback(void*, void*)', # Available since GLFW 3.3
580
- 'void* glfwSetFramebufferSizeCallback(void*, void*)', # Available since GLFW 3.0
581
- 'void* glfwSetWindowContentScaleCallback(void*, void*)', # Available since GLFW 3.3
582
- 'void glfwPollEvents()',
583
- 'void glfwWaitEvents()',
584
- 'void glfwWaitEventsTimeout(double)', # Available since GLFW 3.2
585
- 'void glfwPostEmptyEvent()', # Available since GLFW 3.1
586
- 'int glfwGetInputMode(void*, int)', # Available since GLFW 3.0
587
- 'void glfwSetInputMode(void*, int, int)', # Available since GLFW 3.0
588
- 'int glfwRawMouseMotionSupported()', # Available since GLFW 3.3
589
- 'const char* glfwGetKeyName(int, int)', # Available since GLFW 3.2
590
- 'int glfwGetKeyScancode(int)', # Available since GLFW 3.3
591
- 'int glfwGetKey(void*, int)',
592
- 'int glfwGetMouseButton(void*, int)',
593
- 'void glfwGetCursorPos(void*, double*, double*)', # Available since GLFW 3.0
594
- 'void glfwSetCursorPos(void*, double, double)', # Available since GLFW 3.0
595
- 'void* glfwCreateCursor(void*, int, int)', # Available since GLFW 3.1
596
- 'void* glfwCreateStandardCursor(int)', # Available since GLFW 3.1
597
- 'void glfwDestroyCursor(void*)', # Available since GLFW 3.1
598
- 'void glfwSetCursor(void*, void*)', # Available since GLFW 3.1
599
- 'void* glfwSetKeyCallback(void*, void*)',
600
- 'void* glfwSetCharCallback(void*, void*)',
601
- 'void* glfwSetCharModsCallback(void*, void*)', # Available since GLFW 3.1 / Scheduled for removal in version 4.0.
602
- 'void* glfwSetMouseButtonCallback(void*, void*)',
603
- 'void* glfwSetCursorPosCallback(void*, void*)', # Available since GLFW 3.0
604
- 'void* glfwSetCursorEnterCallback(void*, void*)', # Available since GLFW 3.0
605
- 'void* glfwSetScrollCallback(void*, void*)', # Available since GLFW 3.0
606
- 'void* glfwSetDropCallback(void*, void*)', # Available since GLFW 3.1
607
-
608
- 'int glfwJoystickPresent(int)', # Available since GLFW 3.0
609
- 'const float* glfwGetJoystickAxes(int, int*)', # Available since GLFW 3.0
610
- 'const unsigned char* glfwGetJoystickButtons(int, int*)',
611
- 'const unsigned char* glfwGetJoystickHats(int, int*)', # Available since GLFW 3.3
612
- 'const char* glfwGetJoystickName(int)', # Available since GLFW 3.0
613
- 'const char* glfwGetJoystickGUID(int)', # Available since GLFW 3.3
614
- 'void glfwSetJoystickUserPointer(int, void*)', # Available since GLFW 3.3
615
- 'void* glfwGetJoystickUserPointer(int)', # Available since GLFW 3.3
616
- 'int glfwJoystickIsGamepad(int)', # Available since GLFW 3.3
617
- 'void* glfwSetJoystickCallback(void*)', # Available since GLFW 3.2
618
- 'int glfwUpdateGamepadMappings(const char*)', # Available since GLFW 3.3
619
- 'const char* glfwGetGamepadName(int)', # Available since GLFW 3.3
620
- 'int glfwGetGamepadState(int, void*)', # Available since GLFW 3.3
621
- 'void glfwSetClipboardString(void*, const char*)', # Available since GLFW 3.0
622
- 'const char* glfwGetClipboardString(void*)', # Available since GLFW 3.0
623
- 'double glfwGetTime()',
624
- 'void glfwSetTime(double)',
625
- 'GLFWuint64 glfwGetTimerValue()', # Available since GLFW 3.2
626
- 'GLFWuint64 glfwGetTimerFrequency()', # Available since GLFW 3.2
627
- 'void glfwMakeContextCurrent(void*)', # Available since GLFW 3.0
628
- 'void* glfwGetCurrentContext()', # Available since GLFW 3.0
629
- 'void glfwSwapBuffers(void*)',
630
- 'void glfwSwapInterval(int)',
631
- 'int glfwExtensionSupported(const char*)',
632
- 'void* glfwGetProcAddress(const char*)',
633
- # >>> Vulkan >>>
634
- 'int glfwVulkanSupported()', # Available since GLFW 3.2
635
- 'const char** glfwGetRequiredInstanceExtensions(unsigned int*)', # Available since GLFW 3.2
636
- # 'GLFWvkproc glfwGetInstanceProcAddress(void*, const char*)',
637
- # 'int glfwGetPhysicalDevicePresentationSupport(void*, void*, unsigned int)',
638
- # 'VkResult glfwCreateWindowSurface(void*, void*, const void*, void*)',
639
- # <<< Vulkan <<<
640
- ]
641
-
642
- def self.import_symbols(output_error = false)
643
- typealias 'GLFWuint64', 'unsigned long long' # Available since GLFW 3.2
644
-
645
- # function
646
- @@lib_signature.each do |sig|
647
- begin
648
- extern sig
649
- rescue
650
- $stderr.puts("[Warning] Failed to import #{sig}.") if output_error
651
- end
652
- end
653
-
654
- ver_major = ' ' * 4
655
- ver_minor = ' ' * 4
656
- ver_rev = ' ' * 4
657
- glfwGetVersion(ver_major, ver_minor, ver_rev)
658
-
659
- GLFW.const_set('GLFW_VERSION_MAJOR', ver_major.unpack('L')[0])
660
- GLFW.const_set('GLFW_VERSION_MINOR', ver_minor.unpack('L')[0])
661
- GLFW.const_set('GLFW_VERSION_REVISION', ver_rev.unpack('L')[0])
662
-
663
- @@glfw_import_done = true
664
- end
665
-
666
- end
667
-
668
- =begin
669
- Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator)
670
- Copyright (c) 2013-2020 vaiorabbit <http://twitter.com/vaiorabbit>
671
-
672
- This software is provided 'as-is', without any express or implied
673
- warranty. In no event will the authors be held liable for any damages
674
- arising from the use of this software.
675
-
676
- Permission is granted to anyone to use this software for any purpose,
677
- including commercial applications, and to alter it and redistribute it
678
- freely, subject to the following restrictions:
679
-
680
- 1. The origin of this software must not be misrepresented; you must not
681
- claim that you wrote the original software. If you use this software
682
- in a product, an acknowledgment in the product documentation would be
683
- appreciated but is not required.
684
-
685
- 2. Altered source versions must be plainly marked as such, and must not be
686
- misrepresented as being the original software.
687
-
688
- 3. This notice may not be removed or altered from any source
689
- distribution.
690
- =end
691
-
1
+ # -*- coding: utf-8 -*-
2
+ # A GLFW wrapper (for version 3.0 - 3.3)
3
+ require 'fiddle/import'
4
+
5
+ module GLFW
6
+
7
+ extend Fiddle::Importer
8
+
9
+ #
10
+ # Fiddle's default 'extern' stores all methods into local variable '@func_map', that makes difficult to 'include GLFW'.
11
+ # So I override it and replace '@func_map' into 'GLFW_FUNCTIONS_MAP'.
12
+ # Ref.: /lib/ruby/2.0.0/fiddle/import.rb
13
+ #
14
+ GLFW_FUNCTIONS_MAP = {}
15
+ def self.extern(signature, *opts)
16
+ symname, ctype, argtype = parse_signature(signature, @type_alias)
17
+ opt = parse_bind_options(opts)
18
+ f = import_function(symname, ctype, argtype, opt[:call_type])
19
+ name = symname.gsub(/@.+/,'')
20
+ GLFW_FUNCTIONS_MAP[name] = f
21
+ begin
22
+ /^(.+?):(\d+)/ =~ caller.first
23
+ file, line = $1, $2.to_i
24
+ rescue
25
+ file, line = __FILE__, __LINE__+3
26
+ end
27
+ args_str="*args"
28
+ module_eval(<<-EOS, file, line)
29
+ def #{name}(*args, &block)
30
+ GLFW_FUNCTIONS_MAP['#{name}'].call(*args,&block)
31
+ end
32
+ EOS
33
+ module_function(name)
34
+ f
35
+ end
36
+
37
+ # defines
38
+ GLFW_TRUE = 1 # Available since GLFW 3.2
39
+ GLFW_FALSE = 0 # Available since GLFW 3.2
40
+
41
+ GLFW_RELEASE = 0
42
+ GLFW_PRESS = 1
43
+ GLFW_REPEAT = 2
44
+
45
+ GLFW_HAT_CENTERED = 0 # Available since GLFW 3.3
46
+ GLFW_HAT_UP = 1 # Available since GLFW 3.3
47
+ GLFW_HAT_RIGHT = 2 # Available since GLFW 3.3
48
+ GLFW_HAT_DOWN = 4 # Available since GLFW 3.3
49
+ GLFW_HAT_LEFT = 8 # Available since GLFW 3.3
50
+ GLFW_HAT_RIGHT_UP = (GLFW_HAT_RIGHT | GLFW_HAT_UP) # Available since GLFW 3.3
51
+ GLFW_HAT_RIGHT_DOWN = (GLFW_HAT_RIGHT | GLFW_HAT_DOWN) # Available since GLFW 3.3
52
+ GLFW_HAT_LEFT_UP = (GLFW_HAT_LEFT | GLFW_HAT_UP) # Available since GLFW 3.3
53
+ GLFW_HAT_LEFT_DOWN = (GLFW_HAT_LEFT | GLFW_HAT_DOWN) # Available since GLFW 3.3
54
+
55
+ GLFW_KEY_UNKNOWN = -1
56
+
57
+ GLFW_KEY_SPACE = 32
58
+ GLFW_KEY_APOSTROPHE = 39 # '
59
+ GLFW_KEY_COMMA = 44 # ,
60
+ GLFW_KEY_MINUS = 45 # -
61
+ GLFW_KEY_PERIOD = 46 # .
62
+ GLFW_KEY_SLASH = 47 # /
63
+ GLFW_KEY_0 = 48
64
+ GLFW_KEY_1 = 49
65
+ GLFW_KEY_2 = 50
66
+ GLFW_KEY_3 = 51
67
+ GLFW_KEY_4 = 52
68
+ GLFW_KEY_5 = 53
69
+ GLFW_KEY_6 = 54
70
+ GLFW_KEY_7 = 55
71
+ GLFW_KEY_8 = 56
72
+ GLFW_KEY_9 = 57
73
+ GLFW_KEY_SEMICOLON = 59 # ;
74
+ GLFW_KEY_EQUAL = 61 # =
75
+ GLFW_KEY_A = 65
76
+ GLFW_KEY_B = 66
77
+ GLFW_KEY_C = 67
78
+ GLFW_KEY_D = 68
79
+ GLFW_KEY_E = 69
80
+ GLFW_KEY_F = 70
81
+ GLFW_KEY_G = 71
82
+ GLFW_KEY_H = 72
83
+ GLFW_KEY_I = 73
84
+ GLFW_KEY_J = 74
85
+ GLFW_KEY_K = 75
86
+ GLFW_KEY_L = 76
87
+ GLFW_KEY_M = 77
88
+ GLFW_KEY_N = 78
89
+ GLFW_KEY_O = 79
90
+ GLFW_KEY_P = 80
91
+ GLFW_KEY_Q = 81
92
+ GLFW_KEY_R = 82
93
+ GLFW_KEY_S = 83
94
+ GLFW_KEY_T = 84
95
+ GLFW_KEY_U = 85
96
+ GLFW_KEY_V = 86
97
+ GLFW_KEY_W = 87
98
+ GLFW_KEY_X = 88
99
+ GLFW_KEY_Y = 89
100
+ GLFW_KEY_Z = 90
101
+ GLFW_KEY_LEFT_BRACKET = 91 # [
102
+ GLFW_KEY_BACKSLASH = 92 # \
103
+ GLFW_KEY_RIGHT_BRACKET = 93 # ]
104
+ GLFW_KEY_GRAVE_ACCENT = 96 # `
105
+ GLFW_KEY_WORLD_1 = 161 # non-US #1
106
+ GLFW_KEY_WORLD_2 = 162 # non-US #2
107
+
108
+ GLFW_KEY_ESCAPE = 256
109
+ GLFW_KEY_ENTER = 257
110
+ GLFW_KEY_TAB = 258
111
+ GLFW_KEY_BACKSPACE = 259
112
+ GLFW_KEY_INSERT = 260
113
+ GLFW_KEY_DELETE = 261
114
+ GLFW_KEY_RIGHT = 262
115
+ GLFW_KEY_LEFT = 263
116
+ GLFW_KEY_DOWN = 264
117
+ GLFW_KEY_UP = 265
118
+ GLFW_KEY_PAGE_UP = 266
119
+ GLFW_KEY_PAGE_DOWN = 267
120
+ GLFW_KEY_HOME = 268
121
+ GLFW_KEY_END = 269
122
+ GLFW_KEY_CAPS_LOCK = 280
123
+ GLFW_KEY_SCROLL_LOCK = 281
124
+ GLFW_KEY_NUM_LOCK = 282
125
+ GLFW_KEY_PRINT_SCREEN = 283
126
+ GLFW_KEY_PAUSE = 284
127
+ GLFW_KEY_F1 = 290
128
+ GLFW_KEY_F2 = 291
129
+ GLFW_KEY_F3 = 292
130
+ GLFW_KEY_F4 = 293
131
+ GLFW_KEY_F5 = 294
132
+ GLFW_KEY_F6 = 295
133
+ GLFW_KEY_F7 = 296
134
+ GLFW_KEY_F8 = 297
135
+ GLFW_KEY_F9 = 298
136
+ GLFW_KEY_F10 = 299
137
+ GLFW_KEY_F11 = 300
138
+ GLFW_KEY_F12 = 301
139
+ GLFW_KEY_F13 = 302
140
+ GLFW_KEY_F14 = 303
141
+ GLFW_KEY_F15 = 304
142
+ GLFW_KEY_F16 = 305
143
+ GLFW_KEY_F17 = 306
144
+ GLFW_KEY_F18 = 307
145
+ GLFW_KEY_F19 = 308
146
+ GLFW_KEY_F20 = 309
147
+ GLFW_KEY_F21 = 310
148
+ GLFW_KEY_F22 = 311
149
+ GLFW_KEY_F23 = 312
150
+ GLFW_KEY_F24 = 313
151
+ GLFW_KEY_F25 = 314
152
+ GLFW_KEY_KP_0 = 320
153
+ GLFW_KEY_KP_1 = 321
154
+ GLFW_KEY_KP_2 = 322
155
+ GLFW_KEY_KP_3 = 323
156
+ GLFW_KEY_KP_4 = 324
157
+ GLFW_KEY_KP_5 = 325
158
+ GLFW_KEY_KP_6 = 326
159
+ GLFW_KEY_KP_7 = 327
160
+ GLFW_KEY_KP_8 = 328
161
+ GLFW_KEY_KP_9 = 329
162
+ GLFW_KEY_KP_DECIMAL = 330
163
+ GLFW_KEY_KP_DIVIDE = 331
164
+ GLFW_KEY_KP_MULTIPLY = 332
165
+ GLFW_KEY_KP_SUBTRACT = 333
166
+ GLFW_KEY_KP_ADD = 334
167
+ GLFW_KEY_KP_ENTER = 335
168
+ GLFW_KEY_KP_EQUAL = 336
169
+ GLFW_KEY_LEFT_SHIFT = 340
170
+ GLFW_KEY_LEFT_CONTROL = 341
171
+ GLFW_KEY_LEFT_ALT = 342
172
+ GLFW_KEY_LEFT_SUPER = 343
173
+ GLFW_KEY_RIGHT_SHIFT = 344
174
+ GLFW_KEY_RIGHT_CONTROL = 345
175
+ GLFW_KEY_RIGHT_ALT = 346
176
+ GLFW_KEY_RIGHT_SUPER = 347
177
+ GLFW_KEY_MENU = 348
178
+ GLFW_KEY_LAST = GLFW_KEY_MENU
179
+
180
+ GLFW_MOD_SHIFT = 0x0001
181
+ GLFW_MOD_CONTROL = 0x0002
182
+ GLFW_MOD_ALT = 0x0004
183
+ GLFW_MOD_SUPER = 0x0008
184
+ GLFW_MOD_CAPS_LOCK = 0x0010 # Available since GLFW 3.3
185
+ GLFW_MOD_NUM_LOCK = 0x0020 # Available since GLFW 3.3
186
+
187
+ GLFW_MOUSE_BUTTON_1 = 0
188
+ GLFW_MOUSE_BUTTON_2 = 1
189
+ GLFW_MOUSE_BUTTON_3 = 2
190
+ GLFW_MOUSE_BUTTON_4 = 3
191
+ GLFW_MOUSE_BUTTON_5 = 4
192
+ GLFW_MOUSE_BUTTON_6 = 5
193
+ GLFW_MOUSE_BUTTON_7 = 6
194
+ GLFW_MOUSE_BUTTON_8 = 7
195
+ GLFW_MOUSE_BUTTON_LAST = GLFW_MOUSE_BUTTON_8
196
+ GLFW_MOUSE_BUTTON_LEFT = GLFW_MOUSE_BUTTON_1
197
+ GLFW_MOUSE_BUTTON_RIGHT = GLFW_MOUSE_BUTTON_2
198
+ GLFW_MOUSE_BUTTON_MIDDLE = GLFW_MOUSE_BUTTON_3
199
+
200
+ GLFW_JOYSTICK_1 = 0
201
+ GLFW_JOYSTICK_2 = 1
202
+ GLFW_JOYSTICK_3 = 2
203
+ GLFW_JOYSTICK_4 = 3
204
+ GLFW_JOYSTICK_5 = 4
205
+ GLFW_JOYSTICK_6 = 5
206
+ GLFW_JOYSTICK_7 = 6
207
+ GLFW_JOYSTICK_8 = 7
208
+ GLFW_JOYSTICK_9 = 8
209
+ GLFW_JOYSTICK_10 = 9
210
+ GLFW_JOYSTICK_11 = 10
211
+ GLFW_JOYSTICK_12 = 11
212
+ GLFW_JOYSTICK_13 = 12
213
+ GLFW_JOYSTICK_14 = 13
214
+ GLFW_JOYSTICK_15 = 14
215
+ GLFW_JOYSTICK_16 = 15
216
+ GLFW_JOYSTICK_LAST = GLFW_JOYSTICK_16
217
+
218
+ GLFW_GAMEPAD_BUTTON_A = 0 # Available since GLFW 3.3
219
+ GLFW_GAMEPAD_BUTTON_B = 1 # Available since GLFW 3.3
220
+ GLFW_GAMEPAD_BUTTON_X = 2 # Available since GLFW 3.3
221
+ GLFW_GAMEPAD_BUTTON_Y = 3 # Available since GLFW 3.3
222
+ GLFW_GAMEPAD_BUTTON_LEFT_BUMPER = 4 # Available since GLFW 3.3
223
+ GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER = 5 # Available since GLFW 3.3
224
+ GLFW_GAMEPAD_BUTTON_BACK = 6 # Available since GLFW 3.3
225
+ GLFW_GAMEPAD_BUTTON_START = 7 # Available since GLFW 3.3
226
+ GLFW_GAMEPAD_BUTTON_GUIDE = 8 # Available since GLFW 3.3
227
+ GLFW_GAMEPAD_BUTTON_LEFT_THUMB = 9 # Available since GLFW 3.3
228
+ GLFW_GAMEPAD_BUTTON_RIGHT_THUMB = 10 # Available since GLFW 3.3
229
+ GLFW_GAMEPAD_BUTTON_DPAD_UP = 11 # Available since GLFW 3.3
230
+ GLFW_GAMEPAD_BUTTON_DPAD_RIGHT = 12 # Available since GLFW 3.3
231
+ GLFW_GAMEPAD_BUTTON_DPAD_DOWN = 13 # Available since GLFW 3.3
232
+ GLFW_GAMEPAD_BUTTON_DPAD_LEFT = 14 # Available since GLFW 3.3
233
+ GLFW_GAMEPAD_BUTTON_LAST = GLFW_GAMEPAD_BUTTON_DPAD_LEFT # Available since GLFW 3.3
234
+
235
+ GLFW_GAMEPAD_BUTTON_CROSS = GLFW_GAMEPAD_BUTTON_A # Available since GLFW 3.3
236
+ GLFW_GAMEPAD_BUTTON_CIRCLE = GLFW_GAMEPAD_BUTTON_B # Available since GLFW 3.3
237
+ GLFW_GAMEPAD_BUTTON_SQUARE = GLFW_GAMEPAD_BUTTON_X # Available since GLFW 3.3
238
+ GLFW_GAMEPAD_BUTTON_TRIANGLE = GLFW_GAMEPAD_BUTTON_Y # Available since GLFW 3.3
239
+
240
+ GLFW_GAMEPAD_AXIS_LEFT_X = 0 # Available since GLFW 3.3
241
+ GLFW_GAMEPAD_AXIS_LEFT_Y = 1 # Available since GLFW 3.3
242
+ GLFW_GAMEPAD_AXIS_RIGHT_X = 2 # Available since GLFW 3.3
243
+ GLFW_GAMEPAD_AXIS_RIGHT_Y = 3 # Available since GLFW 3.3
244
+ GLFW_GAMEPAD_AXIS_LEFT_TRIGGER = 4 # Available since GLFW 3.3
245
+ GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER = 5 # Available since GLFW 3.3
246
+ GLFW_GAMEPAD_AXIS_LAST = GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER # Available since GLFW 3.3
247
+
248
+ GLFW_NO_ERROR = 0 # Available since GLFW 3.3
249
+ GLFW_NOT_INITIALIZED = 0x00010001
250
+ GLFW_NO_CURRENT_CONTEXT = 0x00010002
251
+ GLFW_INVALID_ENUM = 0x00010003
252
+ GLFW_INVALID_VALUE = 0x00010004
253
+ GLFW_OUT_OF_MEMORY = 0x00010005
254
+ GLFW_API_UNAVAILABLE = 0x00010006
255
+ GLFW_VERSION_UNAVAILABLE = 0x00010007
256
+ GLFW_PLATFORM_ERROR = 0x00010008
257
+ GLFW_FORMAT_UNAVAILABLE = 0x00010009
258
+ GLFW_NO_WINDOW_CONTEXT = 0x0001000A # Available since GLFW 3.2
259
+
260
+ GLFW_FOCUSED = 0x00020001
261
+ GLFW_ICONIFIED = 0x00020002
262
+ GLFW_RESIZABLE = 0x00020003
263
+ GLFW_VISIBLE = 0x00020004
264
+ GLFW_DECORATED = 0x00020005
265
+ GLFW_AUTO_ICONIFY = 0x00020006 # Available since GLFW 3.1
266
+ GLFW_FLOATING = 0x00020007 # Available since GLFW 3.1
267
+ GLFW_MAXIMIZED = 0x00020008 # Available since GLFW 3.2
268
+ GLFW_CENTER_CURSOR = 0x00020009 # Available since GLFW 3.3
269
+ GLFW_TRANSPARENT_FRAMEBUFFER = 0x0002000A # Available since GLFW 3.3
270
+ GLFW_HOVERED = 0x0002000B # Available since GLFW 3.3
271
+ GLFW_FOCUS_ON_SHOW = 0x0002000C # Available since GLFW 3.3
272
+
273
+ GLFW_RED_BITS = 0x00021001
274
+ GLFW_GREEN_BITS = 0x00021002
275
+ GLFW_BLUE_BITS = 0x00021003
276
+ GLFW_ALPHA_BITS = 0x00021004
277
+ GLFW_DEPTH_BITS = 0x00021005
278
+ GLFW_STENCIL_BITS = 0x00021006
279
+ GLFW_ACCUM_RED_BITS = 0x00021007
280
+ GLFW_ACCUM_GREEN_BITS = 0x00021008
281
+ GLFW_ACCUM_BLUE_BITS = 0x00021009
282
+ GLFW_ACCUM_ALPHA_BITS = 0x0002100A
283
+ GLFW_AUX_BUFFERS = 0x0002100B
284
+ GLFW_STEREO = 0x0002100C
285
+ GLFW_SAMPLES = 0x0002100D
286
+ GLFW_SRGB_CAPABLE = 0x0002100E
287
+ GLFW_REFRESH_RATE = 0x0002100F
288
+ GLFW_DOUBLEBUFFER = 0x00021010
289
+
290
+ GLFW_CLIENT_API = 0x00022001
291
+ GLFW_CONTEXT_VERSION_MAJOR = 0x00022002
292
+ GLFW_CONTEXT_VERSION_MINOR = 0x00022003
293
+ GLFW_CONTEXT_REVISION = 0x00022004
294
+ GLFW_CONTEXT_ROBUSTNESS = 0x00022005
295
+ GLFW_OPENGL_FORWARD_COMPAT = 0x00022006
296
+ GLFW_OPENGL_DEBUG_CONTEXT = 0x00022007
297
+ GLFW_OPENGL_PROFILE = 0x00022008
298
+ GLFW_CONTEXT_RELEASE_BEHAVIOR = 0x00022009
299
+ GLFW_CONTEXT_NO_ERROR = 0x0002200A
300
+ GLFW_CONTEXT_CREATION_API = 0x0002200B # Available since GLFW 3.2
301
+ GLFW_SCALE_TO_MONITOR = 0x0002200C # Available since GLFW 3.3
302
+
303
+ GLFW_COCOA_RETINA_FRAMEBUFFER = 0x00023001 # Available since GLFW 3.3
304
+ GLFW_COCOA_FRAME_NAME = 0x00023002 # Available since GLFW 3.3
305
+ GLFW_COCOA_GRAPHICS_SWITCHING = 0x00023003 # Available since GLFW 3.3
306
+
307
+ GLFW_X11_CLASS_NAME = 0x00024001 # Available since GLFW 3.3
308
+ GLFW_X11_INSTANCE_NAME = 0x00024002 # Available since GLFW 3.3
309
+
310
+ GLFW_NO_API = 0 # Available since GLFW 3.2
311
+ GLFW_OPENGL_API = 0x00030001
312
+ GLFW_OPENGL_ES_API = 0x00030002
313
+
314
+ GLFW_NO_ROBUSTNESS = 0
315
+ GLFW_NO_RESET_NOTIFICATION = 0x00031001
316
+ GLFW_LOSE_CONTEXT_ON_RESET = 0x00031002
317
+
318
+ GLFW_OPENGL_ANY_PROFILE = 0
319
+ GLFW_OPENGL_CORE_PROFILE = 0x00032001
320
+ GLFW_OPENGL_COMPAT_PROFILE = 0x00032002
321
+
322
+ GLFW_CURSOR = 0x00033001
323
+ GLFW_STICKY_KEYS = 0x00033002
324
+ GLFW_STICKY_MOUSE_BUTTONS = 0x00033003
325
+ GLFW_LOCK_KEY_MODS = 0x00033004 # Available since GLFW 3.3
326
+ GLFW_RAW_MOUSE_MOTION = 0x00033005 # Available since GLFW 3.3
327
+
328
+ GLFW_CURSOR_NORMAL = 0x00034001
329
+ GLFW_CURSOR_HIDDEN = 0x00034002
330
+ GLFW_CURSOR_DISABLED = 0x00034003
331
+
332
+ GLFW_ANY_RELEASE_BEHAVIOR = 0
333
+ GLFW_RELEASE_BEHAVIOR_FLUSH = 0x00035001
334
+ GLFW_RELEASE_BEHAVIOR_NONE = 0x00035002
335
+
336
+ GLFW_NATIVE_CONTEXT_API = 0x00036001 # Available since GLFW 3.2
337
+ GLFW_EGL_CONTEXT_API = 0x00036002 # Available since GLFW 3.2
338
+ GLFW_OSMESA_CONTEXT_API = 0x00036003 # Available since GLFW 3.3
339
+
340
+ GLFW_ARROW_CURSOR = 0x00036001
341
+ GLFW_IBEAM_CURSOR = 0x00036002
342
+ GLFW_CROSSHAIR_CURSOR = 0x00036003
343
+ GLFW_HAND_CURSOR = 0x00036004
344
+ GLFW_HRESIZE_CURSOR = 0x00036005
345
+ GLFW_VRESIZE_CURSOR = 0x00036006
346
+
347
+ GLFW_CONNECTED = 0x00040001
348
+ GLFW_DISCONNECTED = 0x00040002
349
+
350
+ GLFW_JOYSTICK_HAT_BUTTONS = 0x00050001 # Available since GLFW 3.3
351
+
352
+ GLFW_COCOA_CHDIR_RESOURCES = 0x00051001 # Available since GLFW 3.3
353
+ GLFW_COCOA_MENUBAR = 0x00051002 # Available since GLFW 3.3
354
+
355
+ GLFW_DONT_CARE = -1
356
+
357
+ # typedefs
358
+ @@glfw_cb_function_signature = {
359
+ :GLFWerrorfun => "void GLFWerrorfun(int,const char*)",
360
+ :GLFWwindowposfun => "void GLFWwindowposfun(void*,int,int)",
361
+ :GLFWwindowsizefun => "void GLFWwindowsizefun(void*,int,int)",
362
+ :GLFWwindowclosefun => "void GLFWwindowclosefun(void*)",
363
+ :GLFWwindowrefreshfun => "void GLFWwindowrefreshfun(void*)",
364
+ :GLFWwindowfocusfun => "void GLFWwindowfocusfun(void*,int)",
365
+ :GLFWwindowiconifyfun => "void GLFWwindowiconifyfun(void*,int)",
366
+ :GLFWwindowmaximizefun => "void GLFWwindowmaximizefun(void*,int)",
367
+ :GLFWframebuffersizefun => "void GLFWframebuffersizefun(void*,int,int)",
368
+ :GLFWwindowcontentscalefun => "void GLFWwindowcontentscalefun(void*,float,float)", # Available since GLFW 3.3
369
+ :GLFWmousebuttonfun => "void GLFWmousebuttonfun(void*,int,int,int)",
370
+ :GLFWcursorposfun => "void GLFWcursorposfun(void*,double,double)",
371
+ :GLFWcursorenterfun => "void GLFWcursorenterfun(void*,int)",
372
+ :GLFWscrollfun => "void GLFWscrollfun(void*,double,double)",
373
+ :GLFWkeyfun => "void GLFWkeyfun(void*,int,int,int,int)",
374
+ :GLFWcharfun => "void GLFWcharfun(void*,unsigned int)",
375
+ :GLFWcharmodsfun => "void GLFWcharmodsfun(void*,unsigned int,int)", # Available since GLFW 3.1 / Scheduled for removal in version 4.0.
376
+ :GLFWdropfun => "void GLFWdropfun(void*,int,const char**)", # Available since GLFW 3.1
377
+ :GLFWmonitorfun => "void GLFWmonitorfun(void*,int)", # Available since GLFW 3.0
378
+ :GLFWjoystickfun => "void GGLFWjoystickfun(int,int)", # Available since GLFW 3.2
379
+ }
380
+
381
+ # Creates a callback as an instance of Fiddle::Function
382
+ def self.create_callback_function( sym, proc=nil, &blk )
383
+ if block_given?
384
+ return bind( @@glfw_cb_function_signature[sym], nil, &blk )
385
+ else
386
+ return bind( @@glfw_cb_function_signature[sym], nil, &proc )
387
+ end
388
+ end
389
+
390
+ GLFWerrorfun_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]
391
+ GLFWerrorfun_cb_retval = Fiddle::TYPE_VOID
392
+ GLFWwindowposfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
393
+ GLFWwindowposfun_cb_retval = Fiddle::TYPE_VOID
394
+ GLFWwindowsizefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
395
+ GLFWwindowsizefun_cb_retval = Fiddle::TYPE_VOID
396
+ GLFWwindowclosefun_cb_args = [Fiddle::TYPE_VOIDP]
397
+ GLFWwindowclosefun_cb_retval = Fiddle::TYPE_VOID
398
+ GLFWwindowrefreshfun_cb_args = [Fiddle::TYPE_VOIDP]
399
+ GLFWwindowrefreshfun_cb_retval = Fiddle::TYPE_VOID
400
+ GLFWwindowfocusfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
401
+ GLFWwindowfocusfun_cb_retval = Fiddle::TYPE_VOID
402
+ GLFWwindowiconifyfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
403
+ GLFWwindowiconifyfun_cb_retval = Fiddle::TYPE_VOID
404
+ GLFWframebuffersizefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
405
+ GLFWframebuffersizefun_cb_retval = Fiddle::TYPE_VOID
406
+ GLFWwindowcontentscalefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_FLOAT, Fiddle::TYPE_FLOAT] # Available since GLFW 3.3
407
+ GLFWwindowcontentscalefun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.3
408
+ GLFWmousebuttonfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
409
+ GLFWmousebuttonfun_cb_retval = Fiddle::TYPE_VOID
410
+ GLFWcursorposfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]
411
+ GLFWcursorposfun_cb_retval = Fiddle::TYPE_VOID
412
+ GLFWcursorenterfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
413
+ GLFWcursorenterfun_cb_retval = Fiddle::TYPE_VOID
414
+ GLFWscrollfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]
415
+ GLFWscrollfun_cb_retval = Fiddle::TYPE_VOID
416
+ GLFWkeyfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
417
+ GLFWkeyfun_cb_retval = Fiddle::TYPE_VOID
418
+ GLFWcharfun_cb_args = [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]
419
+ GLFWcharfun_cb_retval = Fiddle::TYPE_VOID
420
+ GLFWcharmodsfun_cb_args = [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT] # Available since GLFW 3.1
421
+ GLFWcharmodsfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.1
422
+ GLFWdropfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP] # Available since GLFW 3.1
423
+ GLFWdropfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.1
424
+ GLFWmonitorfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT] # Available since GLFW 3.0
425
+ GLFWmonitorfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.0
426
+ GLFWjoystickfun_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT] # Available since GLFW 3.2
427
+ GLFWjoystickfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.2
428
+
429
+ @@glfw_cb_closure_signature = {
430
+ :GLFWerrorfun => [GLFWerrorfun_cb_retval, GLFWerrorfun_cb_args],
431
+ :GLFWwindowposfun => [GLFWwindowposfun_cb_retval, GLFWwindowposfun_cb_args],
432
+ :GLFWwindowsizefun => [GLFWwindowsizefun_cb_retval, GLFWwindowsizefun_cb_args],
433
+ :GLFWwindowclosefun => [GLFWwindowclosefun_cb_retval, GLFWwindowclosefun_cb_args],
434
+ :GLFWwindowrefreshfun => [GLFWwindowrefreshfun_cb_retval, GLFWwindowrefreshfun_cb_args],
435
+ :GLFWwindowfocusfun => [GLFWwindowfocusfun_cb_retval, GLFWwindowfocusfun_cb_args],
436
+ :GLFWwindowiconifyfun => [GLFWwindowiconifyfun_cb_retval, GLFWwindowiconifyfun_cb_args],
437
+ :GLFWframebuffersizefun => [GLFWframebuffersizefun_cb_retval, GLFWframebuffersizefun_cb_args],
438
+ :GLFWwindowcontentscalefun => [GLFWwindowcontentscalefun_cb_retval, GLFWwindowcontentscalefun_cb_args], # Available since GLFW 3.3
439
+ :GLFWmousebuttonfun => [GLFWmousebuttonfun_cb_retval, GLFWmousebuttonfun_cb_args],
440
+ :GLFWcursorposfun => [GLFWcursorposfun_cb_retval, GLFWcursorposfun_cb_args],
441
+ :GLFWcursorenterfun => [GLFWcursorenterfun_cb_retval, GLFWcursorenterfun_cb_args],
442
+ :GLFWscrollfun => [GLFWscrollfun_cb_retval, GLFWscrollfun_cb_args],
443
+ :GLFWkeyfun => [GLFWkeyfun_cb_retval, GLFWkeyfun_cb_args],
444
+ :GLFWcharfun => [GLFWcharfun_cb_retval, GLFWcharfun_cb_args],
445
+ :GLFWcharmodsfun => [GLFWcharmodsfun_cb_retval, GLFWcharmodsfun_cb_args], # Available since GLFW 3.1
446
+ :GLFWdropfun => [GLFWdropfun_cb_retval, GLFWdropfun_cb_args], # Available since GLFW 3.1
447
+ :GLFWmonitorfun => [GLFWmonitorfun_cb_retval, GLFWmonitorfun_cb_args],
448
+ :GLFWjoystickfun => [GLFWjoystickfun_cb_retval, GLFWjoystickfun_cb_args], # Available since GLFW 3.2
449
+ }
450
+
451
+ # Creates a callback as an instance of Fiddle::Closure::BlockCaller
452
+ def self.create_callback_closure( sym, proc=nil, &blk )
453
+ cb_retval = @@glfw_cb_closure_signature[sym][0]
454
+ cb_args = @@glfw_cb_closure_signature[sym][1]
455
+ if block_given?
456
+ return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &blk )
457
+ else
458
+ return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &proc )
459
+ end
460
+ end
461
+
462
+ # NOTE : Use 'create_callback_function' for backward compatibility.
463
+ def self.create_callback( sym, proc=nil, &blk )
464
+ return self.create_callback_closure( sym, proc, &blk )
465
+ end
466
+
467
+ # struct
468
+ GLFWvidmode = struct(["int width",
469
+ "int height",
470
+ "int redBits",
471
+ "int greenBits",
472
+ "int blueBits",
473
+ "int refreshRate"])
474
+
475
+ GLFWgammaramp = struct(["unsigned short* red",
476
+ "unsigned short* green",
477
+ "unsigned short* blue",
478
+ "unsigned int size"])
479
+
480
+ # Available since GLFW 3.1
481
+ GLFWimage = struct(["int width",
482
+ "int height",
483
+ "unsigned char* pixels"])
484
+
485
+ # Available since GLFW 3.3
486
+ GLFWgamepadstate = struct(["unsigned char buttons[15]",
487
+ "float axes[6]"])
488
+
489
+ @@glfw_import_done = false
490
+
491
+ # Load native library.
492
+ def self.load_lib(lib = nil, path = nil, output_error = false)
493
+ if lib == nil && path == nil
494
+ case OpenGL.get_platform
495
+ when :OPENGL_PLATFORM_WINDOWS
496
+ lib, path = 'GLFW3.dll', Dir.pwd
497
+ when :OPENGL_PLATFORM_MACOSX
498
+ lib, path = 'libglfw.dylib', Dir.pwd
499
+ else
500
+ lib = 'libglfw.so'
501
+ end
502
+ end
503
+
504
+ if path
505
+ dlload (path + '/' + lib)
506
+ else
507
+ dlload (lib)
508
+ end
509
+ import_symbols(output_error) unless @@glfw_import_done
510
+ end
511
+
512
+ def self.load_dll(lib = nil, path = nil)
513
+ puts "Warning GLFW.load_dll is deprecated, use GLFW.load_lib instead"
514
+ self.load_lib(lib, path)
515
+ end
516
+
517
+ @@lib_signature = [
518
+ 'int glfwInit()',
519
+ 'void glfwTerminate()',
520
+ 'void glfwInitHint(int, int)', # Available since GLFW 3.3
521
+ 'void glfwGetVersion(int*, int*, int*)',
522
+ 'const char* glfwGetVersionString()',
523
+ 'int glfwGetError(const char**)', # Available since GLFW 3.3
524
+ 'void* glfwSetErrorCallback(void*)',
525
+ 'void** glfwGetMonitors(int*)',
526
+ 'void* glfwGetPrimaryMonitor()',
527
+ 'void glfwGetMonitorPos(void*, int*, int*)',
528
+ 'void glfwGetMonitorWorkarea(void* monitor, int*, int*, int*, int*)', # Available since GLFW 3.3
529
+ 'void glfwGetMonitorPhysicalSize(void*, int*, int*)',
530
+ 'void glfwGetMonitorContentScale(void*, float*, float*)', # Available since GLFW 3.3
531
+ 'const char* glfwGetMonitorName(void*)',
532
+ 'void glfwSetMonitorUserPointer(void*, void*)', # Available since GLFW 3.3
533
+ 'const void* glfwGetMonitorUserPointer(void**)', # Available since GLFW 3.3
534
+ 'void* glfwSetMonitorCallback(void*)', # Available since GLFW 3.0
535
+ 'const void* glfwGetVideoModes(void*, int*)',
536
+ 'const void* glfwGetVideoMode(void*)', # Available since GLFW 3.0
537
+ 'void glfwSetGamma(void*, float)', # Available since GLFW 3.0
538
+ 'const void* glfwGetGammaRamp(void*)', # Available since GLFW 3.0
539
+ 'void glfwSetGammaRamp(void*, const void*)', # Available since GLFW 3.0
540
+ 'void glfwDefaultWindowHints()', # Available since GLFW 3.0
541
+ 'void glfwWindowHint(int, int)', # Available since GLFW 3.0
542
+ 'void glfwWindowHintString(int, const char*)', # Available since GLFW 3.3
543
+ 'void* glfwCreateWindow(int, int, const char*, void*, void*)', # Available since GLFW 3.0
544
+ 'void glfwDestroyWindow(void*)', # Available since GLFW 3.0
545
+ 'int glfwWindowShouldClose(void*)', # Available since GLFW 3.0
546
+ 'void glfwSetWindowShouldClose(void* window, int)', # Available since GLFW 3.0
547
+ 'void glfwSetWindowTitle(void*, const char*)',
548
+ 'void glfwSetWindowIcon(void*, int, void*)', # Available since GLFW 3.2
549
+ 'void glfwGetWindowPos(void*, int*, int*)', # Available since GLFW 3.0
550
+ 'void glfwSetWindowPos(void*, int, int)',
551
+ 'void glfwGetWindowSize(void*, int*, int*)',
552
+ 'void glfwSetWindowSizeLimits(void*, int, int, int, int)', # Available since GLFW 3.2
553
+ 'void glfwSetWindowAspectRatio(void*, int, int)', # Available since GLFW 3.2
554
+ 'void glfwSetWindowSize(void*, int, int)',
555
+ 'void glfwGetFramebufferSize(void*, int*, int*)', # Available since GLFW 3.0
556
+ 'void glfwGetWindowFrameSize(void*, int*, int*, int*, int*)', # Available since GLFW 3.1
557
+ 'void glfwGetWindowContentScale(void*, float*, float*)', # Available since GLFW 3.3
558
+ 'float glfwGetWindowOpacity(void*)', # Available since GLFW 3.3
559
+ 'void glfwSetWindowOpacity(void*, float)', # Available since GLFW 3.3
560
+ 'void glfwIconifyWindow(void*)',
561
+ 'void glfwRestoreWindow(void*)',
562
+ 'void glfwMaximizeWindow(void*)', # Available since GLFW 3.2
563
+ 'void glfwShowWindow(void*)', # Available since GLFW 3.0
564
+ 'void glfwHideWindow(void*)', # Available since GLFW 3.0
565
+ 'void glfwFocusWindow(void*)', # Available since GLFW 3.2
566
+ 'void glfwRequestWindowAttention(void*)', # Available since GLFW 3.3
567
+ 'void* glfwGetWindowMonitor(void*)', # Available since GLFW 3.0
568
+ 'void glfwSetWindowMonitor(void*, void*, int, int, int, int, int)', # Available since GLFW 3.2
569
+ 'int glfwGetWindowAttrib(void*, int)', # Available since GLFW 3.0
570
+ 'void glfwSetWindowAttrib(void*, int, int)', # Available since GLFW 3.3
571
+ 'void glfwSetWindowUserPointer(void*, void*)', # Available since GLFW 3.0
572
+ 'void* glfwGetWindowUserPointer(void*)', # Available since GLFW 3.0
573
+ 'void* glfwSetWindowPosCallback(void*, void*)', # Available since GLFW 3.0
574
+ 'void* glfwSetWindowSizeCallback(void*, void*)',
575
+ 'void* glfwSetWindowCloseCallback(void*, void*)',
576
+ 'void* glfwSetWindowRefreshCallback(void*, void*)',
577
+ 'void* glfwSetWindowFocusCallback(void*, void*)', # Available since GLFW 3.0
578
+ 'void* glfwSetWindowIconifyCallback(void*, void*)', # Available since GLFW 3.0
579
+ 'void* glfwSetWindowMaximizeCallback(void*, void*)', # Available since GLFW 3.3
580
+ 'void* glfwSetFramebufferSizeCallback(void*, void*)', # Available since GLFW 3.0
581
+ 'void* glfwSetWindowContentScaleCallback(void*, void*)', # Available since GLFW 3.3
582
+ 'void glfwPollEvents()',
583
+ 'void glfwWaitEvents()',
584
+ 'void glfwWaitEventsTimeout(double)', # Available since GLFW 3.2
585
+ 'void glfwPostEmptyEvent()', # Available since GLFW 3.1
586
+ 'int glfwGetInputMode(void*, int)', # Available since GLFW 3.0
587
+ 'void glfwSetInputMode(void*, int, int)', # Available since GLFW 3.0
588
+ 'int glfwRawMouseMotionSupported()', # Available since GLFW 3.3
589
+ 'const char* glfwGetKeyName(int, int)', # Available since GLFW 3.2
590
+ 'int glfwGetKeyScancode(int)', # Available since GLFW 3.3
591
+ 'int glfwGetKey(void*, int)',
592
+ 'int glfwGetMouseButton(void*, int)',
593
+ 'void glfwGetCursorPos(void*, double*, double*)', # Available since GLFW 3.0
594
+ 'void glfwSetCursorPos(void*, double, double)', # Available since GLFW 3.0
595
+ 'void* glfwCreateCursor(void*, int, int)', # Available since GLFW 3.1
596
+ 'void* glfwCreateStandardCursor(int)', # Available since GLFW 3.1
597
+ 'void glfwDestroyCursor(void*)', # Available since GLFW 3.1
598
+ 'void glfwSetCursor(void*, void*)', # Available since GLFW 3.1
599
+ 'void* glfwSetKeyCallback(void*, void*)',
600
+ 'void* glfwSetCharCallback(void*, void*)',
601
+ 'void* glfwSetCharModsCallback(void*, void*)', # Available since GLFW 3.1 / Scheduled for removal in version 4.0.
602
+ 'void* glfwSetMouseButtonCallback(void*, void*)',
603
+ 'void* glfwSetCursorPosCallback(void*, void*)', # Available since GLFW 3.0
604
+ 'void* glfwSetCursorEnterCallback(void*, void*)', # Available since GLFW 3.0
605
+ 'void* glfwSetScrollCallback(void*, void*)', # Available since GLFW 3.0
606
+ 'void* glfwSetDropCallback(void*, void*)', # Available since GLFW 3.1
607
+
608
+ 'int glfwJoystickPresent(int)', # Available since GLFW 3.0
609
+ 'const float* glfwGetJoystickAxes(int, int*)', # Available since GLFW 3.0
610
+ 'const unsigned char* glfwGetJoystickButtons(int, int*)',
611
+ 'const unsigned char* glfwGetJoystickHats(int, int*)', # Available since GLFW 3.3
612
+ 'const char* glfwGetJoystickName(int)', # Available since GLFW 3.0
613
+ 'const char* glfwGetJoystickGUID(int)', # Available since GLFW 3.3
614
+ 'void glfwSetJoystickUserPointer(int, void*)', # Available since GLFW 3.3
615
+ 'void* glfwGetJoystickUserPointer(int)', # Available since GLFW 3.3
616
+ 'int glfwJoystickIsGamepad(int)', # Available since GLFW 3.3
617
+ 'void* glfwSetJoystickCallback(void*)', # Available since GLFW 3.2
618
+ 'int glfwUpdateGamepadMappings(const char*)', # Available since GLFW 3.3
619
+ 'const char* glfwGetGamepadName(int)', # Available since GLFW 3.3
620
+ 'int glfwGetGamepadState(int, void*)', # Available since GLFW 3.3
621
+ 'void glfwSetClipboardString(void*, const char*)', # Available since GLFW 3.0
622
+ 'const char* glfwGetClipboardString(void*)', # Available since GLFW 3.0
623
+ 'double glfwGetTime()',
624
+ 'void glfwSetTime(double)',
625
+ 'GLFWuint64 glfwGetTimerValue()', # Available since GLFW 3.2
626
+ 'GLFWuint64 glfwGetTimerFrequency()', # Available since GLFW 3.2
627
+ 'void glfwMakeContextCurrent(void*)', # Available since GLFW 3.0
628
+ 'void* glfwGetCurrentContext()', # Available since GLFW 3.0
629
+ 'void glfwSwapBuffers(void*)',
630
+ 'void glfwSwapInterval(int)',
631
+ 'int glfwExtensionSupported(const char*)',
632
+ 'void* glfwGetProcAddress(const char*)',
633
+ # >>> Vulkan >>>
634
+ 'int glfwVulkanSupported()', # Available since GLFW 3.2
635
+ 'const char** glfwGetRequiredInstanceExtensions(unsigned int*)', # Available since GLFW 3.2
636
+ # 'GLFWvkproc glfwGetInstanceProcAddress(void*, const char*)',
637
+ # 'int glfwGetPhysicalDevicePresentationSupport(void*, void*, unsigned int)',
638
+ # 'VkResult glfwCreateWindowSurface(void*, void*, const void*, void*)',
639
+ # <<< Vulkan <<<
640
+ ]
641
+
642
+ case OpenGL.get_platform
643
+ when :OPENGL_PLATFORM_WINDOWS
644
+ @@lib_signature << 'const char* glfwGetWin32Adapter(void*)'
645
+ @@lib_signature << 'const char* glfwGetWin32Monitor(void*)'
646
+ @@lib_signature << 'void* glfwGetWin32Window(void*)'
647
+ @@lib_signature << 'void* glfwGetWGLContext(void*)'
648
+ when :OPENGL_PLATFORM_MACOSX
649
+ @@lib_signature << 'unsigned int glfwGetCocoaMonitor(void*)'
650
+ @@lib_signature << 'void* glfwGetCocoaWindow(void*)'
651
+ @@lib_signature << 'void* glfwGetNSGLContext(void*)'
652
+ when :OPENGL_PLATFORM_LINUX
653
+ @@lib_signature << 'void* glfwGetX11Display()'
654
+ @@lib_signature << 'unsinged long glfwGetX11Adapter(void*)'
655
+ @@lib_signature << 'unsinged long glfwGetX11Monitor(void*)'
656
+ @@lib_signature << 'unsinged long glfwGetX11Window(void*)'
657
+ @@lib_signature << 'void glfwSetX11SelectionString(const char*)'
658
+ @@lib_signature << 'const char* glfwGetX11SelectionString()'
659
+ @@lib_signature << 'unsinged long glfwGetGLXWindow(void*)'
660
+ end
661
+
662
+ def self.import_symbols(output_error = false)
663
+ typealias 'GLFWuint64', 'unsigned long long' # Available since GLFW 3.2
664
+
665
+ # function
666
+ @@lib_signature.each do |sig|
667
+ begin
668
+ extern sig
669
+ rescue
670
+ $stderr.puts("[Warning] Failed to import #{sig}.") if output_error
671
+ end
672
+ end
673
+
674
+ ver_major = ' ' * 4
675
+ ver_minor = ' ' * 4
676
+ ver_rev = ' ' * 4
677
+ glfwGetVersion(ver_major, ver_minor, ver_rev)
678
+
679
+ GLFW.const_set('GLFW_VERSION_MAJOR', ver_major.unpack('L')[0])
680
+ GLFW.const_set('GLFW_VERSION_MINOR', ver_minor.unpack('L')[0])
681
+ GLFW.const_set('GLFW_VERSION_REVISION', ver_rev.unpack('L')[0])
682
+
683
+ @@glfw_import_done = true
684
+ end
685
+
686
+ end
687
+
688
+ =begin
689
+ Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator)
690
+ Copyright (c) 2013-2021 vaiorabbit <http://twitter.com/vaiorabbit>
691
+
692
+ This software is provided 'as-is', without any express or implied
693
+ warranty. In no event will the authors be held liable for any damages
694
+ arising from the use of this software.
695
+
696
+ Permission is granted to anyone to use this software for any purpose,
697
+ including commercial applications, and to alter it and redistribute it
698
+ freely, subject to the following restrictions:
699
+
700
+ 1. The origin of this software must not be misrepresented; you must not
701
+ claim that you wrote the original software. If you use this software
702
+ in a product, an acknowledgment in the product documentation would be
703
+ appreciated but is not required.
704
+
705
+ 2. Altered source versions must be plainly marked as such, and must not be
706
+ misrepresented as being the original software.
707
+
708
+ 3. This notice may not be removed or altered from any source
709
+ distribution.
710
+ =end
711
+