opengl-bindings 1.6.14 → 1.6.15

Sign up to get free protection for your applications and to get access to all the features.
data/lib/glfw33.rb ADDED
@@ -0,0 +1,716 @@
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_WAYLAND_PREFER_LIBDECOR = 0x00038001 # Available since GLFW 3.3.9
341
+ GLFW_WAYLAND_DISABLE_LIBDECOR = 0x00038002 # Available since GLFW 3.3.9
342
+
343
+ GLFW_ARROW_CURSOR = 0x00036001
344
+ GLFW_IBEAM_CURSOR = 0x00036002
345
+ GLFW_CROSSHAIR_CURSOR = 0x00036003
346
+ GLFW_HAND_CURSOR = 0x00036004
347
+ GLFW_HRESIZE_CURSOR = 0x00036005
348
+ GLFW_VRESIZE_CURSOR = 0x00036006
349
+
350
+ GLFW_CONNECTED = 0x00040001
351
+ GLFW_DISCONNECTED = 0x00040002
352
+
353
+ GLFW_JOYSTICK_HAT_BUTTONS = 0x00050001 # Available since GLFW 3.3
354
+
355
+ GLFW_COCOA_CHDIR_RESOURCES = 0x00051001 # Available since GLFW 3.3
356
+ GLFW_COCOA_MENUBAR = 0x00051002 # Available since GLFW 3.3
357
+
358
+ GLFW_WAYLAND_LIBDECOR = 0x00053001 # Available since GLFW 3.3.9
359
+
360
+ GLFW_DONT_CARE = -1
361
+
362
+ # typedefs
363
+ @@glfw_cb_function_signature = {
364
+ :GLFWerrorfun => "void GLFWerrorfun(int,const char*)",
365
+ :GLFWwindowposfun => "void GLFWwindowposfun(void*,int,int)",
366
+ :GLFWwindowsizefun => "void GLFWwindowsizefun(void*,int,int)",
367
+ :GLFWwindowclosefun => "void GLFWwindowclosefun(void*)",
368
+ :GLFWwindowrefreshfun => "void GLFWwindowrefreshfun(void*)",
369
+ :GLFWwindowfocusfun => "void GLFWwindowfocusfun(void*,int)",
370
+ :GLFWwindowiconifyfun => "void GLFWwindowiconifyfun(void*,int)",
371
+ :GLFWwindowmaximizefun => "void GLFWwindowmaximizefun(void*,int)",
372
+ :GLFWframebuffersizefun => "void GLFWframebuffersizefun(void*,int,int)",
373
+ :GLFWwindowcontentscalefun => "void GLFWwindowcontentscalefun(void*,float,float)", # Available since GLFW 3.3
374
+ :GLFWmousebuttonfun => "void GLFWmousebuttonfun(void*,int,int,int)",
375
+ :GLFWcursorposfun => "void GLFWcursorposfun(void*,double,double)",
376
+ :GLFWcursorenterfun => "void GLFWcursorenterfun(void*,int)",
377
+ :GLFWscrollfun => "void GLFWscrollfun(void*,double,double)",
378
+ :GLFWkeyfun => "void GLFWkeyfun(void*,int,int,int,int)",
379
+ :GLFWcharfun => "void GLFWcharfun(void*,unsigned int)",
380
+ :GLFWcharmodsfun => "void GLFWcharmodsfun(void*,unsigned int,int)", # Available since GLFW 3.1 / Scheduled for removal in version 4.0.
381
+ :GLFWdropfun => "void GLFWdropfun(void*,int,const char**)", # Available since GLFW 3.1
382
+ :GLFWmonitorfun => "void GLFWmonitorfun(void*,int)", # Available since GLFW 3.0
383
+ :GLFWjoystickfun => "void GGLFWjoystickfun(int,int)", # Available since GLFW 3.2
384
+ }
385
+
386
+ # Creates a callback as an instance of Fiddle::Function
387
+ def self.create_callback_function( sym, proc=nil, &blk )
388
+ if block_given?
389
+ return bind( @@glfw_cb_function_signature[sym], nil, &blk )
390
+ else
391
+ return bind( @@glfw_cb_function_signature[sym], nil, &proc )
392
+ end
393
+ end
394
+
395
+ GLFWerrorfun_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]
396
+ GLFWerrorfun_cb_retval = Fiddle::TYPE_VOID
397
+ GLFWwindowposfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
398
+ GLFWwindowposfun_cb_retval = Fiddle::TYPE_VOID
399
+ GLFWwindowsizefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
400
+ GLFWwindowsizefun_cb_retval = Fiddle::TYPE_VOID
401
+ GLFWwindowclosefun_cb_args = [Fiddle::TYPE_VOIDP]
402
+ GLFWwindowclosefun_cb_retval = Fiddle::TYPE_VOID
403
+ GLFWwindowrefreshfun_cb_args = [Fiddle::TYPE_VOIDP]
404
+ GLFWwindowrefreshfun_cb_retval = Fiddle::TYPE_VOID
405
+ GLFWwindowfocusfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
406
+ GLFWwindowfocusfun_cb_retval = Fiddle::TYPE_VOID
407
+ GLFWwindowiconifyfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
408
+ GLFWwindowiconifyfun_cb_retval = Fiddle::TYPE_VOID
409
+ GLFWframebuffersizefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
410
+ GLFWframebuffersizefun_cb_retval = Fiddle::TYPE_VOID
411
+ GLFWwindowcontentscalefun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_FLOAT, Fiddle::TYPE_FLOAT] # Available since GLFW 3.3
412
+ GLFWwindowcontentscalefun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.3
413
+ GLFWmousebuttonfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
414
+ GLFWmousebuttonfun_cb_retval = Fiddle::TYPE_VOID
415
+ GLFWcursorposfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]
416
+ GLFWcursorposfun_cb_retval = Fiddle::TYPE_VOID
417
+ GLFWcursorenterfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]
418
+ GLFWcursorenterfun_cb_retval = Fiddle::TYPE_VOID
419
+ GLFWscrollfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]
420
+ GLFWscrollfun_cb_retval = Fiddle::TYPE_VOID
421
+ GLFWkeyfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
422
+ GLFWkeyfun_cb_retval = Fiddle::TYPE_VOID
423
+ GLFWcharfun_cb_args = [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]
424
+ GLFWcharfun_cb_retval = Fiddle::TYPE_VOID
425
+ GLFWcharmodsfun_cb_args = [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT] # Available since GLFW 3.1
426
+ GLFWcharmodsfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.1
427
+ GLFWdropfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP] # Available since GLFW 3.1
428
+ GLFWdropfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.1
429
+ GLFWmonitorfun_cb_args = [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT] # Available since GLFW 3.0
430
+ GLFWmonitorfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.0
431
+ GLFWjoystickfun_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT] # Available since GLFW 3.2
432
+ GLFWjoystickfun_cb_retval = Fiddle::TYPE_VOID # Available since GLFW 3.2
433
+
434
+ @@glfw_cb_closure_signature = {
435
+ :GLFWerrorfun => [GLFWerrorfun_cb_retval, GLFWerrorfun_cb_args],
436
+ :GLFWwindowposfun => [GLFWwindowposfun_cb_retval, GLFWwindowposfun_cb_args],
437
+ :GLFWwindowsizefun => [GLFWwindowsizefun_cb_retval, GLFWwindowsizefun_cb_args],
438
+ :GLFWwindowclosefun => [GLFWwindowclosefun_cb_retval, GLFWwindowclosefun_cb_args],
439
+ :GLFWwindowrefreshfun => [GLFWwindowrefreshfun_cb_retval, GLFWwindowrefreshfun_cb_args],
440
+ :GLFWwindowfocusfun => [GLFWwindowfocusfun_cb_retval, GLFWwindowfocusfun_cb_args],
441
+ :GLFWwindowiconifyfun => [GLFWwindowiconifyfun_cb_retval, GLFWwindowiconifyfun_cb_args],
442
+ :GLFWframebuffersizefun => [GLFWframebuffersizefun_cb_retval, GLFWframebuffersizefun_cb_args],
443
+ :GLFWwindowcontentscalefun => [GLFWwindowcontentscalefun_cb_retval, GLFWwindowcontentscalefun_cb_args], # Available since GLFW 3.3
444
+ :GLFWmousebuttonfun => [GLFWmousebuttonfun_cb_retval, GLFWmousebuttonfun_cb_args],
445
+ :GLFWcursorposfun => [GLFWcursorposfun_cb_retval, GLFWcursorposfun_cb_args],
446
+ :GLFWcursorenterfun => [GLFWcursorenterfun_cb_retval, GLFWcursorenterfun_cb_args],
447
+ :GLFWscrollfun => [GLFWscrollfun_cb_retval, GLFWscrollfun_cb_args],
448
+ :GLFWkeyfun => [GLFWkeyfun_cb_retval, GLFWkeyfun_cb_args],
449
+ :GLFWcharfun => [GLFWcharfun_cb_retval, GLFWcharfun_cb_args],
450
+ :GLFWcharmodsfun => [GLFWcharmodsfun_cb_retval, GLFWcharmodsfun_cb_args], # Available since GLFW 3.1
451
+ :GLFWdropfun => [GLFWdropfun_cb_retval, GLFWdropfun_cb_args], # Available since GLFW 3.1
452
+ :GLFWmonitorfun => [GLFWmonitorfun_cb_retval, GLFWmonitorfun_cb_args],
453
+ :GLFWjoystickfun => [GLFWjoystickfun_cb_retval, GLFWjoystickfun_cb_args], # Available since GLFW 3.2
454
+ }
455
+
456
+ # Creates a callback as an instance of Fiddle::Closure::BlockCaller
457
+ def self.create_callback_closure( sym, proc=nil, &blk )
458
+ cb_retval = @@glfw_cb_closure_signature[sym][0]
459
+ cb_args = @@glfw_cb_closure_signature[sym][1]
460
+ if block_given?
461
+ return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &blk )
462
+ else
463
+ return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &proc )
464
+ end
465
+ end
466
+
467
+ # NOTE : Use 'create_callback_function' for backward compatibility.
468
+ def self.create_callback( sym, proc=nil, &blk )
469
+ return self.create_callback_closure( sym, proc, &blk )
470
+ end
471
+
472
+ # struct
473
+ GLFWvidmode = struct(["int width",
474
+ "int height",
475
+ "int redBits",
476
+ "int greenBits",
477
+ "int blueBits",
478
+ "int refreshRate"])
479
+
480
+ GLFWgammaramp = struct(["unsigned short* red",
481
+ "unsigned short* green",
482
+ "unsigned short* blue",
483
+ "unsigned int size"])
484
+
485
+ # Available since GLFW 3.1
486
+ GLFWimage = struct(["int width",
487
+ "int height",
488
+ "unsigned char* pixels"])
489
+
490
+ # Available since GLFW 3.3
491
+ GLFWgamepadstate = struct(["unsigned char buttons[15]",
492
+ "float axes[6]"])
493
+
494
+ @@glfw_import_done = false
495
+
496
+ # Load native library.
497
+ def self.load_lib(lib = nil, path = nil, output_error = false)
498
+ if lib == nil && path == nil
499
+ case OpenGL.get_platform
500
+ when :OPENGL_PLATFORM_WINDOWS
501
+ lib, path = 'GLFW3.dll', Dir.pwd
502
+ when :OPENGL_PLATFORM_MACOSX
503
+ lib, path = 'libglfw.dylib', Dir.pwd
504
+ else
505
+ lib = 'libglfw.so.3'
506
+ end
507
+ end
508
+
509
+ if path
510
+ dlload (path + '/' + lib)
511
+ else
512
+ dlload (lib)
513
+ end
514
+ import_symbols(output_error) unless @@glfw_import_done
515
+ end
516
+
517
+ def self.load_dll(lib = nil, path = nil)
518
+ puts "Warning GLFW.load_dll is deprecated, use GLFW.load_lib instead"
519
+ self.load_lib(lib, path)
520
+ end
521
+
522
+ @@lib_signature = [
523
+ 'int glfwInit()',
524
+ 'void glfwTerminate()',
525
+ 'void glfwInitHint(int, int)', # Available since GLFW 3.3
526
+ 'void glfwGetVersion(int*, int*, int*)',
527
+ 'const char* glfwGetVersionString()',
528
+ 'int glfwGetError(const char**)', # Available since GLFW 3.3
529
+ 'void* glfwSetErrorCallback(void*)',
530
+ 'void** glfwGetMonitors(int*)',
531
+ 'void* glfwGetPrimaryMonitor()',
532
+ 'void glfwGetMonitorPos(void*, int*, int*)',
533
+ 'void glfwGetMonitorWorkarea(void* monitor, int*, int*, int*, int*)', # Available since GLFW 3.3
534
+ 'void glfwGetMonitorPhysicalSize(void*, int*, int*)',
535
+ 'void glfwGetMonitorContentScale(void*, float*, float*)', # Available since GLFW 3.3
536
+ 'const char* glfwGetMonitorName(void*)',
537
+ 'void glfwSetMonitorUserPointer(void*, void*)', # Available since GLFW 3.3
538
+ 'const void* glfwGetMonitorUserPointer(void**)', # Available since GLFW 3.3
539
+ 'void* glfwSetMonitorCallback(void*)', # Available since GLFW 3.0
540
+ 'const void* glfwGetVideoModes(void*, int*)',
541
+ 'const void* glfwGetVideoMode(void*)', # Available since GLFW 3.0
542
+ 'void glfwSetGamma(void*, float)', # Available since GLFW 3.0
543
+ 'const void* glfwGetGammaRamp(void*)', # Available since GLFW 3.0
544
+ 'void glfwSetGammaRamp(void*, const void*)', # Available since GLFW 3.0
545
+ 'void glfwDefaultWindowHints()', # Available since GLFW 3.0
546
+ 'void glfwWindowHint(int, int)', # Available since GLFW 3.0
547
+ 'void glfwWindowHintString(int, const char*)', # Available since GLFW 3.3
548
+ 'void* glfwCreateWindow(int, int, const char*, void*, void*)', # Available since GLFW 3.0
549
+ 'void glfwDestroyWindow(void*)', # Available since GLFW 3.0
550
+ 'int glfwWindowShouldClose(void*)', # Available since GLFW 3.0
551
+ 'void glfwSetWindowShouldClose(void* window, int)', # Available since GLFW 3.0
552
+ 'void glfwSetWindowTitle(void*, const char*)',
553
+ 'void glfwSetWindowIcon(void*, int, void*)', # Available since GLFW 3.2
554
+ 'void glfwGetWindowPos(void*, int*, int*)', # Available since GLFW 3.0
555
+ 'void glfwSetWindowPos(void*, int, int)',
556
+ 'void glfwGetWindowSize(void*, int*, int*)',
557
+ 'void glfwSetWindowSizeLimits(void*, int, int, int, int)', # Available since GLFW 3.2
558
+ 'void glfwSetWindowAspectRatio(void*, int, int)', # Available since GLFW 3.2
559
+ 'void glfwSetWindowSize(void*, int, int)',
560
+ 'void glfwGetFramebufferSize(void*, int*, int*)', # Available since GLFW 3.0
561
+ 'void glfwGetWindowFrameSize(void*, int*, int*, int*, int*)', # Available since GLFW 3.1
562
+ 'void glfwGetWindowContentScale(void*, float*, float*)', # Available since GLFW 3.3
563
+ 'float glfwGetWindowOpacity(void*)', # Available since GLFW 3.3
564
+ 'void glfwSetWindowOpacity(void*, float)', # Available since GLFW 3.3
565
+ 'void glfwIconifyWindow(void*)',
566
+ 'void glfwRestoreWindow(void*)',
567
+ 'void glfwMaximizeWindow(void*)', # Available since GLFW 3.2
568
+ 'void glfwShowWindow(void*)', # Available since GLFW 3.0
569
+ 'void glfwHideWindow(void*)', # Available since GLFW 3.0
570
+ 'void glfwFocusWindow(void*)', # Available since GLFW 3.2
571
+ 'void glfwRequestWindowAttention(void*)', # Available since GLFW 3.3
572
+ 'void* glfwGetWindowMonitor(void*)', # Available since GLFW 3.0
573
+ 'void glfwSetWindowMonitor(void*, void*, int, int, int, int, int)', # Available since GLFW 3.2
574
+ 'int glfwGetWindowAttrib(void*, int)', # Available since GLFW 3.0
575
+ 'void glfwSetWindowAttrib(void*, int, int)', # Available since GLFW 3.3
576
+ 'void glfwSetWindowUserPointer(void*, void*)', # Available since GLFW 3.0
577
+ 'void* glfwGetWindowUserPointer(void*)', # Available since GLFW 3.0
578
+ 'void* glfwSetWindowPosCallback(void*, void*)', # Available since GLFW 3.0
579
+ 'void* glfwSetWindowSizeCallback(void*, void*)',
580
+ 'void* glfwSetWindowCloseCallback(void*, void*)',
581
+ 'void* glfwSetWindowRefreshCallback(void*, void*)',
582
+ 'void* glfwSetWindowFocusCallback(void*, void*)', # Available since GLFW 3.0
583
+ 'void* glfwSetWindowIconifyCallback(void*, void*)', # Available since GLFW 3.0
584
+ 'void* glfwSetWindowMaximizeCallback(void*, void*)', # Available since GLFW 3.3
585
+ 'void* glfwSetFramebufferSizeCallback(void*, void*)', # Available since GLFW 3.0
586
+ 'void* glfwSetWindowContentScaleCallback(void*, void*)', # Available since GLFW 3.3
587
+ 'void glfwPollEvents()',
588
+ 'void glfwWaitEvents()',
589
+ 'void glfwWaitEventsTimeout(double)', # Available since GLFW 3.2
590
+ 'void glfwPostEmptyEvent()', # Available since GLFW 3.1
591
+ 'int glfwGetInputMode(void*, int)', # Available since GLFW 3.0
592
+ 'void glfwSetInputMode(void*, int, int)', # Available since GLFW 3.0
593
+ 'int glfwRawMouseMotionSupported()', # Available since GLFW 3.3
594
+ 'const char* glfwGetKeyName(int, int)', # Available since GLFW 3.2
595
+ 'int glfwGetKeyScancode(int)', # Available since GLFW 3.3
596
+ 'int glfwGetKey(void*, int)',
597
+ 'int glfwGetMouseButton(void*, int)',
598
+ 'void glfwGetCursorPos(void*, double*, double*)', # Available since GLFW 3.0
599
+ 'void glfwSetCursorPos(void*, double, double)', # Available since GLFW 3.0
600
+ 'void* glfwCreateCursor(void*, int, int)', # Available since GLFW 3.1
601
+ 'void* glfwCreateStandardCursor(int)', # Available since GLFW 3.1
602
+ 'void glfwDestroyCursor(void*)', # Available since GLFW 3.1
603
+ 'void glfwSetCursor(void*, void*)', # Available since GLFW 3.1
604
+ 'void* glfwSetKeyCallback(void*, void*)',
605
+ 'void* glfwSetCharCallback(void*, void*)',
606
+ 'void* glfwSetCharModsCallback(void*, void*)', # Available since GLFW 3.1 / Scheduled for removal in version 4.0.
607
+ 'void* glfwSetMouseButtonCallback(void*, void*)',
608
+ 'void* glfwSetCursorPosCallback(void*, void*)', # Available since GLFW 3.0
609
+ 'void* glfwSetCursorEnterCallback(void*, void*)', # Available since GLFW 3.0
610
+ 'void* glfwSetScrollCallback(void*, void*)', # Available since GLFW 3.0
611
+ 'void* glfwSetDropCallback(void*, void*)', # Available since GLFW 3.1
612
+
613
+ 'int glfwJoystickPresent(int)', # Available since GLFW 3.0
614
+ 'const float* glfwGetJoystickAxes(int, int*)', # Available since GLFW 3.0
615
+ 'const unsigned char* glfwGetJoystickButtons(int, int*)',
616
+ 'const unsigned char* glfwGetJoystickHats(int, int*)', # Available since GLFW 3.3
617
+ 'const char* glfwGetJoystickName(int)', # Available since GLFW 3.0
618
+ 'const char* glfwGetJoystickGUID(int)', # Available since GLFW 3.3
619
+ 'void glfwSetJoystickUserPointer(int, void*)', # Available since GLFW 3.3
620
+ 'void* glfwGetJoystickUserPointer(int)', # Available since GLFW 3.3
621
+ 'int glfwJoystickIsGamepad(int)', # Available since GLFW 3.3
622
+ 'void* glfwSetJoystickCallback(void*)', # Available since GLFW 3.2
623
+ 'int glfwUpdateGamepadMappings(const char*)', # Available since GLFW 3.3
624
+ 'const char* glfwGetGamepadName(int)', # Available since GLFW 3.3
625
+ 'int glfwGetGamepadState(int, void*)', # Available since GLFW 3.3
626
+ 'void glfwSetClipboardString(void*, const char*)', # Available since GLFW 3.0
627
+ 'const char* glfwGetClipboardString(void*)', # Available since GLFW 3.0
628
+ 'double glfwGetTime()',
629
+ 'void glfwSetTime(double)',
630
+ 'GLFWuint64 glfwGetTimerValue()', # Available since GLFW 3.2
631
+ 'GLFWuint64 glfwGetTimerFrequency()', # Available since GLFW 3.2
632
+ 'void glfwMakeContextCurrent(void*)', # Available since GLFW 3.0
633
+ 'void* glfwGetCurrentContext()', # Available since GLFW 3.0
634
+ 'void glfwSwapBuffers(void*)',
635
+ 'void glfwSwapInterval(int)',
636
+ 'int glfwExtensionSupported(const char*)',
637
+ 'void* glfwGetProcAddress(const char*)',
638
+ # >>> Vulkan >>>
639
+ 'int glfwVulkanSupported()', # Available since GLFW 3.2
640
+ 'const char** glfwGetRequiredInstanceExtensions(unsigned int*)', # Available since GLFW 3.2
641
+ # 'GLFWvkproc glfwGetInstanceProcAddress(void*, const char*)',
642
+ # 'int glfwGetPhysicalDevicePresentationSupport(void*, void*, unsigned int)',
643
+ # 'VkResult glfwCreateWindowSurface(void*, void*, const void*, void*)',
644
+ # <<< Vulkan <<<
645
+ ]
646
+
647
+ case OpenGL.get_platform
648
+ when :OPENGL_PLATFORM_WINDOWS
649
+ @@lib_signature << 'const char* glfwGetWin32Adapter(void*)'
650
+ @@lib_signature << 'const char* glfwGetWin32Monitor(void*)'
651
+ @@lib_signature << 'void* glfwGetWin32Window(void*)'
652
+ @@lib_signature << 'void* glfwGetWGLContext(void*)'
653
+ when :OPENGL_PLATFORM_MACOSX
654
+ @@lib_signature << 'unsigned int glfwGetCocoaMonitor(void*)'
655
+ @@lib_signature << 'void* glfwGetCocoaWindow(void*)'
656
+ @@lib_signature << 'void* glfwGetNSGLContext(void*)'
657
+ when :OPENGL_PLATFORM_LINUX
658
+ @@lib_signature << 'void* glfwGetX11Display()'
659
+ @@lib_signature << 'unsinged long glfwGetX11Adapter(void*)'
660
+ @@lib_signature << 'unsinged long glfwGetX11Monitor(void*)'
661
+ @@lib_signature << 'unsinged long glfwGetX11Window(void*)'
662
+ @@lib_signature << 'void glfwSetX11SelectionString(const char*)'
663
+ @@lib_signature << 'const char* glfwGetX11SelectionString()'
664
+ @@lib_signature << 'unsinged long glfwGetGLXWindow(void*)'
665
+ end
666
+
667
+ def self.import_symbols(output_error = false)
668
+ typealias 'GLFWuint64', 'unsigned long long' # Available since GLFW 3.2
669
+
670
+ # function
671
+ @@lib_signature.each do |sig|
672
+ begin
673
+ extern sig
674
+ rescue
675
+ $stderr.puts("[Warning] Failed to import #{sig}.") if output_error
676
+ end
677
+ end
678
+
679
+ ver_major = ' ' * 4
680
+ ver_minor = ' ' * 4
681
+ ver_rev = ' ' * 4
682
+ glfwGetVersion(ver_major, ver_minor, ver_rev)
683
+
684
+ GLFW.const_set('GLFW_VERSION_MAJOR', ver_major.unpack('L')[0])
685
+ GLFW.const_set('GLFW_VERSION_MINOR', ver_minor.unpack('L')[0])
686
+ GLFW.const_set('GLFW_VERSION_REVISION', ver_rev.unpack('L')[0])
687
+
688
+ @@glfw_import_done = true
689
+ end
690
+
691
+ end
692
+
693
+ =begin
694
+ Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator)
695
+ Copyright (c) 2013-2025 vaiorabbit <http://twitter.com/vaiorabbit>
696
+
697
+ This software is provided 'as-is', without any express or implied
698
+ warranty. In no event will the authors be held liable for any damages
699
+ arising from the use of this software.
700
+
701
+ Permission is granted to anyone to use this software for any purpose,
702
+ including commercial applications, and to alter it and redistribute it
703
+ freely, subject to the following restrictions:
704
+
705
+ 1. The origin of this software must not be misrepresented; you must not
706
+ claim that you wrote the original software. If you use this software
707
+ in a product, an acknowledgment in the product documentation would be
708
+ appreciated but is not required.
709
+
710
+ 2. Altered source versions must be plainly marked as such, and must not be
711
+ misrepresented as being the original software.
712
+
713
+ 3. This notice may not be removed or altered from any source
714
+ distribution.
715
+ =end
716
+