opengl-bindings2 2.0.0.rc1

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