opengl-bindings 1.6.10 → 1.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/glut.rb CHANGED
@@ -1,576 +1,576 @@
1
- # -*- coding: utf-8 -*-
2
- # A FreeGLUT wrapper
3
- require 'fiddle/import'
4
- require_relative 'opengl_platform'
5
-
6
- module GLUT
7
-
8
- extend Fiddle::Importer
9
-
10
- #
11
- # Fiddle's default 'extern' stores all methods into local variable '@func_map', that makes difficult to 'include GLUT'.
12
- # So I override it and replace '@func_map' into 'GLUT_FUNCTIONS_MAP'.
13
- # Ref.: /lib/ruby/2.0.0/fiddle/import.rb
14
- #
15
- GLUT_FUNCTIONS_MAP = {}
16
- def self.extern(signature, *opts)
17
- symname, ctype, argtype = parse_signature(signature, @type_alias)
18
- opt = parse_bind_options(opts)
19
- f = import_function(symname, ctype, argtype, opt[:call_type])
20
- name = symname.gsub(/@.+/,'')
21
- GLUT_FUNCTIONS_MAP[name] = f
22
- begin
23
- /^(.+?):(\d+)/ =~ caller.first
24
- file, line = $1, $2.to_i
25
- rescue
26
- file, line = __FILE__, __LINE__+3
27
- end
28
- args_str="*args"
29
- module_eval(<<-EOS, file, line)
30
- def #{name}(*args, &block)
31
- GLUT_FUNCTIONS_MAP['#{name}'].call(*args,&block)
32
- end
33
- EOS
34
- module_function(name)
35
- f
36
- end
37
-
38
- # defines
39
-
40
- GLUT_API_VERSION = 4
41
-
42
- GLUT_KEY_F1 = 0x0001
43
- GLUT_KEY_F2 = 0x0002
44
- GLUT_KEY_F3 = 0x0003
45
- GLUT_KEY_F4 = 0x0004
46
- GLUT_KEY_F5 = 0x0005
47
- GLUT_KEY_F6 = 0x0006
48
- GLUT_KEY_F7 = 0x0007
49
- GLUT_KEY_F8 = 0x0008
50
- GLUT_KEY_F9 = 0x0009
51
- GLUT_KEY_F10 = 0x000A
52
- GLUT_KEY_F11 = 0x000B
53
- GLUT_KEY_F12 = 0x000C
54
- GLUT_KEY_LEFT = 0x0064
55
- GLUT_KEY_UP = 0x0065
56
- GLUT_KEY_RIGHT = 0x0066
57
- GLUT_KEY_DOWN = 0x0067
58
- GLUT_KEY_PAGE_UP = 0x0068
59
- GLUT_KEY_PAGE_DOWN = 0x0069
60
- GLUT_KEY_HOME = 0x006A
61
- GLUT_KEY_END = 0x006B
62
- GLUT_KEY_INSERT = 0x006C
63
-
64
- GLUT_LEFT_BUTTON = 0x0000
65
- GLUT_MIDDLE_BUTTON = 0x0001
66
- GLUT_RIGHT_BUTTON = 0x0002
67
- GLUT_DOWN = 0x0000
68
- GLUT_UP = 0x0001
69
- GLUT_LEFT = 0x0000
70
- GLUT_ENTERED = 0x0001
71
-
72
- GLUT_RGB = 0x0000
73
- GLUT_RGBA = 0x0000
74
- GLUT_INDEX = 0x0001
75
- GLUT_SINGLE = 0x0000
76
- GLUT_DOUBLE = 0x0002
77
- GLUT_ACCUM = 0x0004
78
- GLUT_ALPHA = 0x0008
79
- GLUT_DEPTH = 0x0010
80
- GLUT_STENCIL = 0x0020
81
- GLUT_MULTISAMPLE = 0x0080
82
- GLUT_STEREO = 0x0100
83
- GLUT_LUMINANCE = 0x0200
84
-
85
- GLUT_MENU_NOT_IN_USE = 0x0000
86
- GLUT_MENU_IN_USE = 0x0001
87
- GLUT_NOT_VISIBLE = 0x0000
88
- GLUT_VISIBLE = 0x0001
89
- GLUT_HIDDEN = 0x0000
90
- GLUT_FULLY_RETAINED = 0x0001
91
- GLUT_PARTIALLY_RETAINED = 0x0002
92
- GLUT_FULLY_COVERED = 0x0003
93
-
94
- GLUT_WINDOW_X = 0x0064
95
- GLUT_WINDOW_Y = 0x0065
96
- GLUT_WINDOW_WIDTH = 0x0066
97
- GLUT_WINDOW_HEIGHT = 0x0067
98
- GLUT_WINDOW_BUFFER_SIZE = 0x0068
99
- GLUT_WINDOW_STENCIL_SIZE = 0x0069
100
- GLUT_WINDOW_DEPTH_SIZE = 0x006A
101
- GLUT_WINDOW_RED_SIZE = 0x006B
102
- GLUT_WINDOW_GREEN_SIZE = 0x006C
103
- GLUT_WINDOW_BLUE_SIZE = 0x006D
104
- GLUT_WINDOW_ALPHA_SIZE = 0x006E
105
- GLUT_WINDOW_ACCUM_RED_SIZE = 0x006F
106
- GLUT_WINDOW_ACCUM_GREEN_SIZE = 0x0070
107
- GLUT_WINDOW_ACCUM_BLUE_SIZE = 0x0071
108
- GLUT_WINDOW_ACCUM_ALPHA_SIZE = 0x0072
109
- GLUT_WINDOW_DOUBLEBUFFER = 0x0073
110
- GLUT_WINDOW_RGBA = 0x0074
111
- GLUT_WINDOW_PARENT = 0x0075
112
- GLUT_WINDOW_NUM_CHILDREN = 0x0076
113
- GLUT_WINDOW_COLORMAP_SIZE = 0x0077
114
- GLUT_WINDOW_NUM_SAMPLES = 0x0078
115
- GLUT_WINDOW_STEREO = 0x0079
116
- GLUT_WINDOW_CURSOR = 0x007A
117
-
118
- GLUT_SCREEN_WIDTH = 0x00C8
119
- GLUT_SCREEN_HEIGHT = 0x00C9
120
- GLUT_SCREEN_WIDTH_MM = 0x00CA
121
- GLUT_SCREEN_HEIGHT_MM = 0x00CB
122
- GLUT_MENU_NUM_ITEMS = 0x012C
123
- GLUT_DISPLAY_MODE_POSSIBLE = 0x0190
124
- GLUT_INIT_WINDOW_X = 0x01F4
125
- GLUT_INIT_WINDOW_Y = 0x01F5
126
- GLUT_INIT_WINDOW_WIDTH = 0x01F6
127
- GLUT_INIT_WINDOW_HEIGHT = 0x01F7
128
- GLUT_INIT_DISPLAY_MODE = 0x01F8
129
- GLUT_ELAPSED_TIME = 0x02BC
130
- GLUT_WINDOW_FORMAT_ID = 0x007B
131
- GLUT_INIT_STATE = 0x007C
132
-
133
- GLUT_HAS_KEYBOARD = 0x0258
134
- GLUT_HAS_MOUSE = 0x0259
135
- GLUT_HAS_SPACEBALL = 0x025A
136
- GLUT_HAS_DIAL_AND_BUTTON_BOX = 0x025B
137
- GLUT_HAS_TABLET = 0x025C
138
- GLUT_NUM_MOUSE_BUTTONS = 0x025D
139
- GLUT_NUM_SPACEBALL_BUTTONS = 0x025E
140
- GLUT_NUM_BUTTON_BOX_BUTTONS = 0x025F
141
- GLUT_NUM_DIALS = 0x0260
142
- GLUT_NUM_TABLET_BUTTONS = 0x0261
143
- GLUT_DEVICE_IGNORE_KEY_REPEAT = 0x0262
144
- GLUT_DEVICE_KEY_REPEAT = 0x0263
145
- GLUT_HAS_JOYSTICK = 0x0264
146
- GLUT_OWNS_JOYSTICK = 0x0265
147
- GLUT_JOYSTICK_BUTTONS = 0x0266
148
- GLUT_JOYSTICK_AXES = 0x0267
149
- GLUT_JOYSTICK_POLL_RATE = 0x0268
150
-
151
- GLUT_OVERLAY_POSSIBLE = 0x0320
152
- GLUT_LAYER_IN_USE = 0x0321
153
- GLUT_HAS_OVERLAY = 0x0322
154
- GLUT_TRANSPARENT_INDEX = 0x0323
155
- GLUT_NORMAL_DAMAGED = 0x0324
156
- GLUT_OVERLAY_DAMAGED = 0x0325
157
-
158
- GLUT_VIDEO_RESIZE_POSSIBLE = 0x0384
159
- GLUT_VIDEO_RESIZE_IN_USE = 0x0385
160
- GLUT_VIDEO_RESIZE_X_DELTA = 0x0386
161
- GLUT_VIDEO_RESIZE_Y_DELTA = 0x0387
162
- GLUT_VIDEO_RESIZE_WIDTH_DELTA = 0x0388
163
- GLUT_VIDEO_RESIZE_HEIGHT_DELTA = 0x0389
164
- GLUT_VIDEO_RESIZE_X = 0x038A
165
- GLUT_VIDEO_RESIZE_Y = 0x038B
166
- GLUT_VIDEO_RESIZE_WIDTH = 0x038C
167
- GLUT_VIDEO_RESIZE_HEIGHT = 0x038D
168
-
169
- GLUT_NORMAL = 0x0000
170
- GLUT_OVERLAY = 0x0001
171
-
172
- GLUT_ACTIVE_SHIFT = 0x0001
173
- GLUT_ACTIVE_CTRL = 0x0002
174
- GLUT_ACTIVE_ALT = 0x0004
175
-
176
- GLUT_CURSOR_RIGHT_ARROW = 0x0000
177
- GLUT_CURSOR_LEFT_ARROW = 0x0001
178
- GLUT_CURSOR_INFO = 0x0002
179
- GLUT_CURSOR_DESTROY = 0x0003
180
- GLUT_CURSOR_HELP = 0x0004
181
- GLUT_CURSOR_CYCLE = 0x0005
182
- GLUT_CURSOR_SPRAY = 0x0006
183
- GLUT_CURSOR_WAIT = 0x0007
184
- GLUT_CURSOR_TEXT = 0x0008
185
- GLUT_CURSOR_CROSSHAIR = 0x0009
186
- GLUT_CURSOR_UP_DOWN = 0x000A
187
- GLUT_CURSOR_LEFT_RIGHT = 0x000B
188
- GLUT_CURSOR_TOP_SIDE = 0x000C
189
- GLUT_CURSOR_BOTTOM_SIDE = 0x000D
190
- GLUT_CURSOR_LEFT_SIDE = 0x000E
191
- GLUT_CURSOR_RIGHT_SIDE = 0x000F
192
- GLUT_CURSOR_TOP_LEFT_CORNER = 0x0010
193
- GLUT_CURSOR_TOP_RIGHT_CORNER = 0x0011
194
- GLUT_CURSOR_BOTTOM_RIGHT_CORNER = 0x0012
195
- GLUT_CURSOR_BOTTOM_LEFT_CORNER = 0x0013
196
- GLUT_CURSOR_INHERIT = 0x0064
197
- GLUT_CURSOR_NONE = 0x0065
198
- GLUT_CURSOR_FULL_CROSSHAIR = 0x0066
199
-
200
- GLUT_RED = 0x0000
201
- GLUT_GREEN = 0x0001
202
- GLUT_BLUE = 0x0002
203
-
204
- GLUT_KEY_REPEAT_OFF = 0x0000
205
- GLUT_KEY_REPEAT_ON = 0x0001
206
- GLUT_KEY_REPEAT_DEFAULT = 0x0002
207
-
208
- GLUT_JOYSTICK_BUTTON_A = 0x0001
209
- GLUT_JOYSTICK_BUTTON_B = 0x0002
210
- GLUT_JOYSTICK_BUTTON_C = 0x0004
211
- GLUT_JOYSTICK_BUTTON_D = 0x0008
212
-
213
- GLUT_GAME_MODE_ACTIVE = 0x0000
214
- GLUT_GAME_MODE_POSSIBLE = 0x0001
215
- GLUT_GAME_MODE_WIDTH = 0x0002
216
- GLUT_GAME_MODE_HEIGHT = 0x0003
217
- GLUT_GAME_MODE_PIXEL_DEPTH = 0x0004
218
- GLUT_GAME_MODE_REFRESH_RATE = 0x0005
219
- GLUT_GAME_MODE_DISPLAY_CHANGED = 0x0006
220
-
221
- # typedefs
222
- @@glut_cb_function_signature = {
223
- :GLUTMenuFunc => "void GLUTMenuFunc(int)",
224
-
225
- :GLUTTimerFunc => "void GLUTTimerFunc(int)",
226
- :GLUTIdleFunc => "void GLUTIdleFunc()",
227
-
228
- :GLUTKeyboardFunc => "void GLUTKeyboardFunc(unsigned char, int, int)",
229
- :GLUTSpecialFunc => "void GLUTSpecialFunc(int, int, int)",
230
- :GLUTReshapeFunc => "void GLUTReshapeFunc(int, int)",
231
- :GLUTVisibilityFunc => "void GLUTVisibilityFunc(int)",
232
- :GLUTDisplayFunc => "void GLUTDisplayFunc()",
233
- :GLUTMouseFunc => "void GLUTMouseFunc(int, int, int, int)",
234
- :GLUTMotionFunc => "void GLUTMotionFunc(int, int)",
235
- :GLUTPassiveMotionFunc => "void GLUTPassiveMotionFunc(int, int)",
236
- :GLUTEntryFunc => "void GLUTEntryFunc(int)",
237
-
238
- :GLUTKeyboardUpFunc => "void GLUTKeyboardUpFunc(unsigned char, int, int)",
239
- :GLUTSpecialUpFunc => "void GLUTSpecialUpFunc(int, int, int)",
240
- :GLUTJoystickFunc => "void GLUTJoystickFunc(unsigned int, int, int, int)",
241
- :GLUTMenuStateFunc => "void GLUTMenuStateFunc(int)",
242
- :GLUTMenuStatusFunc => "void GLUTMenuStatusFunc(int, int, int)",
243
- :GLUTOverlayDisplayFunc => "void GLUTOverlayDisplayFunc()",
244
- :GLUTWindowStatusFunc => "void GLUTWindowStatusFunc(int)",
245
-
246
- :GLUTSpaceballMotionFunc => "void GLUTSpaceballMotionFunc(int, int, int)",
247
- :GLUTSpaceballRotateFunc => "void GLUTSpaceballRotateFunc(int, int, int)",
248
- :GLUTSpaceballButtonFunc => "void GLUTSpaceballButtonFunc(int, int)",
249
- :GLUTButtonBoxFunc => "void GLUTButtonBoxFunc(int, int)",
250
- :GLUTDialsFunc => "void GLUTDialsFunc(int, int)",
251
- :GLUTTabletMotionFunc => "void GLUTTabletMotionFunc(int, int)",
252
- :GLUTTabletButtonFunc => "void GLUTTabletButtonFunc(int, int, int, int)",
253
- }
254
-
255
- # Creates a callback as an instance of Fiddle::Function
256
- def self.create_callback( sym, proc=nil, &blk )
257
- if block_given?
258
- return bind( @@glut_cb_function_signature[sym], nil, &blk )
259
- else
260
- return bind( @@glut_cb_function_signature[sym], nil, &proc )
261
- end
262
- end
263
-
264
- GLUTMenuFunc_cb_args = [Fiddle::TYPE_INT]
265
- GLUTMenuFunc_cb_retval = Fiddle::TYPE_VOID
266
- GLUTTimerFunc_cb_args = [Fiddle::TYPE_INT]
267
- GLUTTimerFunc_cb_retval = Fiddle::TYPE_VOID
268
- GLUTIdleFunc_cb_args = []
269
- GLUTIdleFunc_cb_retval = Fiddle::TYPE_VOID
270
- GLUTKeyboardFunc_cb_args = [-Fiddle::TYPE_CHAR, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
271
- GLUTKeyboardFunc_cb_retval = Fiddle::TYPE_VOID
272
- GLUTSpecialFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
273
- GLUTSpecialFunc_cb_retval = Fiddle::TYPE_VOID
274
- GLUTReshapeFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
275
- GLUTReshapeFunc_cb_retval = Fiddle::TYPE_VOID
276
- GLUTVisibilityFunc_cb_args = [Fiddle::TYPE_INT]
277
- GLUTVisibilityFunc_cb_retval = Fiddle::TYPE_VOID
278
- GLUTDisplayFunc_cb_args = []
279
- GLUTDisplayFunc_cb_retval = Fiddle::TYPE_VOID
280
- GLUTMouseFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
281
- GLUTMouseFunc_cb_retval = Fiddle::TYPE_VOID
282
- GLUTMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
283
- GLUTMotionFunc_cb_retval = Fiddle::TYPE_VOID
284
- GLUTPassiveMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
285
- GLUTPassiveMotionFunc_cb_retval = Fiddle::TYPE_VOID
286
- GLUTEntryFunc_cb_args = [Fiddle::TYPE_INT]
287
- GLUTEntryFunc_cb_retval = Fiddle::TYPE_VOID
288
- GLUTKeyboardUpFunc_cb_args = [-Fiddle::TYPE_CHAR, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
289
- GLUTKeyboardUpFunc_cb_retval = Fiddle::TYPE_VOID
290
- GLUTSpecialUpFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
291
- GLUTSpecialUpFunc_cb_retval = Fiddle::TYPE_VOID
292
- GLUTJoystickFunc_cb_args = [-Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
293
- GLUTJoystickFunc_cb_retval = Fiddle::TYPE_VOID
294
- GLUTMenuStateFunc_cb_args = [Fiddle::TYPE_INT]
295
- GLUTMenuStateFunc_cb_retval = Fiddle::TYPE_VOID
296
- GLUTMenuStatusFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
297
- GLUTMenuStatusFunc_cb_retval = Fiddle::TYPE_VOID
298
- GLUTOverlayDisplayFunc_cb_args = []
299
- GLUTOverlayDisplayFunc_cb_retval = Fiddle::TYPE_VOID
300
- GLUTWindowStatusFunc_cb_args = [Fiddle::TYPE_INT]
301
- GLUTWindowStatusFunc_cb_retval = Fiddle::TYPE_VOID
302
- GLUTSpaceballMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
303
- GLUTSpaceballMotionFunc_cb_retval = Fiddle::TYPE_VOID
304
- GLUTSpaceballRotateFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
305
- GLUTSpaceballRotateFunc_cb_retval = Fiddle::TYPE_VOID
306
- GLUTSpaceballButtonFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
307
- GLUTSpaceballButtonFunc_cb_retval = Fiddle::TYPE_VOID
308
- GLUTButtonBoxFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
309
- GLUTButtonBoxFunc_cb_retval = Fiddle::TYPE_VOID
310
- GLUTDialsFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
311
- GLUTDialsFunc_cb_retval = Fiddle::TYPE_VOID
312
- GLUTTabletMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
313
- GLUTTabletMotionFunc_cb_retval = Fiddle::TYPE_VOID
314
- GLUTTabletButtonFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
315
- GLUTTabletButtonFunc_cb_retval = Fiddle::TYPE_VOID
316
-
317
- @@glut_cb_closure_signature = {
318
- :GLUTMenuFunc => [GLUTMenuFunc_cb_retval, GLUTMenuFunc_cb_args],
319
- :GLUTTimerFunc => [GLUTTimerFunc_cb_retval, GLUTTimerFunc_cb_args],
320
- :GLUTIdleFunc => [GLUTIdleFunc_cb_retval, GLUTIdleFunc_cb_args],
321
- :GLUTKeyboardFunc => [GLUTKeyboardFunc_cb_retval, GLUTKeyboardFunc_cb_args],
322
- :GLUTSpecialFunc => [GLUTSpecialFunc_cb_retval, GLUTSpecialFunc_cb_args],
323
- :GLUTReshapeFunc => [GLUTReshapeFunc_cb_retval, GLUTReshapeFunc_cb_args],
324
- :GLUTVisibilityFunc => [GLUTVisibilityFunc_cb_retval, GLUTVisibilityFunc_cb_args],
325
- :GLUTDisplayFunc => [GLUTDisplayFunc_cb_retval, GLUTDisplayFunc_cb_args],
326
- :GLUTMouseFunc => [GLUTMouseFunc_cb_retval, GLUTMouseFunc_cb_args],
327
- :GLUTMotionFunc => [GLUTMotionFunc_cb_retval, GLUTMotionFunc_cb_args],
328
- :GLUTPassiveMotionFunc => [GLUTPassiveMotionFunc_cb_retval, GLUTPassiveMotionFunc_cb_args],
329
- :GLUTEntryFunc => [GLUTEntryFunc_cb_retval, GLUTEntryFunc_cb_args],
330
- :GLUTKeyboardUpFunc => [GLUTKeyboardUpFunc_cb_retval, GLUTKeyboardUpFunc_cb_args],
331
- :GLUTSpecialUpFunc => [GLUTSpecialUpFunc_cb_retval, GLUTSpecialUpFunc_cb_args],
332
- :GLUTJoystickFunc => [GLUTJoystickFunc_cb_retval, GLUTJoystickFunc_cb_args],
333
- :GLUTMenuStateFunc => [GLUTMenuStateFunc_cb_retval, GLUTMenuStateFunc_cb_args],
334
- :GLUTMenuStatusFunc => [GLUTMenuStatusFunc_cb_retval, GLUTMenuStatusFunc_cb_args],
335
- :GLUTOverlayDisplayFunc => [GLUTOverlayDisplayFunc_cb_retval, GLUTOverlayDisplayFunc_cb_args],
336
- :GLUTWindowStatusFunc => [GLUTWindowStatusFunc_cb_retval, GLUTWindowStatusFunc_cb_args],
337
- :GLUTSpaceballMotionFunc => [GLUTSpaceballMotionFunc_cb_retval, GLUTSpaceballMotionFunc_cb_args],
338
- :GLUTSpaceballRotateFunc => [GLUTSpaceballRotateFunc_cb_retval, GLUTSpaceballRotateFunc_cb_args],
339
- :GLUTSpaceballButtonFunc => [GLUTSpaceballButtonFunc_cb_retval, GLUTSpaceballButtonFunc_cb_args],
340
- :GLUTButtonBoxFunc => [GLUTButtonBoxFunc_cb_retval, GLUTButtonBoxFunc_cb_args],
341
- :GLUTDialsFunc => [GLUTDialsFunc_cb_retval, GLUTDialsFunc_cb_args],
342
- :GLUTTabletMotionFunc => [GLUTTabletMotionFunc_cb_retval, GLUTTabletMotionFunc_cb_args],
343
- :GLUTTabletButtonFunc => [GLUTTabletButtonFunc_cb_retval, GLUTTabletButtonFunc_cb_args],
344
- }
345
-
346
- # Creates a callback as an instance of Fiddle::Closure::BlockCaller
347
- def self.create_callback_closure( sym, proc=nil, &blk )
348
- cb_retval = @@glut_cb_closure_signature[sym][0]
349
- cb_args = @@glut_cb_closure_signature[sym][1]
350
- if block_given?
351
- return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &blk )
352
- else
353
- return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &proc )
354
- end
355
- end
356
-
357
- # NOTE : Use 'create_callback_function' for backward compatibility.
358
- def self.create_callback( sym, proc=nil, &blk )
359
- return self.create_callback_closure( sym, proc, &blk )
360
- end
361
-
362
- @@glut_import_done = false
363
-
364
- # Load native library.
365
- def self.load_lib(lib = nil, path = nil)
366
- if lib == nil && path == nil
367
- case OpenGL.get_platform
368
- when :OPENGL_PLATFORM_WINDOWS
369
- lib, path = 'freeglut.dll', Dir.pwd
370
- when :OPENGL_PLATFORM_MACOSX
371
- lib, path = 'GLUT', '/System/Library/Frameworks/GLUT.framework'
372
- else
373
- lib, path = 'libglut.so'
374
- end
375
- end
376
- if path
377
- dlload (path + '/' + lib)
378
- else
379
- dlload (lib)
380
- end
381
- import_symbols() unless @@glut_import_done
382
- end
383
-
384
- def self.load_dll(lib = nil, path = nil)
385
- puts "Warning GLUT.load_dll is deprecated, use GLUT.load_lib instead"
386
- self.load_lib(lib, path)
387
- end
388
-
389
- def self.import_symbols
390
- # defines
391
- if OpenGL.get_platform == :OPENGL_PLATFORM_WINDOWS
392
- const_set('GLUT_STROKE_ROMAN', Fiddle::Pointer.new(0x0000) )
393
- const_set('GLUT_STROKE_MONO_ROMAN', Fiddle::Pointer.new(0x0001) )
394
- const_set('GLUT_BITMAP_9_BY_15', Fiddle::Pointer.new(0x0002) )
395
- const_set('GLUT_BITMAP_8_BY_13', Fiddle::Pointer.new(0x0003) )
396
- const_set('GLUT_BITMAP_TIMES_ROMAN_10', Fiddle::Pointer.new(0x0004) )
397
- const_set('GLUT_BITMAP_TIMES_ROMAN_24', Fiddle::Pointer.new(0x0005) )
398
- const_set('GLUT_BITMAP_HELVETICA_10', Fiddle::Pointer.new(0x0006) )
399
- const_set('GLUT_BITMAP_HELVETICA_12', Fiddle::Pointer.new(0x0007) )
400
- const_set('GLUT_BITMAP_HELVETICA_18', Fiddle::Pointer.new(0x0008) )
401
- else
402
- const_set('GLUT_STROKE_ROMAN', import_symbol("glutStrokeRoman") )
403
- const_set('GLUT_STROKE_MONO_ROMAN', import_symbol("glutStrokeMonoRoman") )
404
- const_set('GLUT_BITMAP_9_BY_15', import_symbol("glutBitmap9By15") )
405
- const_set('GLUT_BITMAP_8_BY_13', import_symbol("glutBitmap8By13") )
406
- const_set('GLUT_BITMAP_TIMES_ROMAN_10', import_symbol("glutBitmapTimesRoman10") )
407
- const_set('GLUT_BITMAP_TIMES_ROMAN_24', import_symbol("glutBitmapTimesRoman24") )
408
- const_set('GLUT_BITMAP_HELVETICA_10', import_symbol("glutBitmapHelvetica10") )
409
- const_set('GLUT_BITMAP_HELVETICA_12', import_symbol("glutBitmapHelvetica12") )
410
- const_set('GLUT_BITMAP_HELVETICA_18', import_symbol("glutBitmapHelvetica18") )
411
- end
412
-
413
- # function
414
- extern 'void glutInit(int*, char**)'
415
- extern 'void glutInitWindowPosition(int, int)'
416
- extern 'void glutInitWindowSize(int, int)'
417
- extern 'void glutInitDisplayMode(unsigned int)'
418
- extern 'void glutInitDisplayString(const char*)'
419
-
420
- extern 'void glutMainLoop()'
421
-
422
- extern 'int glutCreateWindow(const char *)'
423
- extern 'int glutCreateSubWindow(int, int, int, int, int)'
424
- extern 'void glutDestroyWindow(int)'
425
- extern 'void glutSetWindow(int)'
426
- extern 'int glutGetWindow()'
427
- extern 'void glutSetWindowTitle(const char *)'
428
- extern 'void glutSetIconTitle(const char *)'
429
- extern 'void glutReshapeWindow(int, int)'
430
- extern 'void glutPositionWindow(int, int)'
431
- extern 'void glutShowWindow()'
432
- extern 'void glutHideWindow()'
433
- extern 'void glutIconifyWindow()'
434
- extern 'void glutPushWindow()'
435
- extern 'void glutPopWindow()'
436
- extern 'void glutFullScreen()'
437
-
438
- extern 'void glutPostWindowRedisplay(int)'
439
- extern 'void glutPostRedisplay()'
440
- extern 'void glutSwapBuffers()'
441
-
442
- extern 'void glutWarpPointer(int, int)'
443
- extern 'void glutSetCursor(int)'
444
-
445
- extern 'void glutEstablishOverlay()'
446
- extern 'void glutRemoveOverlay()'
447
- extern 'void glutUseLayer(unsigned int)'
448
- extern 'void glutPostOverlayRedisplay()'
449
- extern 'void glutPostWindowOverlayRedisplay(int)'
450
- extern 'void glutShowOverlay()'
451
- extern 'void glutHideOverlay()'
452
-
453
- extern 'int glutCreateMenu(void *)'
454
- extern 'void glutDestroyMenu(int)'
455
- extern 'int glutGetMenu()'
456
- extern 'void glutSetMenu(int)'
457
- extern 'void glutAddMenuEntry(const char *, int)'
458
- extern 'void glutAddSubMenu(const char *, int)'
459
- extern 'void glutChangeToMenuEntry(int, const char *, int)'
460
- extern 'void glutChangeToSubMenu(int, const char *, int)'
461
- extern 'void glutRemoveMenuItem(int)'
462
- extern 'void glutAttachMenu(int)'
463
- extern 'void glutDetachMenu(int)'
464
-
465
- extern 'void glutTimerFunc(unsigned int, void *, int)'
466
- extern 'void glutIdleFunc(void *)'
467
-
468
- extern 'void glutKeyboardFunc(void *)'
469
- extern 'void glutSpecialFunc(void *)'
470
- extern 'void glutReshapeFunc(void *)'
471
- extern 'void glutVisibilityFunc(void *)'
472
- extern 'void glutDisplayFunc(void *)'
473
- extern 'void glutMouseFunc(void *)'
474
- extern 'void glutMotionFunc(void *)'
475
- extern 'void glutPassiveMotionFunc(void *)'
476
- extern 'void glutEntryFunc(void *)'
477
-
478
- extern 'void glutKeyboardUpFunc(void *)'
479
- extern 'void glutSpecialUpFunc(void *)'
480
- extern 'void glutJoystickFunc(void *, int)'
481
- extern 'void glutMenuStateFunc(void *)'
482
- extern 'void glutMenuStatusFunc(void *)'
483
- extern 'void glutOverlayDisplayFunc(void *)'
484
- extern 'void glutWindowStatusFunc(void *)'
485
-
486
- extern 'void glutSpaceballMotionFunc(void *)'
487
- extern 'void glutSpaceballRotateFunc(void *)'
488
- extern 'void glutSpaceballButtonFunc(void *)'
489
- extern 'void glutButtonBoxFunc(void *)'
490
- extern 'void glutDialsFunc(void *)'
491
- extern 'void glutTabletMotionFunc(void *)'
492
- extern 'void glutTabletButtonFunc(void *)'
493
-
494
- extern 'int glutGet(unsigned int)'
495
- extern 'int glutDeviceGet(unsigned int)'
496
- extern 'int glutGetModifiers()'
497
- extern 'int glutLayerGet(unsigned int)'
498
-
499
- extern 'void glutBitmapCharacter(void *, int)'
500
- extern 'int glutBitmapWidth(void *, int)'
501
- extern 'void glutStrokeCharacter(void *, int)'
502
- extern 'int glutStrokeWidth(void *, int)'
503
- extern 'int glutBitmapLength(void *, const unsigned char*)'
504
- extern 'int glutStrokeLength(void *, const unsigned char*)'
505
-
506
- extern 'void glutWireCube(double)'
507
- extern 'void glutSolidCube(double)'
508
- extern 'void glutWireSphere(double, int, int)'
509
- extern 'void glutSolidSphere(double, int, int)'
510
- extern 'void glutWireCone(double, double, int, int)'
511
- extern 'void glutSolidCone(double, double, int, int)'
512
-
513
- extern 'void glutWireTorus(double, double, int, int)'
514
- extern 'void glutSolidTorus(double, double, int, int)'
515
- extern 'void glutWireDodecahedron()'
516
- extern 'void glutSolidDodecahedron()'
517
- extern 'void glutWireOctahedron()'
518
- extern 'void glutSolidOctahedron()'
519
- extern 'void glutWireTetrahedron()'
520
- extern 'void glutSolidTetrahedron()'
521
- extern 'void glutWireIcosahedron()'
522
- extern 'void glutSolidIcosahedron()'
523
-
524
- extern 'void glutWireTeapot(double)'
525
- extern 'void glutSolidTeapot(double)'
526
-
527
- extern 'void glutGameModeString(const char*)'
528
- extern 'int glutEnterGameMode()'
529
- extern 'void glutLeaveGameMode()'
530
- extern 'int glutGameModeGet(unsigned int)'
531
-
532
- extern 'int glutVideoResizeGet(unsigned int)'
533
- extern 'void glutSetupVideoResizing()'
534
- extern 'void glutStopVideoResizing()'
535
- extern 'void glutVideoResize(int, int, int, int)'
536
- extern 'void glutVideoPan(int, int, int, int)'
537
-
538
- extern 'void glutSetColor(int, float, float, float)'
539
- extern 'float glutGetColor(int, int)'
540
- extern 'void glutCopyColormap(int)'
541
-
542
- extern 'void glutIgnoreKeyRepeat(int)'
543
- extern 'void glutSetKeyRepeat(int)'
544
- extern 'void glutForceJoystickFunc()'
545
-
546
- extern 'int glutExtensionSupported(const char *)'
547
- extern 'void glutReportErrors()'
548
-
549
- @@glut_import_done = true
550
- end
551
-
552
- end
553
-
554
- =begin
555
- Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator)
556
- Copyright (c) 2013-2020 vaiorabbit <http://twitter.com/vaiorabbit>
557
-
558
- This software is provided 'as-is', without any express or implied
559
- warranty. In no event will the authors be held liable for any damages
560
- arising from the use of this software.
561
-
562
- Permission is granted to anyone to use this software for any purpose,
563
- including commercial applications, and to alter it and redistribute it
564
- freely, subject to the following restrictions:
565
-
566
- 1. The origin of this software must not be misrepresented; you must not
567
- claim that you wrote the original software. If you use this software
568
- in a product, an acknowledgment in the product documentation would be
569
- appreciated but is not required.
570
-
571
- 2. Altered source versions must be plainly marked as such, and must not be
572
- misrepresented as being the original software.
573
-
574
- 3. This notice may not be removed or altered from any source
575
- distribution.
576
- =end
1
+ # -*- coding: utf-8 -*-
2
+ # A FreeGLUT wrapper
3
+ require 'fiddle/import'
4
+ require_relative 'opengl_platform'
5
+
6
+ module GLUT
7
+
8
+ extend Fiddle::Importer
9
+
10
+ #
11
+ # Fiddle's default 'extern' stores all methods into local variable '@func_map', that makes difficult to 'include GLUT'.
12
+ # So I override it and replace '@func_map' into 'GLUT_FUNCTIONS_MAP'.
13
+ # Ref.: /lib/ruby/2.0.0/fiddle/import.rb
14
+ #
15
+ GLUT_FUNCTIONS_MAP = {}
16
+ def self.extern(signature, *opts)
17
+ symname, ctype, argtype = parse_signature(signature, @type_alias)
18
+ opt = parse_bind_options(opts)
19
+ f = import_function(symname, ctype, argtype, opt[:call_type])
20
+ name = symname.gsub(/@.+/,'')
21
+ GLUT_FUNCTIONS_MAP[name] = f
22
+ begin
23
+ /^(.+?):(\d+)/ =~ caller.first
24
+ file, line = $1, $2.to_i
25
+ rescue
26
+ file, line = __FILE__, __LINE__+3
27
+ end
28
+ args_str="*args"
29
+ module_eval(<<-EOS, file, line)
30
+ def #{name}(*args, &block)
31
+ GLUT_FUNCTIONS_MAP['#{name}'].call(*args,&block)
32
+ end
33
+ EOS
34
+ module_function(name)
35
+ f
36
+ end
37
+
38
+ # defines
39
+
40
+ GLUT_API_VERSION = 4
41
+
42
+ GLUT_KEY_F1 = 0x0001
43
+ GLUT_KEY_F2 = 0x0002
44
+ GLUT_KEY_F3 = 0x0003
45
+ GLUT_KEY_F4 = 0x0004
46
+ GLUT_KEY_F5 = 0x0005
47
+ GLUT_KEY_F6 = 0x0006
48
+ GLUT_KEY_F7 = 0x0007
49
+ GLUT_KEY_F8 = 0x0008
50
+ GLUT_KEY_F9 = 0x0009
51
+ GLUT_KEY_F10 = 0x000A
52
+ GLUT_KEY_F11 = 0x000B
53
+ GLUT_KEY_F12 = 0x000C
54
+ GLUT_KEY_LEFT = 0x0064
55
+ GLUT_KEY_UP = 0x0065
56
+ GLUT_KEY_RIGHT = 0x0066
57
+ GLUT_KEY_DOWN = 0x0067
58
+ GLUT_KEY_PAGE_UP = 0x0068
59
+ GLUT_KEY_PAGE_DOWN = 0x0069
60
+ GLUT_KEY_HOME = 0x006A
61
+ GLUT_KEY_END = 0x006B
62
+ GLUT_KEY_INSERT = 0x006C
63
+
64
+ GLUT_LEFT_BUTTON = 0x0000
65
+ GLUT_MIDDLE_BUTTON = 0x0001
66
+ GLUT_RIGHT_BUTTON = 0x0002
67
+ GLUT_DOWN = 0x0000
68
+ GLUT_UP = 0x0001
69
+ GLUT_LEFT = 0x0000
70
+ GLUT_ENTERED = 0x0001
71
+
72
+ GLUT_RGB = 0x0000
73
+ GLUT_RGBA = 0x0000
74
+ GLUT_INDEX = 0x0001
75
+ GLUT_SINGLE = 0x0000
76
+ GLUT_DOUBLE = 0x0002
77
+ GLUT_ACCUM = 0x0004
78
+ GLUT_ALPHA = 0x0008
79
+ GLUT_DEPTH = 0x0010
80
+ GLUT_STENCIL = 0x0020
81
+ GLUT_MULTISAMPLE = 0x0080
82
+ GLUT_STEREO = 0x0100
83
+ GLUT_LUMINANCE = 0x0200
84
+
85
+ GLUT_MENU_NOT_IN_USE = 0x0000
86
+ GLUT_MENU_IN_USE = 0x0001
87
+ GLUT_NOT_VISIBLE = 0x0000
88
+ GLUT_VISIBLE = 0x0001
89
+ GLUT_HIDDEN = 0x0000
90
+ GLUT_FULLY_RETAINED = 0x0001
91
+ GLUT_PARTIALLY_RETAINED = 0x0002
92
+ GLUT_FULLY_COVERED = 0x0003
93
+
94
+ GLUT_WINDOW_X = 0x0064
95
+ GLUT_WINDOW_Y = 0x0065
96
+ GLUT_WINDOW_WIDTH = 0x0066
97
+ GLUT_WINDOW_HEIGHT = 0x0067
98
+ GLUT_WINDOW_BUFFER_SIZE = 0x0068
99
+ GLUT_WINDOW_STENCIL_SIZE = 0x0069
100
+ GLUT_WINDOW_DEPTH_SIZE = 0x006A
101
+ GLUT_WINDOW_RED_SIZE = 0x006B
102
+ GLUT_WINDOW_GREEN_SIZE = 0x006C
103
+ GLUT_WINDOW_BLUE_SIZE = 0x006D
104
+ GLUT_WINDOW_ALPHA_SIZE = 0x006E
105
+ GLUT_WINDOW_ACCUM_RED_SIZE = 0x006F
106
+ GLUT_WINDOW_ACCUM_GREEN_SIZE = 0x0070
107
+ GLUT_WINDOW_ACCUM_BLUE_SIZE = 0x0071
108
+ GLUT_WINDOW_ACCUM_ALPHA_SIZE = 0x0072
109
+ GLUT_WINDOW_DOUBLEBUFFER = 0x0073
110
+ GLUT_WINDOW_RGBA = 0x0074
111
+ GLUT_WINDOW_PARENT = 0x0075
112
+ GLUT_WINDOW_NUM_CHILDREN = 0x0076
113
+ GLUT_WINDOW_COLORMAP_SIZE = 0x0077
114
+ GLUT_WINDOW_NUM_SAMPLES = 0x0078
115
+ GLUT_WINDOW_STEREO = 0x0079
116
+ GLUT_WINDOW_CURSOR = 0x007A
117
+
118
+ GLUT_SCREEN_WIDTH = 0x00C8
119
+ GLUT_SCREEN_HEIGHT = 0x00C9
120
+ GLUT_SCREEN_WIDTH_MM = 0x00CA
121
+ GLUT_SCREEN_HEIGHT_MM = 0x00CB
122
+ GLUT_MENU_NUM_ITEMS = 0x012C
123
+ GLUT_DISPLAY_MODE_POSSIBLE = 0x0190
124
+ GLUT_INIT_WINDOW_X = 0x01F4
125
+ GLUT_INIT_WINDOW_Y = 0x01F5
126
+ GLUT_INIT_WINDOW_WIDTH = 0x01F6
127
+ GLUT_INIT_WINDOW_HEIGHT = 0x01F7
128
+ GLUT_INIT_DISPLAY_MODE = 0x01F8
129
+ GLUT_ELAPSED_TIME = 0x02BC
130
+ GLUT_WINDOW_FORMAT_ID = 0x007B
131
+ GLUT_INIT_STATE = 0x007C
132
+
133
+ GLUT_HAS_KEYBOARD = 0x0258
134
+ GLUT_HAS_MOUSE = 0x0259
135
+ GLUT_HAS_SPACEBALL = 0x025A
136
+ GLUT_HAS_DIAL_AND_BUTTON_BOX = 0x025B
137
+ GLUT_HAS_TABLET = 0x025C
138
+ GLUT_NUM_MOUSE_BUTTONS = 0x025D
139
+ GLUT_NUM_SPACEBALL_BUTTONS = 0x025E
140
+ GLUT_NUM_BUTTON_BOX_BUTTONS = 0x025F
141
+ GLUT_NUM_DIALS = 0x0260
142
+ GLUT_NUM_TABLET_BUTTONS = 0x0261
143
+ GLUT_DEVICE_IGNORE_KEY_REPEAT = 0x0262
144
+ GLUT_DEVICE_KEY_REPEAT = 0x0263
145
+ GLUT_HAS_JOYSTICK = 0x0264
146
+ GLUT_OWNS_JOYSTICK = 0x0265
147
+ GLUT_JOYSTICK_BUTTONS = 0x0266
148
+ GLUT_JOYSTICK_AXES = 0x0267
149
+ GLUT_JOYSTICK_POLL_RATE = 0x0268
150
+
151
+ GLUT_OVERLAY_POSSIBLE = 0x0320
152
+ GLUT_LAYER_IN_USE = 0x0321
153
+ GLUT_HAS_OVERLAY = 0x0322
154
+ GLUT_TRANSPARENT_INDEX = 0x0323
155
+ GLUT_NORMAL_DAMAGED = 0x0324
156
+ GLUT_OVERLAY_DAMAGED = 0x0325
157
+
158
+ GLUT_VIDEO_RESIZE_POSSIBLE = 0x0384
159
+ GLUT_VIDEO_RESIZE_IN_USE = 0x0385
160
+ GLUT_VIDEO_RESIZE_X_DELTA = 0x0386
161
+ GLUT_VIDEO_RESIZE_Y_DELTA = 0x0387
162
+ GLUT_VIDEO_RESIZE_WIDTH_DELTA = 0x0388
163
+ GLUT_VIDEO_RESIZE_HEIGHT_DELTA = 0x0389
164
+ GLUT_VIDEO_RESIZE_X = 0x038A
165
+ GLUT_VIDEO_RESIZE_Y = 0x038B
166
+ GLUT_VIDEO_RESIZE_WIDTH = 0x038C
167
+ GLUT_VIDEO_RESIZE_HEIGHT = 0x038D
168
+
169
+ GLUT_NORMAL = 0x0000
170
+ GLUT_OVERLAY = 0x0001
171
+
172
+ GLUT_ACTIVE_SHIFT = 0x0001
173
+ GLUT_ACTIVE_CTRL = 0x0002
174
+ GLUT_ACTIVE_ALT = 0x0004
175
+
176
+ GLUT_CURSOR_RIGHT_ARROW = 0x0000
177
+ GLUT_CURSOR_LEFT_ARROW = 0x0001
178
+ GLUT_CURSOR_INFO = 0x0002
179
+ GLUT_CURSOR_DESTROY = 0x0003
180
+ GLUT_CURSOR_HELP = 0x0004
181
+ GLUT_CURSOR_CYCLE = 0x0005
182
+ GLUT_CURSOR_SPRAY = 0x0006
183
+ GLUT_CURSOR_WAIT = 0x0007
184
+ GLUT_CURSOR_TEXT = 0x0008
185
+ GLUT_CURSOR_CROSSHAIR = 0x0009
186
+ GLUT_CURSOR_UP_DOWN = 0x000A
187
+ GLUT_CURSOR_LEFT_RIGHT = 0x000B
188
+ GLUT_CURSOR_TOP_SIDE = 0x000C
189
+ GLUT_CURSOR_BOTTOM_SIDE = 0x000D
190
+ GLUT_CURSOR_LEFT_SIDE = 0x000E
191
+ GLUT_CURSOR_RIGHT_SIDE = 0x000F
192
+ GLUT_CURSOR_TOP_LEFT_CORNER = 0x0010
193
+ GLUT_CURSOR_TOP_RIGHT_CORNER = 0x0011
194
+ GLUT_CURSOR_BOTTOM_RIGHT_CORNER = 0x0012
195
+ GLUT_CURSOR_BOTTOM_LEFT_CORNER = 0x0013
196
+ GLUT_CURSOR_INHERIT = 0x0064
197
+ GLUT_CURSOR_NONE = 0x0065
198
+ GLUT_CURSOR_FULL_CROSSHAIR = 0x0066
199
+
200
+ GLUT_RED = 0x0000
201
+ GLUT_GREEN = 0x0001
202
+ GLUT_BLUE = 0x0002
203
+
204
+ GLUT_KEY_REPEAT_OFF = 0x0000
205
+ GLUT_KEY_REPEAT_ON = 0x0001
206
+ GLUT_KEY_REPEAT_DEFAULT = 0x0002
207
+
208
+ GLUT_JOYSTICK_BUTTON_A = 0x0001
209
+ GLUT_JOYSTICK_BUTTON_B = 0x0002
210
+ GLUT_JOYSTICK_BUTTON_C = 0x0004
211
+ GLUT_JOYSTICK_BUTTON_D = 0x0008
212
+
213
+ GLUT_GAME_MODE_ACTIVE = 0x0000
214
+ GLUT_GAME_MODE_POSSIBLE = 0x0001
215
+ GLUT_GAME_MODE_WIDTH = 0x0002
216
+ GLUT_GAME_MODE_HEIGHT = 0x0003
217
+ GLUT_GAME_MODE_PIXEL_DEPTH = 0x0004
218
+ GLUT_GAME_MODE_REFRESH_RATE = 0x0005
219
+ GLUT_GAME_MODE_DISPLAY_CHANGED = 0x0006
220
+
221
+ # typedefs
222
+ @@glut_cb_function_signature = {
223
+ :GLUTMenuFunc => "void GLUTMenuFunc(int)",
224
+
225
+ :GLUTTimerFunc => "void GLUTTimerFunc(int)",
226
+ :GLUTIdleFunc => "void GLUTIdleFunc()",
227
+
228
+ :GLUTKeyboardFunc => "void GLUTKeyboardFunc(unsigned char, int, int)",
229
+ :GLUTSpecialFunc => "void GLUTSpecialFunc(int, int, int)",
230
+ :GLUTReshapeFunc => "void GLUTReshapeFunc(int, int)",
231
+ :GLUTVisibilityFunc => "void GLUTVisibilityFunc(int)",
232
+ :GLUTDisplayFunc => "void GLUTDisplayFunc()",
233
+ :GLUTMouseFunc => "void GLUTMouseFunc(int, int, int, int)",
234
+ :GLUTMotionFunc => "void GLUTMotionFunc(int, int)",
235
+ :GLUTPassiveMotionFunc => "void GLUTPassiveMotionFunc(int, int)",
236
+ :GLUTEntryFunc => "void GLUTEntryFunc(int)",
237
+
238
+ :GLUTKeyboardUpFunc => "void GLUTKeyboardUpFunc(unsigned char, int, int)",
239
+ :GLUTSpecialUpFunc => "void GLUTSpecialUpFunc(int, int, int)",
240
+ :GLUTJoystickFunc => "void GLUTJoystickFunc(unsigned int, int, int, int)",
241
+ :GLUTMenuStateFunc => "void GLUTMenuStateFunc(int)",
242
+ :GLUTMenuStatusFunc => "void GLUTMenuStatusFunc(int, int, int)",
243
+ :GLUTOverlayDisplayFunc => "void GLUTOverlayDisplayFunc()",
244
+ :GLUTWindowStatusFunc => "void GLUTWindowStatusFunc(int)",
245
+
246
+ :GLUTSpaceballMotionFunc => "void GLUTSpaceballMotionFunc(int, int, int)",
247
+ :GLUTSpaceballRotateFunc => "void GLUTSpaceballRotateFunc(int, int, int)",
248
+ :GLUTSpaceballButtonFunc => "void GLUTSpaceballButtonFunc(int, int)",
249
+ :GLUTButtonBoxFunc => "void GLUTButtonBoxFunc(int, int)",
250
+ :GLUTDialsFunc => "void GLUTDialsFunc(int, int)",
251
+ :GLUTTabletMotionFunc => "void GLUTTabletMotionFunc(int, int)",
252
+ :GLUTTabletButtonFunc => "void GLUTTabletButtonFunc(int, int, int, int)",
253
+ }
254
+
255
+ # Creates a callback as an instance of Fiddle::Function
256
+ def self.create_callback( sym, proc=nil, &blk )
257
+ if block_given?
258
+ return bind( @@glut_cb_function_signature[sym], nil, &blk )
259
+ else
260
+ return bind( @@glut_cb_function_signature[sym], nil, &proc )
261
+ end
262
+ end
263
+
264
+ GLUTMenuFunc_cb_args = [Fiddle::TYPE_INT]
265
+ GLUTMenuFunc_cb_retval = Fiddle::TYPE_VOID
266
+ GLUTTimerFunc_cb_args = [Fiddle::TYPE_INT]
267
+ GLUTTimerFunc_cb_retval = Fiddle::TYPE_VOID
268
+ GLUTIdleFunc_cb_args = []
269
+ GLUTIdleFunc_cb_retval = Fiddle::TYPE_VOID
270
+ GLUTKeyboardFunc_cb_args = [-Fiddle::TYPE_CHAR, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
271
+ GLUTKeyboardFunc_cb_retval = Fiddle::TYPE_VOID
272
+ GLUTSpecialFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
273
+ GLUTSpecialFunc_cb_retval = Fiddle::TYPE_VOID
274
+ GLUTReshapeFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
275
+ GLUTReshapeFunc_cb_retval = Fiddle::TYPE_VOID
276
+ GLUTVisibilityFunc_cb_args = [Fiddle::TYPE_INT]
277
+ GLUTVisibilityFunc_cb_retval = Fiddle::TYPE_VOID
278
+ GLUTDisplayFunc_cb_args = []
279
+ GLUTDisplayFunc_cb_retval = Fiddle::TYPE_VOID
280
+ GLUTMouseFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
281
+ GLUTMouseFunc_cb_retval = Fiddle::TYPE_VOID
282
+ GLUTMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
283
+ GLUTMotionFunc_cb_retval = Fiddle::TYPE_VOID
284
+ GLUTPassiveMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
285
+ GLUTPassiveMotionFunc_cb_retval = Fiddle::TYPE_VOID
286
+ GLUTEntryFunc_cb_args = [Fiddle::TYPE_INT]
287
+ GLUTEntryFunc_cb_retval = Fiddle::TYPE_VOID
288
+ GLUTKeyboardUpFunc_cb_args = [-Fiddle::TYPE_CHAR, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
289
+ GLUTKeyboardUpFunc_cb_retval = Fiddle::TYPE_VOID
290
+ GLUTSpecialUpFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
291
+ GLUTSpecialUpFunc_cb_retval = Fiddle::TYPE_VOID
292
+ GLUTJoystickFunc_cb_args = [-Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
293
+ GLUTJoystickFunc_cb_retval = Fiddle::TYPE_VOID
294
+ GLUTMenuStateFunc_cb_args = [Fiddle::TYPE_INT]
295
+ GLUTMenuStateFunc_cb_retval = Fiddle::TYPE_VOID
296
+ GLUTMenuStatusFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
297
+ GLUTMenuStatusFunc_cb_retval = Fiddle::TYPE_VOID
298
+ GLUTOverlayDisplayFunc_cb_args = []
299
+ GLUTOverlayDisplayFunc_cb_retval = Fiddle::TYPE_VOID
300
+ GLUTWindowStatusFunc_cb_args = [Fiddle::TYPE_INT]
301
+ GLUTWindowStatusFunc_cb_retval = Fiddle::TYPE_VOID
302
+ GLUTSpaceballMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
303
+ GLUTSpaceballMotionFunc_cb_retval = Fiddle::TYPE_VOID
304
+ GLUTSpaceballRotateFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
305
+ GLUTSpaceballRotateFunc_cb_retval = Fiddle::TYPE_VOID
306
+ GLUTSpaceballButtonFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
307
+ GLUTSpaceballButtonFunc_cb_retval = Fiddle::TYPE_VOID
308
+ GLUTButtonBoxFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
309
+ GLUTButtonBoxFunc_cb_retval = Fiddle::TYPE_VOID
310
+ GLUTDialsFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
311
+ GLUTDialsFunc_cb_retval = Fiddle::TYPE_VOID
312
+ GLUTTabletMotionFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT]
313
+ GLUTTabletMotionFunc_cb_retval = Fiddle::TYPE_VOID
314
+ GLUTTabletButtonFunc_cb_args = [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]
315
+ GLUTTabletButtonFunc_cb_retval = Fiddle::TYPE_VOID
316
+
317
+ @@glut_cb_closure_signature = {
318
+ :GLUTMenuFunc => [GLUTMenuFunc_cb_retval, GLUTMenuFunc_cb_args],
319
+ :GLUTTimerFunc => [GLUTTimerFunc_cb_retval, GLUTTimerFunc_cb_args],
320
+ :GLUTIdleFunc => [GLUTIdleFunc_cb_retval, GLUTIdleFunc_cb_args],
321
+ :GLUTKeyboardFunc => [GLUTKeyboardFunc_cb_retval, GLUTKeyboardFunc_cb_args],
322
+ :GLUTSpecialFunc => [GLUTSpecialFunc_cb_retval, GLUTSpecialFunc_cb_args],
323
+ :GLUTReshapeFunc => [GLUTReshapeFunc_cb_retval, GLUTReshapeFunc_cb_args],
324
+ :GLUTVisibilityFunc => [GLUTVisibilityFunc_cb_retval, GLUTVisibilityFunc_cb_args],
325
+ :GLUTDisplayFunc => [GLUTDisplayFunc_cb_retval, GLUTDisplayFunc_cb_args],
326
+ :GLUTMouseFunc => [GLUTMouseFunc_cb_retval, GLUTMouseFunc_cb_args],
327
+ :GLUTMotionFunc => [GLUTMotionFunc_cb_retval, GLUTMotionFunc_cb_args],
328
+ :GLUTPassiveMotionFunc => [GLUTPassiveMotionFunc_cb_retval, GLUTPassiveMotionFunc_cb_args],
329
+ :GLUTEntryFunc => [GLUTEntryFunc_cb_retval, GLUTEntryFunc_cb_args],
330
+ :GLUTKeyboardUpFunc => [GLUTKeyboardUpFunc_cb_retval, GLUTKeyboardUpFunc_cb_args],
331
+ :GLUTSpecialUpFunc => [GLUTSpecialUpFunc_cb_retval, GLUTSpecialUpFunc_cb_args],
332
+ :GLUTJoystickFunc => [GLUTJoystickFunc_cb_retval, GLUTJoystickFunc_cb_args],
333
+ :GLUTMenuStateFunc => [GLUTMenuStateFunc_cb_retval, GLUTMenuStateFunc_cb_args],
334
+ :GLUTMenuStatusFunc => [GLUTMenuStatusFunc_cb_retval, GLUTMenuStatusFunc_cb_args],
335
+ :GLUTOverlayDisplayFunc => [GLUTOverlayDisplayFunc_cb_retval, GLUTOverlayDisplayFunc_cb_args],
336
+ :GLUTWindowStatusFunc => [GLUTWindowStatusFunc_cb_retval, GLUTWindowStatusFunc_cb_args],
337
+ :GLUTSpaceballMotionFunc => [GLUTSpaceballMotionFunc_cb_retval, GLUTSpaceballMotionFunc_cb_args],
338
+ :GLUTSpaceballRotateFunc => [GLUTSpaceballRotateFunc_cb_retval, GLUTSpaceballRotateFunc_cb_args],
339
+ :GLUTSpaceballButtonFunc => [GLUTSpaceballButtonFunc_cb_retval, GLUTSpaceballButtonFunc_cb_args],
340
+ :GLUTButtonBoxFunc => [GLUTButtonBoxFunc_cb_retval, GLUTButtonBoxFunc_cb_args],
341
+ :GLUTDialsFunc => [GLUTDialsFunc_cb_retval, GLUTDialsFunc_cb_args],
342
+ :GLUTTabletMotionFunc => [GLUTTabletMotionFunc_cb_retval, GLUTTabletMotionFunc_cb_args],
343
+ :GLUTTabletButtonFunc => [GLUTTabletButtonFunc_cb_retval, GLUTTabletButtonFunc_cb_args],
344
+ }
345
+
346
+ # Creates a callback as an instance of Fiddle::Closure::BlockCaller
347
+ def self.create_callback_closure( sym, proc=nil, &blk )
348
+ cb_retval = @@glut_cb_closure_signature[sym][0]
349
+ cb_args = @@glut_cb_closure_signature[sym][1]
350
+ if block_given?
351
+ return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &blk )
352
+ else
353
+ return Fiddle::Closure::BlockCaller.new( cb_retval, cb_args, Fiddle::Function::DEFAULT, &proc )
354
+ end
355
+ end
356
+
357
+ # NOTE : Use 'create_callback_function' for backward compatibility.
358
+ def self.create_callback( sym, proc=nil, &blk )
359
+ return self.create_callback_closure( sym, proc, &blk )
360
+ end
361
+
362
+ @@glut_import_done = false
363
+
364
+ # Load native library.
365
+ def self.load_lib(lib = nil, path = nil)
366
+ if lib == nil && path == nil
367
+ case OpenGL.get_platform
368
+ when :OPENGL_PLATFORM_WINDOWS
369
+ lib, path = 'freeglut.dll', Dir.pwd
370
+ when :OPENGL_PLATFORM_MACOSX
371
+ lib, path = 'GLUT', '/System/Library/Frameworks/GLUT.framework'
372
+ else
373
+ lib, path = 'libglut.so'
374
+ end
375
+ end
376
+ if path
377
+ dlload (path + '/' + lib)
378
+ else
379
+ dlload (lib)
380
+ end
381
+ import_symbols() unless @@glut_import_done
382
+ end
383
+
384
+ def self.load_dll(lib = nil, path = nil)
385
+ puts "Warning GLUT.load_dll is deprecated, use GLUT.load_lib instead"
386
+ self.load_lib(lib, path)
387
+ end
388
+
389
+ def self.import_symbols
390
+ # defines
391
+ if OpenGL.get_platform == :OPENGL_PLATFORM_WINDOWS
392
+ const_set('GLUT_STROKE_ROMAN', Fiddle::Pointer.new(0x0000) )
393
+ const_set('GLUT_STROKE_MONO_ROMAN', Fiddle::Pointer.new(0x0001) )
394
+ const_set('GLUT_BITMAP_9_BY_15', Fiddle::Pointer.new(0x0002) )
395
+ const_set('GLUT_BITMAP_8_BY_13', Fiddle::Pointer.new(0x0003) )
396
+ const_set('GLUT_BITMAP_TIMES_ROMAN_10', Fiddle::Pointer.new(0x0004) )
397
+ const_set('GLUT_BITMAP_TIMES_ROMAN_24', Fiddle::Pointer.new(0x0005) )
398
+ const_set('GLUT_BITMAP_HELVETICA_10', Fiddle::Pointer.new(0x0006) )
399
+ const_set('GLUT_BITMAP_HELVETICA_12', Fiddle::Pointer.new(0x0007) )
400
+ const_set('GLUT_BITMAP_HELVETICA_18', Fiddle::Pointer.new(0x0008) )
401
+ else
402
+ const_set('GLUT_STROKE_ROMAN', import_symbol("glutStrokeRoman") )
403
+ const_set('GLUT_STROKE_MONO_ROMAN', import_symbol("glutStrokeMonoRoman") )
404
+ const_set('GLUT_BITMAP_9_BY_15', import_symbol("glutBitmap9By15") )
405
+ const_set('GLUT_BITMAP_8_BY_13', import_symbol("glutBitmap8By13") )
406
+ const_set('GLUT_BITMAP_TIMES_ROMAN_10', import_symbol("glutBitmapTimesRoman10") )
407
+ const_set('GLUT_BITMAP_TIMES_ROMAN_24', import_symbol("glutBitmapTimesRoman24") )
408
+ const_set('GLUT_BITMAP_HELVETICA_10', import_symbol("glutBitmapHelvetica10") )
409
+ const_set('GLUT_BITMAP_HELVETICA_12', import_symbol("glutBitmapHelvetica12") )
410
+ const_set('GLUT_BITMAP_HELVETICA_18', import_symbol("glutBitmapHelvetica18") )
411
+ end
412
+
413
+ # function
414
+ extern 'void glutInit(int*, char**)'
415
+ extern 'void glutInitWindowPosition(int, int)'
416
+ extern 'void glutInitWindowSize(int, int)'
417
+ extern 'void glutInitDisplayMode(unsigned int)'
418
+ extern 'void glutInitDisplayString(const char*)'
419
+
420
+ extern 'void glutMainLoop()'
421
+
422
+ extern 'int glutCreateWindow(const char *)'
423
+ extern 'int glutCreateSubWindow(int, int, int, int, int)'
424
+ extern 'void glutDestroyWindow(int)'
425
+ extern 'void glutSetWindow(int)'
426
+ extern 'int glutGetWindow()'
427
+ extern 'void glutSetWindowTitle(const char *)'
428
+ extern 'void glutSetIconTitle(const char *)'
429
+ extern 'void glutReshapeWindow(int, int)'
430
+ extern 'void glutPositionWindow(int, int)'
431
+ extern 'void glutShowWindow()'
432
+ extern 'void glutHideWindow()'
433
+ extern 'void glutIconifyWindow()'
434
+ extern 'void glutPushWindow()'
435
+ extern 'void glutPopWindow()'
436
+ extern 'void glutFullScreen()'
437
+
438
+ extern 'void glutPostWindowRedisplay(int)'
439
+ extern 'void glutPostRedisplay()'
440
+ extern 'void glutSwapBuffers()'
441
+
442
+ extern 'void glutWarpPointer(int, int)'
443
+ extern 'void glutSetCursor(int)'
444
+
445
+ extern 'void glutEstablishOverlay()'
446
+ extern 'void glutRemoveOverlay()'
447
+ extern 'void glutUseLayer(unsigned int)'
448
+ extern 'void glutPostOverlayRedisplay()'
449
+ extern 'void glutPostWindowOverlayRedisplay(int)'
450
+ extern 'void glutShowOverlay()'
451
+ extern 'void glutHideOverlay()'
452
+
453
+ extern 'int glutCreateMenu(void *)'
454
+ extern 'void glutDestroyMenu(int)'
455
+ extern 'int glutGetMenu()'
456
+ extern 'void glutSetMenu(int)'
457
+ extern 'void glutAddMenuEntry(const char *, int)'
458
+ extern 'void glutAddSubMenu(const char *, int)'
459
+ extern 'void glutChangeToMenuEntry(int, const char *, int)'
460
+ extern 'void glutChangeToSubMenu(int, const char *, int)'
461
+ extern 'void glutRemoveMenuItem(int)'
462
+ extern 'void glutAttachMenu(int)'
463
+ extern 'void glutDetachMenu(int)'
464
+
465
+ extern 'void glutTimerFunc(unsigned int, void *, int)'
466
+ extern 'void glutIdleFunc(void *)'
467
+
468
+ extern 'void glutKeyboardFunc(void *)'
469
+ extern 'void glutSpecialFunc(void *)'
470
+ extern 'void glutReshapeFunc(void *)'
471
+ extern 'void glutVisibilityFunc(void *)'
472
+ extern 'void glutDisplayFunc(void *)'
473
+ extern 'void glutMouseFunc(void *)'
474
+ extern 'void glutMotionFunc(void *)'
475
+ extern 'void glutPassiveMotionFunc(void *)'
476
+ extern 'void glutEntryFunc(void *)'
477
+
478
+ extern 'void glutKeyboardUpFunc(void *)'
479
+ extern 'void glutSpecialUpFunc(void *)'
480
+ extern 'void glutJoystickFunc(void *, int)'
481
+ extern 'void glutMenuStateFunc(void *)'
482
+ extern 'void glutMenuStatusFunc(void *)'
483
+ extern 'void glutOverlayDisplayFunc(void *)'
484
+ extern 'void glutWindowStatusFunc(void *)'
485
+
486
+ extern 'void glutSpaceballMotionFunc(void *)'
487
+ extern 'void glutSpaceballRotateFunc(void *)'
488
+ extern 'void glutSpaceballButtonFunc(void *)'
489
+ extern 'void glutButtonBoxFunc(void *)'
490
+ extern 'void glutDialsFunc(void *)'
491
+ extern 'void glutTabletMotionFunc(void *)'
492
+ extern 'void glutTabletButtonFunc(void *)'
493
+
494
+ extern 'int glutGet(unsigned int)'
495
+ extern 'int glutDeviceGet(unsigned int)'
496
+ extern 'int glutGetModifiers()'
497
+ extern 'int glutLayerGet(unsigned int)'
498
+
499
+ extern 'void glutBitmapCharacter(void *, int)'
500
+ extern 'int glutBitmapWidth(void *, int)'
501
+ extern 'void glutStrokeCharacter(void *, int)'
502
+ extern 'int glutStrokeWidth(void *, int)'
503
+ extern 'int glutBitmapLength(void *, const unsigned char*)'
504
+ extern 'int glutStrokeLength(void *, const unsigned char*)'
505
+
506
+ extern 'void glutWireCube(double)'
507
+ extern 'void glutSolidCube(double)'
508
+ extern 'void glutWireSphere(double, int, int)'
509
+ extern 'void glutSolidSphere(double, int, int)'
510
+ extern 'void glutWireCone(double, double, int, int)'
511
+ extern 'void glutSolidCone(double, double, int, int)'
512
+
513
+ extern 'void glutWireTorus(double, double, int, int)'
514
+ extern 'void glutSolidTorus(double, double, int, int)'
515
+ extern 'void glutWireDodecahedron()'
516
+ extern 'void glutSolidDodecahedron()'
517
+ extern 'void glutWireOctahedron()'
518
+ extern 'void glutSolidOctahedron()'
519
+ extern 'void glutWireTetrahedron()'
520
+ extern 'void glutSolidTetrahedron()'
521
+ extern 'void glutWireIcosahedron()'
522
+ extern 'void glutSolidIcosahedron()'
523
+
524
+ extern 'void glutWireTeapot(double)'
525
+ extern 'void glutSolidTeapot(double)'
526
+
527
+ extern 'void glutGameModeString(const char*)'
528
+ extern 'int glutEnterGameMode()'
529
+ extern 'void glutLeaveGameMode()'
530
+ extern 'int glutGameModeGet(unsigned int)'
531
+
532
+ extern 'int glutVideoResizeGet(unsigned int)'
533
+ extern 'void glutSetupVideoResizing()'
534
+ extern 'void glutStopVideoResizing()'
535
+ extern 'void glutVideoResize(int, int, int, int)'
536
+ extern 'void glutVideoPan(int, int, int, int)'
537
+
538
+ extern 'void glutSetColor(int, float, float, float)'
539
+ extern 'float glutGetColor(int, int)'
540
+ extern 'void glutCopyColormap(int)'
541
+
542
+ extern 'void glutIgnoreKeyRepeat(int)'
543
+ extern 'void glutSetKeyRepeat(int)'
544
+ extern 'void glutForceJoystickFunc()'
545
+
546
+ extern 'int glutExtensionSupported(const char *)'
547
+ extern 'void glutReportErrors()'
548
+
549
+ @@glut_import_done = true
550
+ end
551
+
552
+ end
553
+
554
+ =begin
555
+ Ruby-OpenGL : Yet another OpenGL wrapper for Ruby (and wrapper code generator)
556
+ Copyright (c) 2013-2021 vaiorabbit <http://twitter.com/vaiorabbit>
557
+
558
+ This software is provided 'as-is', without any express or implied
559
+ warranty. In no event will the authors be held liable for any damages
560
+ arising from the use of this software.
561
+
562
+ Permission is granted to anyone to use this software for any purpose,
563
+ including commercial applications, and to alter it and redistribute it
564
+ freely, subject to the following restrictions:
565
+
566
+ 1. The origin of this software must not be misrepresented; you must not
567
+ claim that you wrote the original software. If you use this software
568
+ in a product, an acknowledgment in the product documentation would be
569
+ appreciated but is not required.
570
+
571
+ 2. Altered source versions must be plainly marked as such, and must not be
572
+ misrepresented as being the original software.
573
+
574
+ 3. This notice may not be removed or altered from any source
575
+ distribution.
576
+ =end