New upstream version 8.3.0
Sophie Brun
4 years ago
0 | require 'autotest/restart' | |
1 | ||
2 | Autotest.add_hook :initialize do |at| | |
3 | at.add_exception /\.git/ | |
4 | at.add_exception /doc/ | |
5 | at.add_exception /examples/ | |
6 | at.add_exception /utils/ | |
7 | at.add_exception /website/ | |
8 | ||
9 | at.add_mapping(/^lib\/.*(\.bundle|so|dll)$/) do |filename, match| | |
10 | possible = File.basename(filename, match[1]) | |
11 | at.files_matching %r%^test/test_#{possible}% | |
12 | end | |
13 | ||
14 | def at.path_to_classname s | |
15 | sep = File::SEPARATOR | |
16 | n = s.sub(/^test#{sep}test_(.*)\.rb/, '\1') | |
17 | c = if n =~ /^(glu?)_?(.*)/ then | |
18 | "#{$1.capitalize}#{$2.split(/_|(\d+)/).map { |seg| seg.capitalize }.join}" | |
19 | end | |
20 | ||
21 | "Test#{c}" | |
22 | end | |
23 | end | |
24 | ||
25 | Autotest.add_hook :run_command do |at| | |
26 | at.unit_diff = 'cat' | |
27 | system Gem.ruby, Gem.bin_path('rake', 'rake'), 'compile' | |
28 | end |
0 | language: ruby | |
1 | rvm: | |
2 | # - "1.9.3" | |
3 | - "2.0.0" | |
4 | # - jruby-19mode # JRuby in 1.9 mode | |
5 | # - rbx-19mode | |
6 | before_install: | |
7 | - gem install hoe rake-compiler; | |
8 | - sudo apt-get install xpra xserver-xorg-video-dummy freeglut3-dev; | |
9 | before_script: | |
10 | - "xpra --xvfb=\"Xorg +extension GLX -config `pwd`/test/dummy.xorg.conf -logfile ${HOME}/.xpra/xorg.log\" start :9" | |
11 | script: "env DISPLAY=:9 rake test" | |
12 | after_script: | |
13 | - "xpra stop :9" | |
14 | - "cat ~/.xpra/*" |
0 | === 8.3.0 / 2017-05-30 | |
1 | ||
2 | * Add ruby-2.4 to binary windows gems and remove ruby-1.9. | |
3 | * Add support for source gems on RubyInstaller-2.4 and MSYS2. | |
4 | ||
5 | === 8.2.2 / 2016-01-21 | |
6 | ||
7 | * Add ruby-2.2 and 2.3 to binary windows gems. | |
8 | * Fix compilation on OS-X. Github #2 | |
9 | ||
10 | === 8.2.1 / 2014-10-06 | |
11 | ||
12 | * Add ruby-2.1 to binary windows gems. | |
13 | * Fix segmentation fault in glutKeyboardUpFunc callback | |
14 | ||
15 | === 8.2.0 / 2014-03-14 | |
16 | ||
17 | * Add x64-mingw platform for cross build and add ruby-2.0.0 to binary gems. | |
18 | * Update to freeglut-2.8.1 for cross build. | |
19 | * Don't pollute the global namespace. Use GLUT namespace. | |
20 | * Replace deprecated rb_thread_blocking_region() by rb_thread_call_with_gvl() | |
21 | ||
22 | === 8.1.0 / 2013-03-03 | |
23 | ||
24 | * Moved glut into a standalone gem. |
0 | ||
1 | Permission is hereby granted, free of charge, to any person obtaining a | |
2 | copy of this software and associated documentation files (the "Software"), | |
3 | to deal in the Software without restriction, including without limitation | |
4 | the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
5 | and/or sell copies of the Software, and to permit persons to whom the | |
6 | Software is furnished to do so, subject to the following conditions: | |
7 | ||
8 | The above copyright notice and this permission notice shall be included in | |
9 | all copies or substantial portions of the Software. | |
10 | ||
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
16 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
17 | DEALINGS IN THE SOFTWARE. |
0 | .autotest | |
1 | .gemtest | |
2 | .gitignore | |
3 | .travis.yml | |
4 | History.rdoc | |
5 | MIT-LICENSE | |
6 | Manifest.txt | |
7 | README.rdoc | |
8 | Rakefile | |
9 | ext/glut/common.h | |
10 | ext/glut/extconf.rb | |
11 | ext/glut/glut.c | |
12 | ext/glut/glut_callbacks.c | |
13 | ext/glut/glut_ext.c | |
14 | lib/glut.rb | |
15 | lib/glut/dummy.rb |
0 | = glut | |
1 | ||
2 | == Description | |
3 | ||
4 | Glut bindings for OpenGL. To be used with the {opengl}[https://github.com/larskanis/opengl] gem. | |
5 | ||
6 | == Features and Problems | |
7 | ||
8 | * available for Windows, Linux and OS X | |
9 | ||
10 | == Requirements | |
11 | ||
12 | * Ruby 1.9.2+ | |
13 | * see {0.7}[https://github.com/archSeer/opengl/tree/0.7] for Ruby 1.8.x compatible branch | |
14 | * (free-)GLUT development files installed | |
15 | ||
16 | == Install | |
17 | ||
18 | gem install glut | |
19 | ||
20 | == Cross compiling for Windows | |
21 | ||
22 | Using rake-compiler a cross compiled opengl gem can be build on a Linux or MacOS X | |
23 | host for the win32 platform. The generated gem is statically linked against | |
24 | libfreeglut. Freeglut is downloaded and compiled from the sources. | |
25 | There are no runtime dependencies to any but the standard Windows | |
26 | DLLs. | |
27 | ||
28 | Install mingw32 or w64 using the instructions in rake-compiler's README. | |
29 | For Debian/Ubuntu it is <tt>apt-get install gcc-mingw-w64</tt> . | |
30 | ||
31 | Download and cross compile ruby 1.9 for win32 with: | |
32 | ||
33 | rake-compiler cross-ruby VERSION=1.9.3-p0 | |
34 | ||
35 | Download and cross compile opengl for win32: | |
36 | ||
37 | rake cross native gem | |
38 | ||
39 | or with custom versions: | |
40 | ||
41 | rake cross native gem RUBY_CC_VERSION=1.9.3 LIBFREEGLUT_VERSION=2.8.0 | |
42 | ||
43 | If everything works, there should be ruby-opengl-VERSION-x86-mingw32.gem in the pkg | |
44 | directory. | |
45 | ||
46 | ||
47 | == License | |
48 | ||
49 | (The MIT License) | |
50 | ||
51 | Copyright (c) Blaž Hrastnik (current maintainer) | |
52 | Copyright (c) Eric Hodel (current maintainer) | |
53 | Copyright (c) Alain Hoang (previous maintainer) | |
54 | Copyright (c) Jan Dvorak (contributor) | |
55 | Copyright (c) Minh Thu Vo (contributor) | |
56 | Copyright (c) James Adam (contributor) | |
57 | ||
58 | Permission is hereby granted, free of charge, to any person obtaining | |
59 | a copy of this software and associated documentation files (the | |
60 | 'Software'), to deal in the Software without restriction, including | |
61 | without limitation the rights to use, copy, modify, merge, publish, | |
62 | distribute, sublicense, and/or sell copies of the Software, and to | |
63 | permit persons to whom the Software is furnished to do so, subject to | |
64 | the following conditions: | |
65 | ||
66 | The above copyright notice and this permission notice shall be | |
67 | included in all copies or substantial portions of the Software. | |
68 | ||
69 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | |
70 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
71 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
72 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
73 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
74 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
75 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
76 |
0 | # -*- coding: UTF-8 -*- | |
1 | # -*-ruby-*- | |
2 | # | |
3 | # Copyright (C) 2006 John M. Gabriele <[email protected]> | |
4 | # Copyright (C) Eric Hodel <[email protected]> | |
5 | # | |
6 | # This program is distributed under the terms of the MIT license. | |
7 | # See the included MIT-LICENSE file for the terms of this license. | |
8 | # | |
9 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
10 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
11 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
12 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
13 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
14 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
15 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
16 | ||
17 | require 'hoe' | |
18 | require 'rake/extensiontask' | |
19 | ||
20 | hoe = Hoe.spec 'glut' do | |
21 | developer 'Eric Hodel', '[email protected]' | |
22 | developer 'Lars Kanis', '[email protected]' | |
23 | developer 'Blaž Hrastnik', '[email protected]' | |
24 | developer 'Alain Hoang', '' | |
25 | developer 'Jan Dvorak', '' | |
26 | developer 'Minh Thu Vo', '' | |
27 | developer 'James Adam', '' | |
28 | ||
29 | self.readme_file = 'README.rdoc' | |
30 | self.history_file = 'History.rdoc' | |
31 | self.extra_rdoc_files = FileList['*.rdoc'] | |
32 | ||
33 | extra_dev_deps << ['rake-compiler', '~> 1.0'] | |
34 | extra_dev_deps << ['rake-compiler-dock', '~> 0.6.0'] | |
35 | extra_dev_deps << ['mini_portile2', '~> 2.1'] | |
36 | ||
37 | self.spec_extras = { | |
38 | :extensions => %w[ext/glut/extconf.rb], | |
39 | :required_ruby_version => '>= 1.9.2', | |
40 | :metadata => {'msys2_mingw_dependencies' => 'freeglut'}, | |
41 | } | |
42 | end | |
43 | ||
44 | Rake::ExtensionTask.new 'glut', hoe.spec do |ext| | |
45 | ext.lib_dir = 'lib/glut' | |
46 | ||
47 | ext.cross_compile = true | |
48 | ext.cross_platform = ['x86-mingw32', 'x64-mingw32'] | |
49 | ext.cross_config_options += [ | |
50 | "--enable-win32-cross", | |
51 | ] | |
52 | ext.cross_compiling do |spec| | |
53 | # The fat binary gem doesn't depend on the freeglut package, since it bundles the library. | |
54 | spec.metadata.delete('msys2_mingw_dependencies') | |
55 | end | |
56 | end | |
57 | ||
58 | ||
59 | # To reduce the gem file size strip mingw32 dlls before packaging | |
60 | ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version| | |
61 | task "copy:glut:x86-mingw32:#{ruby_version}" do |t| | |
62 | sh "i686-w64-mingw32-strip -S tmp/x86-mingw32/stage/lib/glut/#{ruby_version[/^\d+\.\d+/]}/glut.so" | |
63 | end | |
64 | ||
65 | task "copy:glut:x64-mingw32:#{ruby_version}" do |t| | |
66 | sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/glut/#{ruby_version[/^\d+\.\d+/]}/glut.so" | |
67 | end | |
68 | end | |
69 | ||
70 | desc "Build windows binary gems per rake-compiler-dock." | |
71 | task "gem:windows" do | |
72 | require "rake_compiler_dock" | |
73 | RakeCompilerDock.sh <<-EOT | |
74 | rake cross native gem MAKE='nice make -j`nproc`' | |
75 | EOT | |
76 | end | |
77 | ||
78 | task :test => :compile |
0 | /* | |
1 | * Last edit by previous maintainer: | |
2 | * 2000/01/06 16:37:43, kusano | |
3 | * | |
4 | * Copyright (C) 1999 - 2005 Yoshi <[email protected]> | |
5 | * Copyright (C) 2006 John M. Gabriele <[email protected]> | |
6 | * Copyright (C) 2007 James Adam <[email protected]> | |
7 | * Copyright (C) 2007 Jan Dvorak <[email protected]> | |
8 | * | |
9 | * This program is distributed under the terms of the MIT license. | |
10 | * See the included MIT-LICENSE file for the terms of this license. | |
11 | * | |
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
15 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
16 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
17 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
19 | */ | |
20 | ||
21 | #ifndef _COMMON_H_ | |
22 | #define _COMMON_H_ | |
23 | ||
24 | #include <ruby.h> | |
25 | #include "extconf.h" | |
26 | ||
27 | #ifdef HAVE_GL_FREEGLUT_H | |
28 | #include <GL/freeglut.h> | |
29 | #endif | |
30 | ||
31 | #ifdef HAVE_GL_GLUT_H | |
32 | #include <GL/glut.h> | |
33 | #endif | |
34 | ||
35 | #ifdef HAVE_GLUT_GLUT_H | |
36 | #include <GLUT/glut.h> | |
37 | #endif | |
38 | ||
39 | #ifndef GLUTCALLBACK | |
40 | #define GLUTCALLBACK | |
41 | #endif | |
42 | ||
43 | #ifdef HAVE_WINDOWS_H | |
44 | #define DLLEXPORT __declspec(dllexport) | |
45 | #else | |
46 | #define DLLEXPORT | |
47 | #endif | |
48 | ||
49 | /* these two macros are cast to a 32 bit type in the places they are used */ | |
50 | #ifndef RARRAY_LENINT | |
51 | #define RARRAY_LENINT RARRAY_LEN | |
52 | #endif | |
53 | ||
54 | /* GLUT */ | |
55 | ||
56 | #define GLUT_SIMPLE_FUNCTION(_name_) \ | |
57 | static VALUE \ | |
58 | glut_##_name_(obj) \ | |
59 | VALUE obj; \ | |
60 | { \ | |
61 | glut##_name_(); \ | |
62 | return Qnil; \ | |
63 | } | |
64 | ||
65 | VALUE rb_glut_check_callback(VALUE, VALUE); | |
66 | ||
67 | #endif |
0 | require 'mkmf' | |
1 | ||
2 | def have_framework(fw, &b) | |
3 | checking_for fw do | |
4 | src = cpp_include("#{fw}/#{fw}.h") << "\n" "int main(void){return 0;}" | |
5 | if try_link(src, opt = "-ObjC -framework #{fw}", &b) | |
6 | $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp)) | |
7 | $LDFLAGS << " " << opt | |
8 | true | |
9 | else | |
10 | false | |
11 | end | |
12 | end | |
13 | end unless respond_to? :have_framework | |
14 | ||
15 | if enable_config('win32-cross') | |
16 | require "rubygems" | |
17 | gem "mini_portile2", "~> 2.0" | |
18 | require "mini_portile2" | |
19 | ||
20 | LIBFREEGLUT_VERSION = ENV['LIBFREEGLUT_VERSION'] || '2.8.1' | |
21 | LIBFREEGLUT_SOURCE_URI = "http://downloads.sourceforge.net/project/freeglut/freeglut/#{LIBFREEGLUT_VERSION}/freeglut-#{LIBFREEGLUT_VERSION}.tar.gz" | |
22 | ||
23 | recipe = MiniPortile.new("libglut", LIBFREEGLUT_VERSION) | |
24 | recipe.files = [LIBFREEGLUT_SOURCE_URI] | |
25 | recipe.target = portsdir = File.expand_path('../../../ports', __FILE__) | |
26 | # Prefer host_alias over host in order to use i586-mingw32msvc as | |
27 | # correct compiler prefix for cross build, but use host if not set. | |
28 | recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"] | |
29 | recipe.configure_options = [ | |
30 | "--enable-static", | |
31 | "--target=#{recipe.host}", | |
32 | "--host=#{recipe.host}", | |
33 | ] | |
34 | ||
35 | checkpoint = File.join(portsdir, "#{recipe.name}-#{recipe.version}-#{recipe.host}.installed") | |
36 | unless File.exist?(checkpoint) | |
37 | recipe.cook | |
38 | # --disable-static can not be used since it breaks the freeglut build, | |
39 | # but to enforce static linking, we delete the import lib. | |
40 | FileUtils.rm File.join(recipe.path, "lib", "libglut.dll.a") | |
41 | FileUtils.touch checkpoint | |
42 | end | |
43 | recipe.activate | |
44 | ||
45 | $defs.push "-DFREEGLUT_EXPORTS" | |
46 | dir_config('freeglut', "#{recipe.path}/include", "#{recipe.path}/lib") | |
47 | ||
48 | # libfreeglut is linked to gdi32 and winmm | |
49 | have_library( 'gdi32', 'CreateDC' ) && append_library( $libs, 'gdi32' ) | |
50 | have_library( 'winmm', 'timeBeginPeriod' ) && append_library( $libs, 'winmm' ) | |
51 | end | |
52 | ||
53 | ok = | |
54 | (have_library('opengl32.lib', 'glVertex3d') && have_library('glut32.lib', 'gluSolidTeapot')) || | |
55 | (have_library('opengl32') && (have_library('glut') || have_library('freeglut'))) || | |
56 | (have_library('GL', 'glVertex3d') && have_library('glut', 'glutSolidTeapot')) || | |
57 | (have_framework('OpenGL') && have_framework('GLUT') && have_framework('Cocoa')) | |
58 | ||
59 | ok &&= | |
60 | have_header('GL/freeglut.h') || | |
61 | have_header('GL/glut.h') || | |
62 | have_header('GLUT/glut.h') # OS X | |
63 | ||
64 | if String === ?a then | |
65 | $defs.push "-DHAVE_SINGLE_BYTE_STRINGS" | |
66 | end | |
67 | ||
68 | if ok then | |
69 | create_header | |
70 | create_makefile 'glut/glut' | |
71 | end |
0 | /* | |
1 | * Last edit by previous maintainer: | |
2 | * 2004/03/02 01:13:06, yoshi | |
3 | * | |
4 | * Copyright (C) 1999 - 2005 Yoshi <[email protected]> | |
5 | * Copyright (C) 2005 James Adam <[email protected]> | |
6 | * Copyright (C) 2006 John M. Gabriele <[email protected]> | |
7 | * Copyright (C) 2007 Jan Dvorak <[email protected]> | |
8 | * | |
9 | * This program is distributed under the terms of the MIT license. | |
10 | * See the included COPYRIGHT file for the terms of this license. | |
11 | * | |
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
15 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
16 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
17 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
19 | * | |
20 | */ | |
21 | ||
22 | #include "common.h" | |
23 | extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1, | |
24 | rb_unblock_function_t *ubf, void *data2); | |
25 | ||
26 | static VALUE menu_callback = Qnil; | |
27 | static ID call_id; /* 'call' method id */ | |
28 | ||
29 | VALUE | |
30 | rb_glut_check_callback(VALUE self, VALUE callback) | |
31 | { | |
32 | VALUE inspect; | |
33 | ||
34 | if (NIL_P(callback)) | |
35 | return callback; | |
36 | ||
37 | if (rb_respond_to(callback, call_id)) | |
38 | return callback; | |
39 | ||
40 | if (SYMBOL_P(callback)) | |
41 | return rb_obj_method(self, callback); | |
42 | ||
43 | inspect = rb_inspect(callback); | |
44 | rb_raise(rb_eArgError, "%s must respond to call", StringValueCStr(inspect)); | |
45 | } | |
46 | ||
47 | static VALUE glut_Init( int argc, VALUE * argv, VALUE obj) | |
48 | { | |
49 | int largc; | |
50 | char** largv; | |
51 | VALUE new_argv; | |
52 | VALUE orig_arg; | |
53 | int i; | |
54 | ||
55 | if (rb_scan_args(argc, argv, "01", &orig_arg) == 0) | |
56 | orig_arg = rb_eval_string("[$0] + ARGV"); | |
57 | else | |
58 | Check_Type(orig_arg, T_ARRAY); | |
59 | ||
60 | /* converts commandline parameters from ruby to C, passes them | |
61 | to glutInit and returns the parameters stripped of glut-specific | |
62 | commands ("-display","-geometry" etc.) */ | |
63 | largc = (int)RARRAY_LENINT(orig_arg); | |
64 | largv = ALLOCA_N(char*, largc); | |
65 | for (i = 0; i < largc; i++) | |
66 | largv[i] = StringValueCStr(RARRAY_PTR(orig_arg)[i]); | |
67 | ||
68 | glutInit(&largc, largv); | |
69 | ||
70 | new_argv = rb_ary_new2(largc); | |
71 | for (i = 0; i < largc; i++) | |
72 | rb_ary_push(new_argv,rb_str_new2(largv[i])); | |
73 | ||
74 | rb_ary_shift(new_argv); | |
75 | ||
76 | return new_argv; | |
77 | } | |
78 | ||
79 | static VALUE glut_InitDisplayMode(obj,arg1) | |
80 | VALUE obj,arg1; | |
81 | { | |
82 | unsigned int mode; | |
83 | mode = (unsigned int)NUM2INT(arg1); | |
84 | glutInitDisplayMode(mode); | |
85 | return Qnil; | |
86 | } | |
87 | ||
88 | static VALUE | |
89 | glut_InitDisplayString(obj,arg1) | |
90 | VALUE obj,arg1; | |
91 | { | |
92 | Check_Type(arg1,T_STRING); | |
93 | glutInitDisplayString(RSTRING_PTR(arg1)); | |
94 | return Qnil; | |
95 | } | |
96 | ||
97 | static VALUE | |
98 | glut_InitWindowPosition(obj,arg1,arg2) | |
99 | VALUE obj,arg1,arg2; | |
100 | { | |
101 | int x,y; | |
102 | x = NUM2INT(arg1); | |
103 | y = NUM2INT(arg2); | |
104 | glutInitWindowPosition(x,y); | |
105 | return Qnil; | |
106 | } | |
107 | ||
108 | static VALUE | |
109 | glut_InitWindowSize(obj, arg1, arg2) | |
110 | VALUE obj,arg1,arg2; | |
111 | { | |
112 | int width,height; | |
113 | width = NUM2INT(arg1); | |
114 | height = NUM2INT(arg2); | |
115 | glutInitWindowSize(width,height); | |
116 | return Qnil; | |
117 | } | |
118 | ||
119 | void *glut_MainLoop0(void *ignored) { | |
120 | glutMainLoop(); | |
121 | ||
122 | return NULL; /* never reached */ | |
123 | } | |
124 | ||
125 | static VALUE | |
126 | glut_MainLoop(void) { | |
127 | rb_thread_call_without_gvl(glut_MainLoop0, NULL, NULL, NULL); | |
128 | ||
129 | return Qnil; /* never reached */ | |
130 | } | |
131 | ||
132 | static VALUE | |
133 | glut_CheckLoop(void) { | |
134 | rb_warn("calling fake CheckLoop implementation which never returns"); | |
135 | ||
136 | glut_MainLoop(); | |
137 | ||
138 | return Qnil; | |
139 | } | |
140 | ||
141 | /* GLUT window sub-API. */ | |
142 | static VALUE glut_CreateWindow(argc, argv, obj) | |
143 | int argc; | |
144 | VALUE* argv; | |
145 | VALUE obj; | |
146 | { | |
147 | int ret; | |
148 | VALUE title; | |
149 | rb_scan_args(argc, argv, "01", &title); | |
150 | if (argc == 0) | |
151 | title = rb_eval_string("$0"); | |
152 | Check_Type(title,T_STRING); | |
153 | ret = glutCreateWindow(RSTRING_PTR(title)); | |
154 | return INT2NUM(ret); | |
155 | } | |
156 | ||
157 | static VALUE | |
158 | glut_CreateSubWindow(obj,arg1,arg2,arg3,arg4,arg5) | |
159 | VALUE obj,arg1,arg2,arg3,arg4,arg5; | |
160 | { | |
161 | int win, x, y, width, height; | |
162 | int ret; | |
163 | win = NUM2INT(arg1); | |
164 | x = NUM2INT(arg2); | |
165 | y = NUM2INT(arg3); | |
166 | width = NUM2INT(arg4); | |
167 | height = NUM2INT(arg5); | |
168 | ret = glutCreateSubWindow(win, x, y, width, height); | |
169 | return INT2NUM(ret); | |
170 | } | |
171 | ||
172 | static VALUE | |
173 | glut_DestroyWindow(obj,arg1) | |
174 | VALUE obj,arg1; | |
175 | { | |
176 | int win; | |
177 | win = NUM2INT(arg1); | |
178 | glutDestroyWindow(win); | |
179 | return Qnil; | |
180 | } | |
181 | ||
182 | GLUT_SIMPLE_FUNCTION(PostRedisplay) | |
183 | GLUT_SIMPLE_FUNCTION(SwapBuffers) | |
184 | ||
185 | static VALUE | |
186 | glut_GetWindow(obj) | |
187 | VALUE obj; | |
188 | { | |
189 | int ret; | |
190 | ret = glutGetWindow(); | |
191 | return INT2NUM(ret); | |
192 | } | |
193 | ||
194 | static VALUE | |
195 | glut_SetWindow(obj,arg1) | |
196 | VALUE obj,arg1; | |
197 | { | |
198 | int win; | |
199 | win = NUM2INT(arg1); | |
200 | glutSetWindow(win); | |
201 | return Qnil; | |
202 | } | |
203 | ||
204 | static VALUE | |
205 | glut_SetWindowTitle(obj,arg1) | |
206 | VALUE obj,arg1; | |
207 | { | |
208 | Check_Type(arg1,T_STRING); | |
209 | glutSetWindowTitle(RSTRING_PTR(arg1)); | |
210 | return Qnil; | |
211 | } | |
212 | ||
213 | static VALUE | |
214 | glut_SetIconTitle(obj, arg1) | |
215 | VALUE obj,arg1; | |
216 | { | |
217 | Check_Type(arg1,T_STRING); | |
218 | glutSetIconTitle(RSTRING_PTR(arg1)); | |
219 | return Qnil; | |
220 | } | |
221 | ||
222 | static VALUE | |
223 | glut_PositionWindow(obj,arg1,arg2) | |
224 | VALUE obj,arg1,arg2; | |
225 | { | |
226 | int x,y; | |
227 | x = NUM2INT(arg1); | |
228 | y = NUM2INT(arg2); | |
229 | glutPositionWindow(x,y); | |
230 | return Qnil; | |
231 | } | |
232 | ||
233 | static VALUE | |
234 | glut_ReshapeWindow(obj,arg1,arg2) | |
235 | VALUE obj,arg1,arg2; | |
236 | { | |
237 | int width,height; | |
238 | width = NUM2INT(arg1); | |
239 | height = NUM2INT(arg2); | |
240 | glutReshapeWindow(width, height); | |
241 | return Qnil; | |
242 | } | |
243 | ||
244 | GLUT_SIMPLE_FUNCTION(PopWindow) | |
245 | GLUT_SIMPLE_FUNCTION(PushWindow) | |
246 | GLUT_SIMPLE_FUNCTION(IconifyWindow) | |
247 | GLUT_SIMPLE_FUNCTION(ShowWindow) | |
248 | GLUT_SIMPLE_FUNCTION(HideWindow) | |
249 | GLUT_SIMPLE_FUNCTION(FullScreen) | |
250 | ||
251 | static VALUE | |
252 | glut_SetCursor(obj,arg1) | |
253 | VALUE obj,arg1; | |
254 | { | |
255 | int cursor; | |
256 | cursor = NUM2INT(arg1); | |
257 | glutSetCursor(cursor); | |
258 | return Qnil; | |
259 | } | |
260 | ||
261 | static VALUE | |
262 | glut_WarpPointer(obj,arg1,arg2) | |
263 | VALUE obj,arg1,arg2; | |
264 | { | |
265 | int x,y; | |
266 | x = NUM2INT(arg1); | |
267 | y = NUM2INT(arg2); | |
268 | glutWarpPointer(x,y); | |
269 | return Qnil; | |
270 | } | |
271 | ||
272 | /* GLUT overlay sub-API. */ | |
273 | GLUT_SIMPLE_FUNCTION(EstablishOverlay) | |
274 | GLUT_SIMPLE_FUNCTION(RemoveOverlay) | |
275 | GLUT_SIMPLE_FUNCTION(PostOverlayRedisplay) | |
276 | GLUT_SIMPLE_FUNCTION(ShowOverlay) | |
277 | GLUT_SIMPLE_FUNCTION(HideOverlay) | |
278 | ||
279 | static VALUE | |
280 | glut_UseLayer(obj,arg1) | |
281 | VALUE obj, arg1; | |
282 | { | |
283 | GLenum layer; | |
284 | layer = (GLenum)NUM2INT(arg1); | |
285 | glutUseLayer(layer); | |
286 | return Qnil; | |
287 | } | |
288 | ||
289 | static void GLUTCALLBACK | |
290 | glut_CreateMenuCallback(int value) | |
291 | { | |
292 | VALUE func; | |
293 | int menu; | |
294 | menu = glutGetMenu(); | |
295 | func = rb_ary_entry(menu_callback, menu); | |
296 | ||
297 | rb_funcall(func, call_id, 1, INT2NUM(value)); | |
298 | } | |
299 | ||
300 | static VALUE | |
301 | glut_CreateMenu(VALUE obj, VALUE callback) { | |
302 | int menu; | |
303 | ||
304 | callback = rb_glut_check_callback(obj, callback); | |
305 | ||
306 | if (NIL_P(callback)) | |
307 | menu = glutCreateMenu(NULL); | |
308 | else | |
309 | menu = glutCreateMenu(glut_CreateMenuCallback); | |
310 | ||
311 | rb_ary_store(menu_callback, menu, callback); | |
312 | ||
313 | return INT2FIX(menu); | |
314 | } | |
315 | ||
316 | static VALUE | |
317 | glut_DestroyMenu(obj,arg1) | |
318 | VALUE obj,arg1; | |
319 | { | |
320 | int menu; | |
321 | menu = NUM2INT(arg1); | |
322 | glutDestroyMenu(menu); | |
323 | //rb_hash_aset(g_menucallback, menu, Qnil); | |
324 | //rb_hash_aset(g_menuargs, menu, Qnil); | |
325 | return Qnil; | |
326 | } | |
327 | ||
328 | static VALUE | |
329 | glut_GetMenu(obj) | |
330 | VALUE obj; | |
331 | { | |
332 | int ret; | |
333 | ret = glutGetMenu(); | |
334 | return INT2NUM(ret); | |
335 | } | |
336 | ||
337 | static VALUE | |
338 | glut_SetMenu(obj,arg1) | |
339 | VALUE obj,arg1; | |
340 | { | |
341 | glutSetMenu(NUM2INT(arg1)); | |
342 | return Qnil; | |
343 | } | |
344 | ||
345 | static VALUE | |
346 | glut_AddMenuEntry(obj,arg1,arg2) | |
347 | VALUE obj,arg1,arg2; | |
348 | { | |
349 | Check_Type(arg1,T_STRING); | |
350 | glutAddMenuEntry(RSTRING_PTR(arg1), NUM2INT(arg2)); | |
351 | return Qnil; | |
352 | } | |
353 | ||
354 | static VALUE | |
355 | glut_AddSubMenu(obj,arg1,arg2) | |
356 | VALUE obj,arg1,arg2; | |
357 | { | |
358 | Check_Type(arg1,T_STRING); | |
359 | glutAddSubMenu(RSTRING_PTR(arg1), NUM2INT(arg2)); | |
360 | return Qnil; | |
361 | } | |
362 | ||
363 | static VALUE glut_ChangeToMenuEntry(obj,arg1,arg2,arg3) | |
364 | VALUE obj,arg1,arg2,arg3; | |
365 | { | |
366 | Check_Type(arg2,T_STRING); | |
367 | glutChangeToMenuEntry(NUM2INT(arg1), RSTRING_PTR(arg2), NUM2INT(arg3)); | |
368 | return Qnil; | |
369 | } | |
370 | ||
371 | static VALUE glut_ChangeToSubMenu(obj,arg1,arg2,arg3) | |
372 | VALUE obj,arg1,arg2,arg3; | |
373 | { | |
374 | Check_Type(arg2,T_STRING); | |
375 | glutChangeToSubMenu(NUM2INT(arg1), RSTRING_PTR(arg2), NUM2INT(arg3)); | |
376 | return Qnil; | |
377 | } | |
378 | ||
379 | static VALUE glut_RemoveMenuItem( VALUE obj, VALUE arg1 ) | |
380 | { | |
381 | glutRemoveMenuItem(NUM2INT(arg1)); | |
382 | return Qnil; | |
383 | } | |
384 | ||
385 | static VALUE | |
386 | glut_AttachMenu(obj,arg1) | |
387 | VALUE obj, arg1; | |
388 | { | |
389 | glutAttachMenu(NUM2INT(arg1)); | |
390 | return Qnil; | |
391 | } | |
392 | ||
393 | static VALUE | |
394 | glut_DetachMenu(obj,arg1) | |
395 | VALUE obj, arg1; | |
396 | { | |
397 | glutDetachMenu(NUM2INT(arg1)); | |
398 | return Qnil; | |
399 | } | |
400 | ||
401 | /* GLUT color index sub-API. */ | |
402 | static VALUE | |
403 | glut_SetColor(obj,arg1,arg2,arg3,arg4) | |
404 | VALUE obj,arg1,arg2,arg3,arg4; | |
405 | { | |
406 | int set; | |
407 | GLfloat red; | |
408 | GLfloat green; | |
409 | GLfloat blue; | |
410 | set = NUM2INT(arg1); | |
411 | red = (GLfloat)NUM2DBL(arg2); | |
412 | green = (GLfloat)NUM2DBL(arg3); | |
413 | blue = (GLfloat)NUM2DBL(arg4); | |
414 | glutSetColor(set, red, green, blue); | |
415 | return Qnil; | |
416 | } | |
417 | ||
418 | static VALUE | |
419 | glut_GetColor(obj,arg1,arg2) | |
420 | VALUE obj,arg1,arg2; | |
421 | { | |
422 | int ndx; | |
423 | int component; | |
424 | GLfloat ret; | |
425 | ndx = NUM2INT(arg1); | |
426 | component = NUM2INT(arg2); | |
427 | ret = (GLfloat)glutGetColor(ndx, component); | |
428 | return rb_float_new(ret); | |
429 | } | |
430 | ||
431 | static VALUE | |
432 | glut_CopyColormap(obj,arg1) | |
433 | VALUE obj,arg1; | |
434 | { | |
435 | int win; | |
436 | win = NUM2INT(arg1); | |
437 | glutCopyColormap(win); | |
438 | return Qnil; | |
439 | } | |
440 | ||
441 | /* GLUT state retrieval sub-API. */ | |
442 | static VALUE | |
443 | glut_Get(obj,arg1) | |
444 | VALUE obj,arg1; | |
445 | { | |
446 | GLenum type; | |
447 | int ret; | |
448 | type = (GLenum)NUM2INT(arg1); | |
449 | ret = glutGet(type); | |
450 | return INT2NUM(ret); | |
451 | } | |
452 | ||
453 | static VALUE | |
454 | glut_DeviceGet(obj,arg1) | |
455 | VALUE obj,arg1; | |
456 | { | |
457 | GLenum type; | |
458 | int ret; | |
459 | type = (GLenum)NUM2INT(arg1); | |
460 | ret = glutDeviceGet(type); | |
461 | return INT2NUM(ret); | |
462 | } | |
463 | ||
464 | /* GLUT extension support sub-API */ | |
465 | static VALUE | |
466 | glut_ExtensionSupported(obj,arg1) | |
467 | VALUE obj,arg1; | |
468 | { | |
469 | int ret; | |
470 | Check_Type(arg1,T_STRING); | |
471 | ret = glutExtensionSupported(RSTRING_PTR(arg1)); | |
472 | return INT2NUM(ret); | |
473 | } | |
474 | ||
475 | static VALUE | |
476 | glut_GetModifiers(obj) | |
477 | VALUE obj; | |
478 | { | |
479 | int ret; | |
480 | ret = glutGetModifiers(); | |
481 | return INT2NUM(ret); | |
482 | } | |
483 | ||
484 | static VALUE | |
485 | glut_LayerGet(obj,arg1) | |
486 | VALUE obj,arg1; | |
487 | { | |
488 | GLenum type; | |
489 | int ret; | |
490 | type = (GLenum)NUM2INT(arg1); | |
491 | ret = glutLayerGet(type); | |
492 | return INT2NUM(ret); | |
493 | } | |
494 | ||
495 | /* GLUT font sub-API */ | |
496 | ||
497 | /* Some glut implementations define font enums as addresses of local functions | |
498 | * which are then called by glut internally. This may lead to crashes or bus | |
499 | * errors on some platforms, so to be safe we hardcode the values passed | |
500 | * to/from ruby | |
501 | */ | |
502 | ||
503 | static inline void * bitmap_font_map(int f) | |
504 | { | |
505 | switch (f) { | |
506 | case 0: return (void *)GLUT_BITMAP_9_BY_15; | |
507 | case 1: return (void *)GLUT_BITMAP_8_BY_13; | |
508 | case 2: return (void *)GLUT_BITMAP_TIMES_ROMAN_10; | |
509 | case 3: return (void *)GLUT_BITMAP_TIMES_ROMAN_24; | |
510 | case 4: return (void *)GLUT_BITMAP_HELVETICA_10; | |
511 | case 5: return (void *)GLUT_BITMAP_HELVETICA_12; | |
512 | case 6: return (void *)GLUT_BITMAP_HELVETICA_18; | |
513 | default: | |
514 | rb_raise(rb_eArgError, "Unsupported font %d", f); | |
515 | } | |
516 | ||
517 | return (void *) 0; /* not reached */ | |
518 | } | |
519 | ||
520 | static inline void * stroke_font_map(int f) | |
521 | { | |
522 | switch (f) { | |
523 | case 7: return (void *)GLUT_STROKE_ROMAN; | |
524 | case 8: return (void *)GLUT_STROKE_MONO_ROMAN; | |
525 | default: | |
526 | rb_raise(rb_eArgError, "Unsupported font %d", f); | |
527 | } | |
528 | ||
529 | return (void *) 0; /* not reached */ | |
530 | } | |
531 | ||
532 | static VALUE | |
533 | glut_BitmapCharacter(obj,arg1,arg2) | |
534 | VALUE obj,arg1,arg2; | |
535 | { | |
536 | int character; | |
537 | int font; | |
538 | font = NUM2INT(arg1); | |
539 | character = NUM2INT(arg2); | |
540 | glutBitmapCharacter(bitmap_font_map(font),character); | |
541 | return Qnil; | |
542 | } | |
543 | ||
544 | static VALUE | |
545 | glut_BitmapWidth(obj,arg1,arg2) | |
546 | VALUE obj,arg1,arg2; | |
547 | { | |
548 | int font; | |
549 | int character; | |
550 | int ret; | |
551 | font = NUM2INT(arg1); | |
552 | character = NUM2INT(arg2); | |
553 | ret = glutBitmapWidth(bitmap_font_map(font), character); | |
554 | return INT2NUM(ret); | |
555 | } | |
556 | ||
557 | static VALUE | |
558 | glut_StrokeCharacter(obj,arg1,arg2) | |
559 | VALUE obj,arg1,arg2; | |
560 | { | |
561 | int font; | |
562 | int character; | |
563 | font = NUM2INT(arg1); | |
564 | character = NUM2INT(arg2); | |
565 | glutStrokeCharacter(stroke_font_map(font), character); | |
566 | return Qnil; | |
567 | } | |
568 | ||
569 | static VALUE | |
570 | glut_StrokeWidth(obj,arg1,arg2) | |
571 | VALUE obj,arg1,arg2; | |
572 | { | |
573 | int font; | |
574 | int character; | |
575 | int ret; | |
576 | font = NUM2INT(arg1); | |
577 | character = NUM2INT(arg2); | |
578 | ret = glutStrokeWidth(stroke_font_map(font), character); | |
579 | return INT2NUM(ret); | |
580 | } | |
581 | ||
582 | static VALUE | |
583 | glut_BitmapLength(obj,arg1,arg2) | |
584 | VALUE obj,arg1,arg2; | |
585 | { | |
586 | int font; | |
587 | int ret; | |
588 | Check_Type(arg2,T_STRING); | |
589 | font = NUM2INT(arg1); | |
590 | ret = glutBitmapLength(bitmap_font_map(font), (const unsigned char*)RSTRING_PTR(arg2)); | |
591 | return INT2NUM(ret); | |
592 | } | |
593 | ||
594 | static VALUE | |
595 | glut_StrokeLength(obj,arg1,arg2) | |
596 | VALUE obj,arg1,arg2; | |
597 | { | |
598 | int font; | |
599 | int ret; | |
600 | Check_Type(arg2,T_STRING); | |
601 | font = NUM2INT(arg1); | |
602 | ret = glutStrokeLength(stroke_font_map(font), (const unsigned char*)RSTRING_PTR(arg2)); | |
603 | return INT2NUM(ret); | |
604 | } | |
605 | ||
606 | /* GLUT pre-built models sub-API */ | |
607 | static VALUE | |
608 | glut_WireSphere(obj,arg1,arg2,arg3) | |
609 | VALUE obj,arg1,arg2,arg3; | |
610 | { | |
611 | GLdouble radius; | |
612 | GLint slices; | |
613 | GLint stacks; | |
614 | radius = (GLdouble)NUM2DBL(arg1); | |
615 | slices = (GLint)NUM2INT(arg2); | |
616 | stacks = (GLint)NUM2INT(arg3); | |
617 | glutWireSphere(radius, slices, stacks); | |
618 | return Qnil; | |
619 | } | |
620 | ||
621 | static VALUE | |
622 | glut_SolidSphere(obj,arg1,arg2,arg3) | |
623 | VALUE obj,arg1,arg2,arg3; | |
624 | { | |
625 | GLdouble radius; | |
626 | GLint slices; | |
627 | GLint stacks; | |
628 | radius = (GLdouble)NUM2DBL(arg1); | |
629 | slices = (GLint)NUM2INT(arg2); | |
630 | stacks = (GLint)NUM2INT(arg3); | |
631 | glutSolidSphere(radius, slices, stacks); | |
632 | return Qnil; | |
633 | } | |
634 | ||
635 | static VALUE | |
636 | glut_WireCone(obj,arg1,arg2,arg3,arg4) | |
637 | VALUE obj,arg1,arg2,arg3,arg4; | |
638 | { | |
639 | GLdouble base; | |
640 | GLdouble height; | |
641 | GLint slices; | |
642 | GLint stacks; | |
643 | base = (GLdouble)NUM2DBL(arg1); | |
644 | height = (GLdouble)NUM2DBL(arg2); | |
645 | slices = (GLint)NUM2INT(arg3); | |
646 | stacks = (GLint)NUM2INT(arg4); | |
647 | glutWireCone(base, height, slices, stacks); | |
648 | return Qnil; | |
649 | } | |
650 | ||
651 | static VALUE | |
652 | glut_SolidCone(obj,arg1,arg2,arg3,arg4) | |
653 | VALUE obj,arg1,arg2,arg3,arg4; | |
654 | { | |
655 | GLdouble base; | |
656 | GLdouble height; | |
657 | GLint slices; | |
658 | GLint stacks; | |
659 | base = (GLdouble)NUM2DBL(arg1); | |
660 | height = (GLdouble)NUM2DBL(arg2); | |
661 | slices = (GLint)NUM2INT(arg3); | |
662 | stacks = (GLint)NUM2INT(arg4); | |
663 | glutSolidCone(base, height, slices, stacks); | |
664 | return Qnil; | |
665 | } | |
666 | ||
667 | static VALUE | |
668 | glut_WireCube(obj,arg1) | |
669 | VALUE obj,arg1; | |
670 | { | |
671 | GLdouble size; | |
672 | size = (GLdouble)NUM2DBL(arg1); | |
673 | glutWireCube(size); | |
674 | return Qnil; | |
675 | } | |
676 | ||
677 | static VALUE | |
678 | glut_SolidCube(obj,arg1) | |
679 | VALUE obj,arg1; | |
680 | { | |
681 | GLdouble size; | |
682 | size = (GLdouble)NUM2DBL(arg1); | |
683 | glutSolidCube(size); | |
684 | return Qnil; | |
685 | } | |
686 | ||
687 | static VALUE | |
688 | glut_WireTorus(obj,arg1,arg2,arg3,arg4) | |
689 | VALUE obj,arg1,arg2,arg3,arg4; | |
690 | { | |
691 | GLdouble innerRadius; | |
692 | GLdouble outerRadius; | |
693 | GLint sides; | |
694 | GLint rings; | |
695 | innerRadius = (GLdouble)NUM2DBL(arg1); | |
696 | outerRadius = (GLdouble)NUM2DBL(arg2); | |
697 | sides = (GLint)NUM2INT(arg3); | |
698 | rings = (GLint)NUM2INT(arg4); | |
699 | glutWireTorus(innerRadius, outerRadius, sides, rings); | |
700 | return Qnil; | |
701 | } | |
702 | ||
703 | static VALUE | |
704 | glut_SolidTorus(obj,arg1,arg2,arg3,arg4) | |
705 | VALUE obj,arg1,arg2,arg3,arg4; | |
706 | { | |
707 | GLdouble innerRadius; | |
708 | GLdouble outerRadius; | |
709 | GLint sides; | |
710 | GLint rings; | |
711 | innerRadius = (GLdouble)NUM2DBL(arg1); | |
712 | outerRadius = (GLdouble)NUM2DBL(arg2); | |
713 | sides = (GLint)NUM2INT(arg3); | |
714 | rings = (GLint)NUM2INT(arg4); | |
715 | glutSolidTorus(innerRadius, outerRadius, sides, rings); | |
716 | return Qnil; | |
717 | } | |
718 | ||
719 | GLUT_SIMPLE_FUNCTION(WireDodecahedron) | |
720 | GLUT_SIMPLE_FUNCTION(SolidDodecahedron) | |
721 | GLUT_SIMPLE_FUNCTION(WireOctahedron) | |
722 | GLUT_SIMPLE_FUNCTION(SolidOctahedron) | |
723 | GLUT_SIMPLE_FUNCTION(WireTetrahedron) | |
724 | GLUT_SIMPLE_FUNCTION(SolidTetrahedron) | |
725 | GLUT_SIMPLE_FUNCTION(WireIcosahedron) | |
726 | GLUT_SIMPLE_FUNCTION(SolidIcosahedron) | |
727 | ||
728 | static VALUE | |
729 | glut_WireTeapot(obj,arg1) | |
730 | VALUE obj,arg1; | |
731 | { | |
732 | GLdouble size; | |
733 | size = (GLdouble)NUM2DBL(arg1); | |
734 | glutWireTeapot(size); | |
735 | return Qnil; | |
736 | } | |
737 | ||
738 | static VALUE | |
739 | glut_SolidTeapot(obj,arg1) | |
740 | VALUE obj,arg1; | |
741 | { | |
742 | GLdouble size; | |
743 | size = (GLdouble)NUM2DBL(arg1); | |
744 | glutSolidTeapot(size); | |
745 | return Qnil; | |
746 | } | |
747 | ||
748 | /* GLUT video resize sub-API. */ | |
749 | static VALUE | |
750 | glut_VideoResizeGet(obj,arg1) | |
751 | VALUE obj,arg1; | |
752 | { | |
753 | GLenum param; | |
754 | int ret; | |
755 | param = (GLenum)NUM2INT(arg1); | |
756 | ret = glutVideoResizeGet(param); | |
757 | return INT2NUM(ret); | |
758 | } | |
759 | ||
760 | GLUT_SIMPLE_FUNCTION(SetupVideoResizing) | |
761 | GLUT_SIMPLE_FUNCTION(StopVideoResizing) | |
762 | ||
763 | static VALUE | |
764 | glut_VideoResize(obj,arg1,arg2,arg3,arg4) | |
765 | VALUE obj,arg1,arg2,arg3,arg4; | |
766 | { | |
767 | int x; | |
768 | int y; | |
769 | int width; | |
770 | int height; | |
771 | x = NUM2INT(arg1); | |
772 | y = NUM2INT(arg2); | |
773 | width = NUM2INT(arg3); | |
774 | height = NUM2INT(arg4); | |
775 | glutVideoResize(x,y, width, height); | |
776 | return Qnil; | |
777 | } | |
778 | ||
779 | static VALUE | |
780 | glut_VideoPan(obj,arg1,arg2,arg3,arg4) | |
781 | VALUE obj,arg1,arg2,arg3,arg4; | |
782 | { | |
783 | int x; | |
784 | int y; | |
785 | int width; | |
786 | int height; | |
787 | x = NUM2INT(arg1); | |
788 | y = NUM2INT(arg2); | |
789 | width = NUM2INT(arg3); | |
790 | height = NUM2INT(arg4); | |
791 | glutVideoPan(x,y, width, height); | |
792 | return Qnil; | |
793 | } | |
794 | ||
795 | /* GLUT debugging sub-API. */ | |
796 | GLUT_SIMPLE_FUNCTION(ReportErrors) | |
797 | ||
798 | static VALUE | |
799 | glut_GameModeString(obj,arg1) | |
800 | VALUE obj,arg1; | |
801 | { | |
802 | Check_Type(arg1,T_STRING); | |
803 | glutGameModeString((const char*)RSTRING_PTR(arg1)); | |
804 | return Qnil; | |
805 | } | |
806 | ||
807 | GLUT_SIMPLE_FUNCTION(EnterGameMode) | |
808 | GLUT_SIMPLE_FUNCTION(LeaveGameMode) | |
809 | ||
810 | static VALUE | |
811 | glut_GameModeGet(obj,arg1) | |
812 | VALUE obj,arg1; | |
813 | { | |
814 | GLenum info; | |
815 | int i; | |
816 | info = (GLenum)NUM2INT(arg1); | |
817 | i = glutGameModeGet(info); | |
818 | return INT2NUM(i); | |
819 | } | |
820 | ||
821 | static VALUE | |
822 | glut_SetKeyRepeat(obj,arg1) | |
823 | VALUE obj,arg1; | |
824 | { | |
825 | GLenum repeatMode; | |
826 | repeatMode = (int) NUM2INT(arg1); | |
827 | glutSetKeyRepeat(repeatMode); | |
828 | return Qnil; | |
829 | } | |
830 | ||
831 | static VALUE | |
832 | glut_IgnoreKeyRepeat(obj,arg1) | |
833 | VALUE obj,arg1; | |
834 | { | |
835 | GLenum ignore; | |
836 | ignore = (int) NUM2INT(arg1); | |
837 | glutIgnoreKeyRepeat(ignore); | |
838 | return Qnil; | |
839 | } | |
840 | ||
841 | static VALUE | |
842 | glut_PostWindowOverlayRedisplay(obj,arg1) | |
843 | VALUE obj,arg1; | |
844 | { | |
845 | int win; | |
846 | win = (int) NUM2INT(arg1); | |
847 | glutPostWindowOverlayRedisplay(win); | |
848 | return Qnil; | |
849 | } | |
850 | ||
851 | static VALUE | |
852 | glut_PostWindowRedisplay(obj,arg1) | |
853 | VALUE obj,arg1; | |
854 | { | |
855 | int win; | |
856 | win = (int) NUM2INT(arg1); | |
857 | glutPostWindowRedisplay(win); | |
858 | return Qnil; | |
859 | } | |
860 | ||
861 | void Init_glut_callbacks(void); | |
862 | void Init_glut_ext(void); | |
863 | ||
864 | void Init_glut() { | |
865 | VALUE mGlut; | |
866 | ||
867 | call_id = rb_intern("call"); | |
868 | mGlut = rb_define_module("Glut"); | |
869 | ||
870 | menu_callback = rb_ary_new(); | |
871 | rb_global_variable(&menu_callback); | |
872 | ||
873 | rb_define_module_function(mGlut, "glutInit", glut_Init, -1); | |
874 | rb_define_module_function(mGlut, "glutInitDisplayMode", glut_InitDisplayMode, 1); | |
875 | rb_define_module_function(mGlut, "glutInitDisplayString", glut_InitDisplayString, 1); | |
876 | rb_define_module_function(mGlut, "glutInitWindowPosition", glut_InitWindowPosition, 2); | |
877 | rb_define_module_function(mGlut, "glutInitWindowSize", glut_InitWindowSize, 2); | |
878 | rb_define_module_function(mGlut, "glutMainLoop", glut_MainLoop, 0); | |
879 | rb_define_module_function(mGlut, "glutCheckLoop", glut_CheckLoop, 0); | |
880 | rb_define_module_function(mGlut, "glutGameModeString", glut_GameModeString, 1); | |
881 | rb_define_module_function(mGlut, "glutEnterGameMode", glut_EnterGameMode, 0); | |
882 | rb_define_module_function(mGlut, "glutLeaveGameMode", glut_LeaveGameMode, 0); | |
883 | rb_define_module_function(mGlut, "glutCreateWindow", glut_CreateWindow, -1); | |
884 | rb_define_module_function(mGlut, "glutCreateSubWindow", glut_CreateSubWindow, 5); | |
885 | rb_define_module_function(mGlut, "glutDestroyWindow", glut_DestroyWindow, 1); | |
886 | rb_define_module_function(mGlut, "glutPostRedisplay", glut_PostRedisplay, 0); | |
887 | rb_define_module_function(mGlut, "glutSwapBuffers", glut_SwapBuffers, 0); | |
888 | rb_define_module_function(mGlut, "glutGetWindow", glut_GetWindow, 0); | |
889 | rb_define_module_function(mGlut, "glutSetWindow", glut_SetWindow, 1); | |
890 | rb_define_module_function(mGlut, "glutSetWindowTitle", glut_SetWindowTitle, 1); | |
891 | rb_define_module_function(mGlut, "glutSetIconTitle", glut_SetIconTitle, 1); | |
892 | rb_define_module_function(mGlut, "glutPositionWindow", glut_PositionWindow, 2); | |
893 | rb_define_module_function(mGlut, "glutReshapeWindow", glut_ReshapeWindow, 2); | |
894 | rb_define_module_function(mGlut, "glutPopWindow", glut_PopWindow, 0); | |
895 | rb_define_module_function(mGlut, "glutPushWindow", glut_PushWindow, 0); | |
896 | rb_define_module_function(mGlut, "glutIconifyWindow", glut_IconifyWindow, 0); | |
897 | rb_define_module_function(mGlut, "glutShowWindow", glut_ShowWindow, 0); | |
898 | rb_define_module_function(mGlut, "glutHideWindow", glut_HideWindow, 0); | |
899 | rb_define_module_function(mGlut, "glutFullScreen", glut_FullScreen, 0); | |
900 | rb_define_module_function(mGlut, "glutSetCursor", glut_SetCursor, 1); | |
901 | rb_define_module_function(mGlut, "glutWarpPointer", glut_WarpPointer, 2); | |
902 | rb_define_module_function(mGlut, "glutEstablishOverlay", glut_EstablishOverlay, 0); | |
903 | rb_define_module_function(mGlut, "glutRemoveOverlay", glut_RemoveOverlay, 0); | |
904 | rb_define_module_function(mGlut, "glutUseLayer", glut_UseLayer, 1); | |
905 | rb_define_module_function(mGlut, "glutPostOverlayRedisplay", glut_PostOverlayRedisplay, 0); | |
906 | rb_define_module_function(mGlut, "glutShowOverlay", glut_ShowOverlay, 0); | |
907 | rb_define_module_function(mGlut, "glutHideOverlay", glut_HideOverlay, 0); | |
908 | rb_define_module_function(mGlut, "glutCreateMenu", glut_CreateMenu, 1); | |
909 | rb_define_module_function(mGlut, "glutDestroyMenu", glut_DestroyMenu, 1); | |
910 | rb_define_module_function(mGlut, "glutGetMenu", glut_GetMenu, 0); | |
911 | rb_define_module_function(mGlut, "glutSetMenu", glut_SetMenu, 1); | |
912 | rb_define_module_function(mGlut, "glutAddMenuEntry", glut_AddMenuEntry, 2); | |
913 | rb_define_module_function(mGlut, "glutAddSubMenu", glut_AddSubMenu, 2); | |
914 | rb_define_module_function(mGlut, "glutChangeToMenuEntry", glut_ChangeToMenuEntry, 3); | |
915 | rb_define_module_function(mGlut, "glutChangeToSubMenu", glut_ChangeToSubMenu, 3); | |
916 | rb_define_module_function(mGlut, "glutRemoveMenuItem", glut_RemoveMenuItem, 1); | |
917 | rb_define_module_function(mGlut, "glutAttachMenu", glut_AttachMenu, 1); | |
918 | rb_define_module_function(mGlut, "glutDetachMenu", glut_DetachMenu, 1); | |
919 | rb_define_module_function(mGlut, "glutSetColor", glut_SetColor, 4); | |
920 | rb_define_module_function(mGlut, "glutGetColor", glut_GetColor, 2); | |
921 | rb_define_module_function(mGlut, "glutCopyColormap", glut_CopyColormap, 1); | |
922 | rb_define_module_function(mGlut, "glutGet", glut_Get, 1); | |
923 | rb_define_module_function(mGlut, "glutDeviceGet", glut_DeviceGet, 1); | |
924 | rb_define_module_function(mGlut, "glutExtensionSupported", glut_ExtensionSupported, 1); | |
925 | rb_define_module_function(mGlut, "glutGetModifiers", glut_GetModifiers, 0); | |
926 | rb_define_module_function(mGlut, "glutLayerGet", glut_LayerGet, 1); | |
927 | rb_define_module_function(mGlut, "glutBitmapCharacter", glut_BitmapCharacter, 2); | |
928 | rb_define_module_function(mGlut, "glutBitmapWidth", glut_BitmapWidth, 2); | |
929 | rb_define_module_function(mGlut, "glutStrokeCharacter", glut_StrokeCharacter, 2); | |
930 | rb_define_module_function(mGlut, "glutStrokeWidth", glut_StrokeWidth, 2); | |
931 | rb_define_module_function(mGlut, "glutBitmapLength", glut_BitmapLength, 2); | |
932 | rb_define_module_function(mGlut, "glutStrokeLength", glut_StrokeLength, 2); | |
933 | rb_define_module_function(mGlut, "glutWireSphere", glut_WireSphere, 3); | |
934 | rb_define_module_function(mGlut, "glutSolidSphere", glut_SolidSphere, 3); | |
935 | rb_define_module_function(mGlut, "glutWireCone", glut_WireCone, 4); | |
936 | rb_define_module_function(mGlut, "glutSolidCone", glut_SolidCone, 4); | |
937 | rb_define_module_function(mGlut, "glutWireCube", glut_WireCube, 1); | |
938 | rb_define_module_function(mGlut, "glutSolidCube", glut_SolidCube, 1); | |
939 | rb_define_module_function(mGlut, "glutWireTorus", glut_WireTorus, 4); | |
940 | rb_define_module_function(mGlut, "glutSolidTorus", glut_SolidTorus, 4); | |
941 | rb_define_module_function(mGlut, "glutWireDodecahedron", glut_WireDodecahedron, 0); | |
942 | rb_define_module_function(mGlut, "glutSolidDodecahedron", glut_SolidDodecahedron, 0); | |
943 | rb_define_module_function(mGlut, "glutWireTeapot", glut_WireTeapot, 1); | |
944 | rb_define_module_function(mGlut, "glutSolidTeapot", glut_SolidTeapot, 1); | |
945 | rb_define_module_function(mGlut, "glutWireOctahedron", glut_WireOctahedron, 0); | |
946 | rb_define_module_function(mGlut, "glutSolidOctahedron", glut_SolidOctahedron, 0); | |
947 | rb_define_module_function(mGlut, "glutWireTetrahedron", glut_WireTetrahedron, 0); | |
948 | rb_define_module_function(mGlut, "glutSolidTetrahedron", glut_SolidTetrahedron, 0); | |
949 | rb_define_module_function(mGlut, "glutWireIcosahedron", glut_WireIcosahedron, 0); | |
950 | rb_define_module_function(mGlut, "glutSolidIcosahedron", glut_SolidIcosahedron, 0); | |
951 | rb_define_module_function(mGlut, "glutVideoResizeGet", glut_VideoResizeGet, 1); | |
952 | rb_define_module_function(mGlut, "glutSetupVideoResizing", glut_SetupVideoResizing, 0); | |
953 | rb_define_module_function(mGlut, "glutStopVideoResizing", glut_StopVideoResizing, 0); | |
954 | rb_define_module_function(mGlut, "glutVideoResize", glut_VideoResize, 4); | |
955 | rb_define_module_function(mGlut, "glutVideoPan", glut_VideoPan, 4); | |
956 | rb_define_module_function(mGlut, "glutReportErrors", glut_ReportErrors, 0); | |
957 | ||
958 | rb_define_module_function(mGlut, "glutGameModeGet", glut_GameModeGet, 1); | |
959 | rb_define_module_function(mGlut, "glutSetKeyRepeat", glut_SetKeyRepeat, 1); | |
960 | rb_define_module_function(mGlut, "glutIgnoreKeyRepeat", glut_IgnoreKeyRepeat, 1); | |
961 | rb_define_module_function(mGlut, "glutPostWindowOverlayRedisplay", glut_PostWindowOverlayRedisplay, 1); | |
962 | rb_define_module_function(mGlut, "glutPostWindowRedisplay", glut_PostWindowRedisplay, 1); | |
963 | ||
964 | rb_define_const(mGlut, "GLUT_API_VERSION", INT2NUM(GLUT_API_VERSION)); | |
965 | rb_define_const(mGlut, "GLUT_XLIB_IMPLEMENTATION", INT2NUM(GLUT_XLIB_IMPLEMENTATION)); | |
966 | rb_define_const(mGlut, "GLUT_RGB", INT2NUM(GLUT_RGB)); | |
967 | rb_define_const(mGlut, "GLUT_RGBA", INT2NUM(GLUT_RGBA)); | |
968 | rb_define_const(mGlut, "GLUT_INDEX", INT2NUM(GLUT_INDEX)); | |
969 | rb_define_const(mGlut, "GLUT_SINGLE", INT2NUM(GLUT_SINGLE)); | |
970 | rb_define_const(mGlut, "GLUT_DOUBLE", INT2NUM(GLUT_DOUBLE)); | |
971 | rb_define_const(mGlut, "GLUT_ACCUM", INT2NUM(GLUT_ACCUM)); | |
972 | rb_define_const(mGlut, "GLUT_ALPHA", INT2NUM(GLUT_ALPHA)); | |
973 | rb_define_const(mGlut, "GLUT_DEPTH", INT2NUM(GLUT_DEPTH)); | |
974 | rb_define_const(mGlut, "GLUT_STENCIL", INT2NUM(GLUT_STENCIL)); | |
975 | rb_define_const(mGlut, "GLUT_MULTISAMPLE", INT2NUM(GLUT_MULTISAMPLE)); | |
976 | rb_define_const(mGlut, "GLUT_STEREO", INT2NUM(GLUT_STEREO)); | |
977 | rb_define_const(mGlut, "GLUT_LUMINANCE", INT2NUM(GLUT_LUMINANCE)); | |
978 | rb_define_const(mGlut, "GLUT_LEFT_BUTTON", INT2NUM(GLUT_LEFT_BUTTON)); | |
979 | rb_define_const(mGlut, "GLUT_MIDDLE_BUTTON", INT2NUM(GLUT_MIDDLE_BUTTON)); | |
980 | rb_define_const(mGlut, "GLUT_RIGHT_BUTTON", INT2NUM(GLUT_RIGHT_BUTTON)); | |
981 | rb_define_const(mGlut, "GLUT_DOWN", INT2NUM(GLUT_DOWN)); | |
982 | rb_define_const(mGlut, "GLUT_UP", INT2NUM(GLUT_UP)); | |
983 | rb_define_const(mGlut, "GLUT_KEY_F1", INT2NUM(GLUT_KEY_F1)); | |
984 | rb_define_const(mGlut, "GLUT_KEY_F2", INT2NUM(GLUT_KEY_F2)); | |
985 | rb_define_const(mGlut, "GLUT_KEY_F3", INT2NUM(GLUT_KEY_F3)); | |
986 | rb_define_const(mGlut, "GLUT_KEY_F4", INT2NUM(GLUT_KEY_F4)); | |
987 | rb_define_const(mGlut, "GLUT_KEY_F5", INT2NUM(GLUT_KEY_F5)); | |
988 | rb_define_const(mGlut, "GLUT_KEY_F6", INT2NUM(GLUT_KEY_F6)); | |
989 | rb_define_const(mGlut, "GLUT_KEY_F7", INT2NUM(GLUT_KEY_F7)); | |
990 | rb_define_const(mGlut, "GLUT_KEY_F8", INT2NUM(GLUT_KEY_F8)); | |
991 | rb_define_const(mGlut, "GLUT_KEY_F9", INT2NUM(GLUT_KEY_F9)); | |
992 | rb_define_const(mGlut, "GLUT_KEY_F10", INT2NUM(GLUT_KEY_F10)); | |
993 | rb_define_const(mGlut, "GLUT_KEY_F11", INT2NUM(GLUT_KEY_F11)); | |
994 | rb_define_const(mGlut, "GLUT_KEY_F12", INT2NUM(GLUT_KEY_F12)); | |
995 | rb_define_const(mGlut, "GLUT_KEY_LEFT", INT2NUM(GLUT_KEY_LEFT)); | |
996 | rb_define_const(mGlut, "GLUT_KEY_UP", INT2NUM(GLUT_KEY_UP)); | |
997 | rb_define_const(mGlut, "GLUT_KEY_RIGHT", INT2NUM(GLUT_KEY_RIGHT)); | |
998 | rb_define_const(mGlut, "GLUT_KEY_DOWN", INT2NUM(GLUT_KEY_DOWN)); | |
999 | rb_define_const(mGlut, "GLUT_KEY_PAGE_UP", INT2NUM(GLUT_KEY_PAGE_UP)); | |
1000 | rb_define_const(mGlut, "GLUT_KEY_PAGE_DOWN", INT2NUM(GLUT_KEY_PAGE_DOWN)); | |
1001 | rb_define_const(mGlut, "GLUT_KEY_HOME", INT2NUM(GLUT_KEY_HOME)); | |
1002 | rb_define_const(mGlut, "GLUT_KEY_END", INT2NUM(GLUT_KEY_END)); | |
1003 | rb_define_const(mGlut, "GLUT_KEY_INSERT", INT2NUM(GLUT_KEY_INSERT)); | |
1004 | rb_define_const(mGlut, "GLUT_LEFT", INT2NUM(GLUT_LEFT)); | |
1005 | rb_define_const(mGlut, "GLUT_ENTERED", INT2NUM(GLUT_ENTERED)); | |
1006 | rb_define_const(mGlut, "GLUT_MENU_NOT_IN_USE", INT2NUM(GLUT_MENU_NOT_IN_USE)); | |
1007 | rb_define_const(mGlut, "GLUT_MENU_IN_USE", INT2NUM(GLUT_MENU_IN_USE)); | |
1008 | rb_define_const(mGlut, "GLUT_NOT_VISIBLE", INT2NUM(GLUT_NOT_VISIBLE)); | |
1009 | rb_define_const(mGlut, "GLUT_VISIBLE", INT2NUM(GLUT_VISIBLE)); | |
1010 | rb_define_const(mGlut, "GLUT_HIDDEN", INT2NUM(GLUT_HIDDEN)); | |
1011 | rb_define_const(mGlut, "GLUT_FULLY_RETAINED", INT2NUM(GLUT_FULLY_RETAINED)); | |
1012 | rb_define_const(mGlut, "GLUT_PARTIALLY_RETAINED", INT2NUM(GLUT_PARTIALLY_RETAINED)); | |
1013 | rb_define_const(mGlut, "GLUT_FULLY_COVERED", INT2NUM(GLUT_FULLY_COVERED)); | |
1014 | rb_define_const(mGlut, "GLUT_RED", INT2NUM(GLUT_RED)); | |
1015 | rb_define_const(mGlut, "GLUT_GREEN", INT2NUM(GLUT_GREEN)); | |
1016 | rb_define_const(mGlut, "GLUT_BLUE", INT2NUM(GLUT_BLUE)); | |
1017 | rb_define_const(mGlut, "GLUT_WINDOW_X", INT2NUM(GLUT_WINDOW_X)); | |
1018 | rb_define_const(mGlut, "GLUT_WINDOW_Y", INT2NUM(GLUT_WINDOW_Y)); | |
1019 | rb_define_const(mGlut, "GLUT_WINDOW_WIDTH", INT2NUM(GLUT_WINDOW_WIDTH)); | |
1020 | rb_define_const(mGlut, "GLUT_WINDOW_HEIGHT", INT2NUM(GLUT_WINDOW_HEIGHT)); | |
1021 | rb_define_const(mGlut, "GLUT_WINDOW_BUFFER_SIZE", INT2NUM(GLUT_WINDOW_BUFFER_SIZE)); | |
1022 | rb_define_const(mGlut, "GLUT_WINDOW_STENCIL_SIZE", INT2NUM(GLUT_WINDOW_STENCIL_SIZE)); | |
1023 | rb_define_const(mGlut, "GLUT_WINDOW_DEPTH_SIZE", INT2NUM(GLUT_WINDOW_DEPTH_SIZE)); | |
1024 | rb_define_const(mGlut, "GLUT_WINDOW_RED_SIZE", INT2NUM(GLUT_WINDOW_RED_SIZE)); | |
1025 | rb_define_const(mGlut, "GLUT_WINDOW_GREEN_SIZE", INT2NUM(GLUT_WINDOW_GREEN_SIZE)); | |
1026 | rb_define_const(mGlut, "GLUT_WINDOW_BLUE_SIZE", INT2NUM(GLUT_WINDOW_BLUE_SIZE)); | |
1027 | rb_define_const(mGlut, "GLUT_WINDOW_ALPHA_SIZE", INT2NUM(GLUT_WINDOW_ALPHA_SIZE)); | |
1028 | rb_define_const(mGlut, "GLUT_WINDOW_ACCUM_RED_SIZE", INT2NUM(GLUT_WINDOW_ACCUM_RED_SIZE)); | |
1029 | rb_define_const(mGlut, "GLUT_WINDOW_ACCUM_GREEN_SIZE", INT2NUM(GLUT_WINDOW_ACCUM_GREEN_SIZE)); | |
1030 | rb_define_const(mGlut, "GLUT_WINDOW_ACCUM_BLUE_SIZE", INT2NUM(GLUT_WINDOW_ACCUM_BLUE_SIZE)); | |
1031 | rb_define_const(mGlut, "GLUT_WINDOW_ACCUM_ALPHA_SIZE", INT2NUM(GLUT_WINDOW_ACCUM_ALPHA_SIZE)); | |
1032 | rb_define_const(mGlut, "GLUT_WINDOW_DOUBLEBUFFER", INT2NUM(GLUT_WINDOW_DOUBLEBUFFER)); | |
1033 | rb_define_const(mGlut, "GLUT_WINDOW_RGBA", INT2NUM(GLUT_WINDOW_RGBA)); | |
1034 | rb_define_const(mGlut, "GLUT_WINDOW_PARENT", INT2NUM(GLUT_WINDOW_PARENT)); | |
1035 | rb_define_const(mGlut, "GLUT_WINDOW_NUM_CHILDREN", INT2NUM(GLUT_WINDOW_NUM_CHILDREN)); | |
1036 | rb_define_const(mGlut, "GLUT_WINDOW_COLORMAP_SIZE", INT2NUM(GLUT_WINDOW_COLORMAP_SIZE)); | |
1037 | rb_define_const(mGlut, "GLUT_WINDOW_NUM_SAMPLES", INT2NUM(GLUT_WINDOW_NUM_SAMPLES)); | |
1038 | rb_define_const(mGlut, "GLUT_WINDOW_STEREO", INT2NUM(GLUT_WINDOW_STEREO)); | |
1039 | rb_define_const(mGlut, "GLUT_WINDOW_CURSOR", INT2NUM(GLUT_WINDOW_CURSOR)); | |
1040 | rb_define_const(mGlut, "GLUT_SCREEN_WIDTH", INT2NUM(GLUT_SCREEN_WIDTH)); | |
1041 | rb_define_const(mGlut, "GLUT_SCREEN_HEIGHT", INT2NUM(GLUT_SCREEN_HEIGHT)); | |
1042 | rb_define_const(mGlut, "GLUT_SCREEN_WIDTH_MM", INT2NUM(GLUT_SCREEN_WIDTH_MM)); | |
1043 | rb_define_const(mGlut, "GLUT_SCREEN_HEIGHT_MM", INT2NUM(GLUT_SCREEN_HEIGHT_MM)); | |
1044 | rb_define_const(mGlut, "GLUT_MENU_NUM_ITEMS", INT2NUM(GLUT_MENU_NUM_ITEMS)); | |
1045 | rb_define_const(mGlut, "GLUT_DISPLAY_MODE_POSSIBLE", INT2NUM(GLUT_DISPLAY_MODE_POSSIBLE)); | |
1046 | rb_define_const(mGlut, "GLUT_INIT_WINDOW_X", INT2NUM(GLUT_INIT_WINDOW_X)); | |
1047 | rb_define_const(mGlut, "GLUT_INIT_WINDOW_Y", INT2NUM(GLUT_INIT_WINDOW_Y)); | |
1048 | rb_define_const(mGlut, "GLUT_INIT_WINDOW_WIDTH", INT2NUM(GLUT_INIT_WINDOW_WIDTH)); | |
1049 | rb_define_const(mGlut, "GLUT_INIT_WINDOW_HEIGHT", INT2NUM(GLUT_INIT_WINDOW_HEIGHT)); | |
1050 | rb_define_const(mGlut, "GLUT_INIT_DISPLAY_MODE", INT2NUM(GLUT_INIT_DISPLAY_MODE)); | |
1051 | rb_define_const(mGlut, "GLUT_ELAPSED_TIME", INT2NUM(GLUT_ELAPSED_TIME)); | |
1052 | rb_define_const(mGlut, "GLUT_HAS_KEYBOARD", INT2NUM(GLUT_HAS_KEYBOARD)); | |
1053 | rb_define_const(mGlut, "GLUT_HAS_MOUSE", INT2NUM(GLUT_HAS_MOUSE)); | |
1054 | rb_define_const(mGlut, "GLUT_HAS_SPACEBALL", INT2NUM(GLUT_HAS_SPACEBALL)); | |
1055 | rb_define_const(mGlut, "GLUT_HAS_DIAL_AND_BUTTON_BOX", INT2NUM(GLUT_HAS_DIAL_AND_BUTTON_BOX)); | |
1056 | rb_define_const(mGlut, "GLUT_HAS_TABLET", INT2NUM(GLUT_HAS_TABLET)); | |
1057 | rb_define_const(mGlut, "GLUT_NUM_MOUSE_BUTTONS", INT2NUM(GLUT_NUM_MOUSE_BUTTONS)); | |
1058 | rb_define_const(mGlut, "GLUT_NUM_SPACEBALL_BUTTONS", INT2NUM(GLUT_NUM_SPACEBALL_BUTTONS)); | |
1059 | rb_define_const(mGlut, "GLUT_NUM_BUTTON_BOX_BUTTONS", INT2NUM(GLUT_NUM_BUTTON_BOX_BUTTONS)); | |
1060 | rb_define_const(mGlut, "GLUT_NUM_DIALS", INT2NUM(GLUT_NUM_DIALS)); | |
1061 | rb_define_const(mGlut, "GLUT_NUM_TABLET_BUTTONS", INT2NUM(GLUT_NUM_TABLET_BUTTONS)); | |
1062 | rb_define_const(mGlut, "GLUT_OVERLAY_POSSIBLE", INT2NUM(GLUT_OVERLAY_POSSIBLE)); | |
1063 | rb_define_const(mGlut, "GLUT_LAYER_IN_USE", INT2NUM(GLUT_LAYER_IN_USE)); | |
1064 | rb_define_const(mGlut, "GLUT_HAS_OVERLAY", INT2NUM(GLUT_HAS_OVERLAY)); | |
1065 | rb_define_const(mGlut, "GLUT_TRANSPARENT_INDEX", INT2NUM(GLUT_TRANSPARENT_INDEX)); | |
1066 | rb_define_const(mGlut, "GLUT_NORMAL_DAMAGED", INT2NUM(GLUT_NORMAL_DAMAGED)); | |
1067 | rb_define_const(mGlut, "GLUT_OVERLAY_DAMAGED", INT2NUM(GLUT_OVERLAY_DAMAGED)); | |
1068 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_POSSIBLE", INT2NUM(GLUT_VIDEO_RESIZE_POSSIBLE)); | |
1069 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_IN_USE", INT2NUM(GLUT_VIDEO_RESIZE_IN_USE)); | |
1070 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_X_DELTA", INT2NUM(GLUT_VIDEO_RESIZE_X_DELTA)); | |
1071 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_Y_DELTA", INT2NUM(GLUT_VIDEO_RESIZE_Y_DELTA)); | |
1072 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_WIDTH_DELTA", INT2NUM(GLUT_VIDEO_RESIZE_WIDTH_DELTA)); | |
1073 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_HEIGHT_DELTA", INT2NUM(GLUT_VIDEO_RESIZE_HEIGHT_DELTA)); | |
1074 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_X", INT2NUM(GLUT_VIDEO_RESIZE_X)); | |
1075 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_Y", INT2NUM(GLUT_VIDEO_RESIZE_Y)); | |
1076 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_WIDTH", INT2NUM(GLUT_VIDEO_RESIZE_WIDTH)); | |
1077 | rb_define_const(mGlut, "GLUT_VIDEO_RESIZE_HEIGHT", INT2NUM(GLUT_VIDEO_RESIZE_HEIGHT)); | |
1078 | rb_define_const(mGlut, "GLUT_NORMAL", INT2NUM(GLUT_NORMAL)); | |
1079 | rb_define_const(mGlut, "GLUT_OVERLAY", INT2NUM(GLUT_OVERLAY)); | |
1080 | rb_define_const(mGlut, "GLUT_ACTIVE_SHIFT", INT2NUM(GLUT_ACTIVE_SHIFT)); | |
1081 | rb_define_const(mGlut, "GLUT_ACTIVE_CTRL", INT2NUM(GLUT_ACTIVE_CTRL)); | |
1082 | rb_define_const(mGlut, "GLUT_ACTIVE_ALT", INT2NUM(GLUT_ACTIVE_ALT)); | |
1083 | rb_define_const(mGlut, "GLUT_CURSOR_RIGHT_ARROW", INT2NUM(GLUT_CURSOR_RIGHT_ARROW)); | |
1084 | rb_define_const(mGlut, "GLUT_CURSOR_LEFT_ARROW", INT2NUM(GLUT_CURSOR_LEFT_ARROW)); | |
1085 | rb_define_const(mGlut, "GLUT_CURSOR_INFO", INT2NUM(GLUT_CURSOR_INFO)); | |
1086 | rb_define_const(mGlut, "GLUT_CURSOR_DESTROY", INT2NUM(GLUT_CURSOR_DESTROY)); | |
1087 | rb_define_const(mGlut, "GLUT_CURSOR_HELP", INT2NUM(GLUT_CURSOR_HELP)); | |
1088 | rb_define_const(mGlut, "GLUT_CURSOR_CYCLE", INT2NUM(GLUT_CURSOR_CYCLE)); | |
1089 | rb_define_const(mGlut, "GLUT_CURSOR_SPRAY", INT2NUM(GLUT_CURSOR_SPRAY)); | |
1090 | rb_define_const(mGlut, "GLUT_CURSOR_WAIT", INT2NUM(GLUT_CURSOR_WAIT)); | |
1091 | rb_define_const(mGlut, "GLUT_CURSOR_TEXT", INT2NUM(GLUT_CURSOR_TEXT)); | |
1092 | rb_define_const(mGlut, "GLUT_CURSOR_CROSSHAIR", INT2NUM(GLUT_CURSOR_CROSSHAIR)); | |
1093 | rb_define_const(mGlut, "GLUT_CURSOR_UP_DOWN", INT2NUM(GLUT_CURSOR_UP_DOWN)); | |
1094 | rb_define_const(mGlut, "GLUT_CURSOR_LEFT_RIGHT", INT2NUM(GLUT_CURSOR_LEFT_RIGHT)); | |
1095 | rb_define_const(mGlut, "GLUT_CURSOR_TOP_SIDE", INT2NUM(GLUT_CURSOR_TOP_SIDE)); | |
1096 | rb_define_const(mGlut, "GLUT_CURSOR_BOTTOM_SIDE", INT2NUM(GLUT_CURSOR_BOTTOM_SIDE)); | |
1097 | rb_define_const(mGlut, "GLUT_CURSOR_LEFT_SIDE", INT2NUM(GLUT_CURSOR_LEFT_SIDE)); | |
1098 | rb_define_const(mGlut, "GLUT_CURSOR_RIGHT_SIDE", INT2NUM(GLUT_CURSOR_RIGHT_SIDE)); | |
1099 | rb_define_const(mGlut, "GLUT_CURSOR_TOP_LEFT_CORNER", INT2NUM(GLUT_CURSOR_TOP_LEFT_CORNER)); | |
1100 | rb_define_const(mGlut, "GLUT_CURSOR_TOP_RIGHT_CORNER", INT2NUM(GLUT_CURSOR_TOP_RIGHT_CORNER)); | |
1101 | rb_define_const(mGlut, "GLUT_CURSOR_BOTTOM_RIGHT_CORNER", INT2NUM(GLUT_CURSOR_BOTTOM_RIGHT_CORNER)); | |
1102 | rb_define_const(mGlut, "GLUT_CURSOR_BOTTOM_LEFT_CORNER", INT2NUM(GLUT_CURSOR_BOTTOM_LEFT_CORNER)); | |
1103 | rb_define_const(mGlut, "GLUT_CURSOR_INHERIT", INT2NUM(GLUT_CURSOR_INHERIT)); | |
1104 | rb_define_const(mGlut, "GLUT_CURSOR_NONE", INT2NUM(GLUT_CURSOR_NONE)); | |
1105 | rb_define_const(mGlut, "GLUT_CURSOR_FULL_CROSSHAIR", INT2NUM(GLUT_CURSOR_FULL_CROSSHAIR)); | |
1106 | ||
1107 | /* hardcoded, see bitmap_font_map for explanation */ | |
1108 | rb_define_const(mGlut, "GLUT_BITMAP_9_BY_15", INT2NUM(0)); | |
1109 | rb_define_const(mGlut, "GLUT_BITMAP_8_BY_13", INT2NUM(1)); | |
1110 | rb_define_const(mGlut, "GLUT_BITMAP_TIMES_ROMAN_10", INT2NUM(2)); | |
1111 | rb_define_const(mGlut, "GLUT_BITMAP_TIMES_ROMAN_24", INT2NUM(3)); | |
1112 | rb_define_const(mGlut, "GLUT_BITMAP_HELVETICA_10", INT2NUM(4)); | |
1113 | rb_define_const(mGlut, "GLUT_BITMAP_HELVETICA_12", INT2NUM(5)); | |
1114 | rb_define_const(mGlut, "GLUT_BITMAP_HELVETICA_18", INT2NUM(6)); | |
1115 | rb_define_const(mGlut, "GLUT_STROKE_ROMAN", INT2NUM(7)); | |
1116 | rb_define_const(mGlut, "GLUT_STROKE_MONO_ROMAN", INT2NUM(8)); | |
1117 | ||
1118 | rb_define_const(mGlut, "GLUT_WINDOW_FORMAT_ID", INT2NUM(GLUT_WINDOW_FORMAT_ID)); | |
1119 | rb_define_const(mGlut, "GLUT_DEVICE_IGNORE_KEY_REPEAT", INT2NUM(GLUT_DEVICE_IGNORE_KEY_REPEAT)); | |
1120 | rb_define_const(mGlut, "GLUT_DEVICE_KEY_REPEAT", INT2NUM(GLUT_DEVICE_KEY_REPEAT)); | |
1121 | rb_define_const(mGlut, "GLUT_HAS_JOYSTICK", INT2NUM(GLUT_HAS_JOYSTICK)); | |
1122 | rb_define_const(mGlut, "GLUT_OWNS_JOYSTICK", INT2NUM(GLUT_OWNS_JOYSTICK)); | |
1123 | rb_define_const(mGlut, "GLUT_JOYSTICK_BUTTONS", INT2NUM(GLUT_JOYSTICK_BUTTONS)); | |
1124 | rb_define_const(mGlut, "GLUT_JOYSTICK_AXES", INT2NUM(GLUT_JOYSTICK_AXES)); | |
1125 | rb_define_const(mGlut, "GLUT_JOYSTICK_POLL_RATE", INT2NUM(GLUT_JOYSTICK_POLL_RATE)); | |
1126 | rb_define_const(mGlut, "GLUT_KEY_REPEAT_OFF", INT2NUM(GLUT_KEY_REPEAT_OFF)); | |
1127 | rb_define_const(mGlut, "GLUT_KEY_REPEAT_ON", INT2NUM(GLUT_KEY_REPEAT_ON)); | |
1128 | rb_define_const(mGlut, "GLUT_KEY_REPEAT_DEFAULT", INT2NUM(GLUT_KEY_REPEAT_DEFAULT)); | |
1129 | rb_define_const(mGlut, "GLUT_JOYSTICK_BUTTON_A", INT2NUM(GLUT_JOYSTICK_BUTTON_A)); | |
1130 | rb_define_const(mGlut, "GLUT_JOYSTICK_BUTTON_B", INT2NUM(GLUT_JOYSTICK_BUTTON_B)); | |
1131 | rb_define_const(mGlut, "GLUT_JOYSTICK_BUTTON_C", INT2NUM(GLUT_JOYSTICK_BUTTON_C)); | |
1132 | rb_define_const(mGlut, "GLUT_JOYSTICK_BUTTON_D", INT2NUM(GLUT_JOYSTICK_BUTTON_D)); | |
1133 | rb_define_const(mGlut, "GLUT_GAME_MODE_ACTIVE", INT2NUM(GLUT_GAME_MODE_ACTIVE)); | |
1134 | rb_define_const(mGlut, "GLUT_GAME_MODE_POSSIBLE", INT2NUM(GLUT_GAME_MODE_POSSIBLE)); | |
1135 | rb_define_const(mGlut, "GLUT_GAME_MODE_WIDTH", INT2NUM(GLUT_GAME_MODE_WIDTH)); | |
1136 | rb_define_const(mGlut, "GLUT_GAME_MODE_HEIGHT", INT2NUM(GLUT_GAME_MODE_HEIGHT)); | |
1137 | rb_define_const(mGlut, "GLUT_GAME_MODE_PIXEL_DEPTH", INT2NUM(GLUT_GAME_MODE_PIXEL_DEPTH)); | |
1138 | rb_define_const(mGlut, "GLUT_GAME_MODE_REFRESH_RATE", INT2NUM(GLUT_GAME_MODE_REFRESH_RATE)); | |
1139 | rb_define_const(mGlut, "GLUT_GAME_MODE_DISPLAY_CHANGED", INT2NUM(GLUT_GAME_MODE_DISPLAY_CHANGED)); | |
1140 | ||
1141 | // Some OSX specific constants | |
1142 | #ifdef GLUT_NO_RECOVERY | |
1143 | rb_define_const(mGlut, "GLUT_NO_RECOVERY", INT2NUM(GLUT_NO_RECOVERY)); | |
1144 | #endif | |
1145 | #ifdef GLUT_3_2_CORE_PROFILE | |
1146 | rb_define_const(mGlut, "GLUT_3_2_CORE_PROFILE", INT2NUM(GLUT_3_2_CORE_PROFILE)); | |
1147 | #endif | |
1148 | ||
1149 | Init_glut_callbacks(); | |
1150 | Init_glut_ext(); | |
1151 | } |
0 | #include "common.h" | |
1 | ||
2 | /* HACK experimental API */ | |
3 | void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1); | |
4 | ||
5 | static ID call_id; /* 'call' method id */ | |
6 | static VALUE idle_func = Qnil; | |
7 | static VALUE joystick_func = Qnil; | |
8 | static VALUE menustate_func = Qnil; | |
9 | static VALUE menustatus_func = Qnil; | |
10 | static VALUE timer_func = Qnil; | |
11 | ||
12 | typedef void *(*gvl_call)(void *); | |
13 | ||
14 | struct callback_args { | |
15 | union { | |
16 | int button; | |
17 | int dial; | |
18 | int special; | |
19 | int state; | |
20 | int value; | |
21 | int width; | |
22 | int x; | |
23 | unsigned char key; | |
24 | unsigned int button_mask; | |
25 | } arg0; | |
26 | union { | |
27 | int height; | |
28 | int state; | |
29 | int value; | |
30 | int x; | |
31 | int y; | |
32 | } arg1; | |
33 | union { | |
34 | int x; | |
35 | int y; | |
36 | int z; | |
37 | } arg2; | |
38 | union { | |
39 | int y; | |
40 | int z; | |
41 | } arg3; | |
42 | } ; | |
43 | ||
44 | static struct callback_args * | |
45 | alloc_callback_args(void) { | |
46 | struct callback_args *args; | |
47 | args = (struct callback_args *)malloc(sizeof(struct callback_args)); | |
48 | ||
49 | if (args == NULL) { | |
50 | fprintf(stderr, "[BUG] out of memory in opengl callback"); | |
51 | abort(); | |
52 | } | |
53 | ||
54 | return args; | |
55 | } | |
56 | ||
57 | /* | |
58 | * macros for registering callbacks - | |
59 | * | |
60 | * most GLUT callback functions are part of specific window state, so | |
61 | * the same callback may have different functions for each GLUT window | |
62 | * | |
63 | * callbacks that are not tied to specific window (idle,timer,menustate) are | |
64 | * registered manually | |
65 | */ | |
66 | ||
67 | #define WINDOW_CALLBACK_SETUP(_funcname) \ | |
68 | static VALUE _funcname = Qnil; \ | |
69 | static VALUE \ | |
70 | glut_ ## _funcname(VALUE self, VALUE callback) \ | |
71 | { \ | |
72 | int win = glutGetWindow(); \ | |
73 | \ | |
74 | if (win == 0) { \ | |
75 | rb_raise(rb_eRuntimeError, "glut%s needs current window", #_funcname); \ | |
76 | } \ | |
77 | \ | |
78 | callback = rb_glut_check_callback(self, callback); \ | |
79 | \ | |
80 | rb_ary_store(_funcname, win, callback); \ | |
81 | \ | |
82 | if (NIL_P(callback)) \ | |
83 | glut##_funcname(NULL); \ | |
84 | else \ | |
85 | glut##_funcname(&glut_##_funcname##Callback0); \ | |
86 | \ | |
87 | return Qnil; \ | |
88 | } | |
89 | ||
90 | #define WINDOW_CALLBACK_DEFINE(module, _funcname) \ | |
91 | rb_define_module_function(module, "glut"#_funcname, glut_##_funcname, 1); \ | |
92 | rb_global_variable(&_funcname); \ | |
93 | _funcname = rb_ary_new() | |
94 | ||
95 | static void GLUTCALLBACK glut_DisplayFuncCallback0(void); | |
96 | static void GLUTCALLBACK glut_ReshapeFuncCallback0(int, int); | |
97 | static void GLUTCALLBACK glut_KeyboardFuncCallback0(unsigned char, int, int); | |
98 | static void GLUTCALLBACK glut_MouseFuncCallback0(int, int, int, int); | |
99 | static void GLUTCALLBACK glut_MotionFuncCallback0(int, int); | |
100 | static void GLUTCALLBACK glut_PassiveMotionFuncCallback0(int, int); | |
101 | static void GLUTCALLBACK glut_EntryFuncCallback0(int); | |
102 | static void GLUTCALLBACK glut_VisibilityFuncCallback0(int); | |
103 | static void GLUTCALLBACK glut_SpecialFuncCallback0(int, int, int); | |
104 | static void GLUTCALLBACK glut_SpaceballMotionFuncCallback0(int, int, int); | |
105 | static void GLUTCALLBACK glut_SpaceballRotateFuncCallback0(int, int, int); | |
106 | static void GLUTCALLBACK glut_SpaceballButtonFuncCallback0(int, int); | |
107 | static void GLUTCALLBACK glut_ButtonBoxFuncCallback0(int, int); | |
108 | static void GLUTCALLBACK glut_DialsFuncCallback0(int, int); | |
109 | static void GLUTCALLBACK glut_TabletMotionFuncCallback0(int, int); | |
110 | static void GLUTCALLBACK glut_TabletButtonFuncCallback0(int, int, int, int); | |
111 | static void GLUTCALLBACK glut_OverlayDisplayFuncCallback0(void); | |
112 | static void GLUTCALLBACK glut_WindowStatusFuncCallback0(int); | |
113 | static void GLUTCALLBACK glut_JoystickFuncCallback0(unsigned int, int, int, int); | |
114 | static void GLUTCALLBACK glut_KeyboardUpFuncCallback0(unsigned char, int, int); | |
115 | static void GLUTCALLBACK glut_SpecialUpFuncCallback0(int, int, int); | |
116 | ||
117 | WINDOW_CALLBACK_SETUP(DisplayFunc) | |
118 | WINDOW_CALLBACK_SETUP(ReshapeFunc) | |
119 | WINDOW_CALLBACK_SETUP(KeyboardFunc) | |
120 | WINDOW_CALLBACK_SETUP(MouseFunc) | |
121 | WINDOW_CALLBACK_SETUP(MotionFunc) | |
122 | WINDOW_CALLBACK_SETUP(PassiveMotionFunc) | |
123 | WINDOW_CALLBACK_SETUP(EntryFunc) | |
124 | WINDOW_CALLBACK_SETUP(VisibilityFunc) | |
125 | WINDOW_CALLBACK_SETUP(SpecialFunc) | |
126 | WINDOW_CALLBACK_SETUP(SpaceballMotionFunc) | |
127 | WINDOW_CALLBACK_SETUP(SpaceballRotateFunc) | |
128 | WINDOW_CALLBACK_SETUP(SpaceballButtonFunc) | |
129 | WINDOW_CALLBACK_SETUP(ButtonBoxFunc) | |
130 | WINDOW_CALLBACK_SETUP(DialsFunc) | |
131 | WINDOW_CALLBACK_SETUP(TabletMotionFunc) | |
132 | WINDOW_CALLBACK_SETUP(TabletButtonFunc) | |
133 | WINDOW_CALLBACK_SETUP(OverlayDisplayFunc) | |
134 | WINDOW_CALLBACK_SETUP(WindowStatusFunc) | |
135 | WINDOW_CALLBACK_SETUP(KeyboardUpFunc) | |
136 | WINDOW_CALLBACK_SETUP(SpecialUpFunc) | |
137 | ||
138 | GLUT_SIMPLE_FUNCTION(ForceJoystickFunc) | |
139 | ||
140 | static void * | |
141 | glut_DisplayFuncCallback(void *ignored) { | |
142 | VALUE func; | |
143 | ||
144 | func = rb_ary_entry(DisplayFunc, glutGetWindow()); | |
145 | ||
146 | if (!NIL_P(func)) | |
147 | rb_funcall(func, call_id, 0); | |
148 | ||
149 | return NULL; | |
150 | } | |
151 | ||
152 | static void GLUTCALLBACK | |
153 | glut_DisplayFuncCallback0(void) { | |
154 | rb_thread_call_with_gvl(glut_DisplayFuncCallback, NULL); | |
155 | } | |
156 | ||
157 | static void * | |
158 | glut_ReshapeFuncCallback(struct callback_args *args) { | |
159 | VALUE func = rb_ary_entry(ReshapeFunc, glutGetWindow()); | |
160 | VALUE width = INT2FIX(args->arg0.width); | |
161 | VALUE height = INT2FIX(args->arg1.height); | |
162 | ||
163 | if (!NIL_P(func)) | |
164 | rb_funcall(func, call_id, 2, width, height); | |
165 | ||
166 | return NULL; | |
167 | } | |
168 | ||
169 | static void GLUTCALLBACK | |
170 | glut_ReshapeFuncCallback0(int width, int height) { | |
171 | struct callback_args *args = alloc_callback_args(); | |
172 | ||
173 | args->arg0.width = width; | |
174 | args->arg1.height = height; | |
175 | ||
176 | rb_thread_call_with_gvl((gvl_call)glut_ReshapeFuncCallback, args); | |
177 | ||
178 | free(args); | |
179 | } | |
180 | ||
181 | static void * | |
182 | glut_KeyboardFuncCallback(struct callback_args *args) { | |
183 | VALUE func = rb_ary_entry(KeyboardFunc, glutGetWindow()); | |
184 | #if HAVE_SINGLE_BYTE_STRINGS | |
185 | VALUE key = rb_str_new((char *)&args->arg0.key, 1); | |
186 | #else | |
187 | VALUE key = UINT2NUM((unsigned char)args->arg0.key); | |
188 | #endif | |
189 | VALUE x = INT2FIX(args->arg1.x); | |
190 | VALUE y = INT2FIX(args->arg2.y); | |
191 | ||
192 | if (!NIL_P(func)) | |
193 | rb_funcall(func, call_id, 3, key, x, y); | |
194 | ||
195 | return NULL; | |
196 | } | |
197 | ||
198 | static void GLUTCALLBACK | |
199 | glut_KeyboardFuncCallback0(unsigned char key, int x, int y) { | |
200 | struct callback_args *args = alloc_callback_args(); | |
201 | ||
202 | args->arg0.key = key; | |
203 | args->arg1.x = x; | |
204 | args->arg2.y = y; | |
205 | ||
206 | rb_thread_call_with_gvl((gvl_call)glut_KeyboardFuncCallback, args); | |
207 | ||
208 | free(args); | |
209 | } | |
210 | ||
211 | static void * | |
212 | glut_KeyboardUpFuncCallback(struct callback_args *args) { | |
213 | VALUE func = rb_ary_entry(KeyboardUpFunc, glutGetWindow()); | |
214 | #if HAVE_SINGLE_BYTE_STRINGS | |
215 | VALUE key = rb_str_new((char *)&args->arg0.key, 1); | |
216 | #else | |
217 | VALUE key = UINT2NUM((unsigned char)args->arg0.key); | |
218 | #endif | |
219 | VALUE x = INT2FIX(args->arg1.x); | |
220 | VALUE y = INT2FIX(args->arg2.y); | |
221 | ||
222 | if (!NIL_P(func)) | |
223 | rb_funcall(func, call_id, 3, key, x, y); | |
224 | ||
225 | return NULL; | |
226 | } | |
227 | ||
228 | static void GLUTCALLBACK | |
229 | glut_KeyboardUpFuncCallback0(unsigned char key, int x, int y) { | |
230 | struct callback_args *args = alloc_callback_args(); | |
231 | ||
232 | args->arg0.key = key; | |
233 | args->arg1.x = x; | |
234 | args->arg2.y = y; | |
235 | ||
236 | rb_thread_call_with_gvl((gvl_call)glut_KeyboardUpFuncCallback, args); | |
237 | ||
238 | free(args); | |
239 | } | |
240 | ||
241 | static void * | |
242 | glut_MouseFuncCallback(struct callback_args *args) { | |
243 | VALUE func = rb_ary_entry(MouseFunc, glutGetWindow()); | |
244 | ||
245 | VALUE button = INT2FIX(args->arg0.button); | |
246 | VALUE state = INT2FIX(args->arg1.state); | |
247 | VALUE x = INT2FIX(args->arg2.x); | |
248 | VALUE y = INT2FIX(args->arg3.y); | |
249 | ||
250 | if (!NIL_P(func)) | |
251 | rb_funcall(func, call_id, 4, button, state, x, y); | |
252 | ||
253 | return NULL; | |
254 | } | |
255 | ||
256 | static void GLUTCALLBACK | |
257 | glut_MouseFuncCallback0(int button, int state, int x, int y) { | |
258 | struct callback_args *args = alloc_callback_args(); | |
259 | ||
260 | args->arg0.button = button; | |
261 | args->arg1.state = state; | |
262 | args->arg2.x = x; | |
263 | args->arg3.y = y; | |
264 | ||
265 | rb_thread_call_with_gvl((gvl_call)glut_MouseFuncCallback, args); | |
266 | ||
267 | free(args); | |
268 | } | |
269 | ||
270 | static void * | |
271 | glut_MotionFuncCallback(struct callback_args *args) { | |
272 | VALUE func = rb_ary_entry(MotionFunc, glutGetWindow()); | |
273 | VALUE x = INT2FIX(args->arg0.x); | |
274 | VALUE y = INT2FIX(args->arg1.y); | |
275 | ||
276 | if (!NIL_P(func)) | |
277 | rb_funcall(func, call_id, 2, x, y); | |
278 | ||
279 | return NULL; | |
280 | } | |
281 | ||
282 | static void GLUTCALLBACK | |
283 | glut_MotionFuncCallback0(int x, int y) { | |
284 | struct callback_args *args = alloc_callback_args(); | |
285 | ||
286 | args->arg0.x = x; | |
287 | args->arg1.y = y; | |
288 | ||
289 | rb_thread_call_with_gvl((gvl_call)glut_MotionFuncCallback, args); | |
290 | ||
291 | free(args); | |
292 | } | |
293 | ||
294 | static void * | |
295 | glut_PassiveMotionFuncCallback(struct callback_args *args) { | |
296 | VALUE func = rb_ary_entry(PassiveMotionFunc, glutGetWindow()); | |
297 | VALUE x = INT2FIX(args->arg0.x); | |
298 | VALUE y = INT2FIX(args->arg1.y); | |
299 | ||
300 | if (!NIL_P(func)) | |
301 | rb_funcall(func, call_id, 2, x, y); | |
302 | ||
303 | return NULL; | |
304 | } | |
305 | ||
306 | static void GLUTCALLBACK | |
307 | glut_PassiveMotionFuncCallback0(int x, int y) { | |
308 | struct callback_args *args = alloc_callback_args(); | |
309 | ||
310 | args->arg0.x = x; | |
311 | args->arg1.y = y; | |
312 | ||
313 | rb_thread_call_with_gvl((gvl_call)glut_PassiveMotionFuncCallback, args); | |
314 | ||
315 | free(args); | |
316 | } | |
317 | ||
318 | static void * | |
319 | glut_EntryFuncCallback(struct callback_args *args) { | |
320 | VALUE func = rb_ary_entry(EntryFunc, glutGetWindow()); | |
321 | VALUE state = INT2NUM(args->arg0.state); | |
322 | ||
323 | if (!NIL_P(func)) | |
324 | rb_funcall(func, call_id, 1, state); | |
325 | ||
326 | return NULL; | |
327 | } | |
328 | ||
329 | static void GLUTCALLBACK | |
330 | glut_EntryFuncCallback0(int state) { | |
331 | struct callback_args *args = alloc_callback_args(); | |
332 | ||
333 | args->arg0.state = state; | |
334 | ||
335 | rb_thread_call_with_gvl((gvl_call)glut_EntryFuncCallback, args); | |
336 | ||
337 | free(args); | |
338 | } | |
339 | ||
340 | static void * | |
341 | glut_VisibilityFuncCallback(struct callback_args *args) { | |
342 | VALUE func = rb_ary_entry(VisibilityFunc, glutGetWindow()); | |
343 | VALUE state = INT2NUM(args->arg0.state); | |
344 | ||
345 | if (!NIL_P(func)) | |
346 | rb_funcall(func, call_id, 1, state); | |
347 | ||
348 | return NULL; | |
349 | } | |
350 | ||
351 | static void GLUTCALLBACK | |
352 | glut_VisibilityFuncCallback0(int state) { | |
353 | struct callback_args *args = alloc_callback_args(); | |
354 | ||
355 | args->arg0.state = state; | |
356 | ||
357 | rb_thread_call_with_gvl((gvl_call)glut_VisibilityFuncCallback, args); | |
358 | ||
359 | free(args); | |
360 | } | |
361 | ||
362 | static void * | |
363 | glut_IdleFuncCallback(void *ignored) { | |
364 | if (!NIL_P(idle_func)) | |
365 | rb_funcall(idle_func, call_id, 0); | |
366 | ||
367 | return NULL; | |
368 | } | |
369 | ||
370 | static void GLUTCALLBACK | |
371 | glut_IdleFuncCallback0(void) { | |
372 | rb_thread_call_with_gvl((gvl_call)glut_IdleFuncCallback, NULL); | |
373 | } | |
374 | ||
375 | static void * | |
376 | glut_TimerFuncCallback(struct callback_args *args) { | |
377 | VALUE value = INT2NUM(args->arg0.value); | |
378 | ||
379 | if (!NIL_P(timer_func)) | |
380 | rb_funcall(timer_func, call_id, 1, value); | |
381 | ||
382 | return NULL; | |
383 | } | |
384 | ||
385 | static void GLUTCALLBACK | |
386 | glut_TimerFuncCallback0(int value) { | |
387 | struct callback_args *args = alloc_callback_args(); | |
388 | ||
389 | args->arg0.value = value; | |
390 | ||
391 | rb_thread_call_with_gvl((gvl_call)glut_TimerFuncCallback, args); | |
392 | ||
393 | free(args); | |
394 | } | |
395 | ||
396 | static void * | |
397 | glut_MenuStateFuncCallback(struct callback_args *args) { | |
398 | VALUE state = INT2NUM(args->arg0.state); | |
399 | ||
400 | if (!NIL_P(menustate_func)) | |
401 | rb_funcall(menustate_func, call_id, 1, state); | |
402 | ||
403 | return NULL; | |
404 | } | |
405 | ||
406 | static void GLUTCALLBACK | |
407 | glut_MenuStateFuncCallback0(int state) { | |
408 | struct callback_args *args = alloc_callback_args(); | |
409 | ||
410 | args->arg0.state = state; | |
411 | ||
412 | rb_thread_call_with_gvl((gvl_call)glut_MenuStateFuncCallback, args); | |
413 | ||
414 | free(args); | |
415 | } | |
416 | ||
417 | static void * | |
418 | glut_MenuStatusFuncCallback(struct callback_args *args) { | |
419 | VALUE state = INT2NUM(args->arg0.state); | |
420 | VALUE x = INT2NUM(args->arg1.x); | |
421 | VALUE y = INT2NUM(args->arg2.y); | |
422 | ||
423 | if (!NIL_P(menustatus_func)) | |
424 | rb_funcall(menustatus_func, call_id, 3, state, x, y); | |
425 | ||
426 | return NULL; | |
427 | } | |
428 | ||
429 | static void GLUTCALLBACK | |
430 | glut_MenuStatusFuncCallback0(int state, int x, int y) { | |
431 | struct callback_args *args = alloc_callback_args(); | |
432 | ||
433 | args->arg0.state = state; | |
434 | args->arg1.x = x; | |
435 | args->arg2.y = y; | |
436 | ||
437 | rb_thread_call_with_gvl((gvl_call)glut_MenuStatusFuncCallback, args); | |
438 | ||
439 | free(args); | |
440 | } | |
441 | ||
442 | static void * | |
443 | glut_SpecialFuncCallback(struct callback_args *args) { | |
444 | VALUE func = rb_ary_entry(SpecialFunc, glutGetWindow()); | |
445 | VALUE key = INT2NUM(args->arg0.key); | |
446 | VALUE x = INT2NUM(args->arg1.x); | |
447 | VALUE y = INT2NUM(args->arg2.y); | |
448 | ||
449 | if (!NIL_P(func)) | |
450 | rb_funcall(func, call_id, 3, key, x, y); | |
451 | ||
452 | return NULL; | |
453 | } | |
454 | ||
455 | static void GLUTCALLBACK | |
456 | glut_SpecialFuncCallback0(int key, int x, int y) { | |
457 | struct callback_args *args = alloc_callback_args(); | |
458 | ||
459 | args->arg0.key = key; | |
460 | args->arg1.x = x; | |
461 | args->arg2.y = y; | |
462 | ||
463 | rb_thread_call_with_gvl((gvl_call)glut_SpecialFuncCallback, args); | |
464 | ||
465 | free(args); | |
466 | } | |
467 | ||
468 | static void * | |
469 | glut_SpecialUpFuncCallback(struct callback_args *args) { | |
470 | VALUE func = rb_ary_entry(SpecialUpFunc, glutGetWindow()); | |
471 | VALUE key = INT2NUM(args->arg0.key); | |
472 | VALUE x = INT2NUM(args->arg1.x); | |
473 | VALUE y = INT2NUM(args->arg2.y); | |
474 | ||
475 | if (!NIL_P(func)) | |
476 | rb_funcall(func, call_id, 3, key, x, y); | |
477 | ||
478 | return NULL; | |
479 | } | |
480 | ||
481 | static void GLUTCALLBACK | |
482 | glut_SpecialUpFuncCallback0(int key, int x, int y) { | |
483 | struct callback_args *args = alloc_callback_args(); | |
484 | ||
485 | args->arg0.key = key; | |
486 | args->arg1.x = x; | |
487 | args->arg2.y = y; | |
488 | ||
489 | rb_thread_call_with_gvl((gvl_call)glut_SpecialUpFuncCallback, args); | |
490 | ||
491 | free(args); | |
492 | } | |
493 | ||
494 | static void * | |
495 | glut_SpaceballMotionFuncCallback(struct callback_args *args) { | |
496 | VALUE func = rb_ary_entry(SpaceballMotionFunc, glutGetWindow()); | |
497 | VALUE x = INT2NUM(args->arg0.x); | |
498 | VALUE y = INT2NUM(args->arg1.y); | |
499 | VALUE z = INT2NUM(args->arg2.z); | |
500 | ||
501 | if (!NIL_P(func)) | |
502 | rb_funcall(func, call_id, 3, x, y, z); | |
503 | ||
504 | return NULL; | |
505 | } | |
506 | ||
507 | static void GLUTCALLBACK | |
508 | glut_SpaceballMotionFuncCallback0(int x, int y, int z) { | |
509 | struct callback_args *args = alloc_callback_args(); | |
510 | ||
511 | args->arg0.x = x; | |
512 | args->arg1.y = y; | |
513 | args->arg2.z = z; | |
514 | ||
515 | rb_thread_call_with_gvl((gvl_call)glut_SpaceballMotionFuncCallback, args); | |
516 | ||
517 | free(args); | |
518 | } | |
519 | ||
520 | static void * | |
521 | glut_SpaceballRotateFuncCallback(struct callback_args *args) { | |
522 | VALUE func = rb_ary_entry(SpaceballRotateFunc, glutGetWindow()); | |
523 | VALUE x = INT2NUM(args->arg0.x); | |
524 | VALUE y = INT2NUM(args->arg1.y); | |
525 | VALUE z = INT2NUM(args->arg2.z); | |
526 | ||
527 | if (!NIL_P(func)) | |
528 | rb_funcall(func, call_id, 3, x, y, z); | |
529 | ||
530 | return NULL; | |
531 | } | |
532 | ||
533 | static void GLUTCALLBACK | |
534 | glut_SpaceballRotateFuncCallback0(int x, int y, int z) { | |
535 | struct callback_args *args = alloc_callback_args(); | |
536 | ||
537 | args->arg0.x = x; | |
538 | args->arg1.y = y; | |
539 | args->arg2.z = z; | |
540 | ||
541 | rb_thread_call_with_gvl((gvl_call)glut_SpaceballRotateFuncCallback, args); | |
542 | ||
543 | free(args); | |
544 | } | |
545 | ||
546 | static void * | |
547 | glut_SpaceballButtonFuncCallback(struct callback_args *args) { | |
548 | VALUE func = rb_ary_entry(SpaceballButtonFunc, glutGetWindow()); | |
549 | VALUE button = INT2NUM(args->arg0.button); | |
550 | VALUE state = INT2NUM(args->arg1.state); | |
551 | ||
552 | if (!NIL_P(func)) | |
553 | rb_funcall(func, call_id, 2, button, state); | |
554 | ||
555 | return NULL; | |
556 | } | |
557 | ||
558 | static void GLUTCALLBACK | |
559 | glut_SpaceballButtonFuncCallback0(int button, int state) { | |
560 | struct callback_args *args = alloc_callback_args(); | |
561 | ||
562 | args->arg0.button = button; | |
563 | args->arg1.state = state; | |
564 | ||
565 | rb_thread_call_with_gvl((gvl_call)glut_SpaceballButtonFuncCallback, args); | |
566 | ||
567 | free(args); | |
568 | } | |
569 | ||
570 | static void * | |
571 | glut_ButtonBoxFuncCallback(struct callback_args *args) { | |
572 | VALUE func = rb_ary_entry(ButtonBoxFunc, glutGetWindow()); | |
573 | VALUE button = INT2NUM(args->arg0.button); | |
574 | VALUE state = INT2NUM(args->arg1.state); | |
575 | ||
576 | if (!NIL_P(func)) | |
577 | rb_funcall(func, call_id, 2, button, state); | |
578 | ||
579 | return NULL; | |
580 | } | |
581 | ||
582 | static void GLUTCALLBACK | |
583 | glut_ButtonBoxFuncCallback0(int button, int state) { | |
584 | struct callback_args *args = alloc_callback_args(); | |
585 | ||
586 | args->arg0.button = button; | |
587 | args->arg1.state = state; | |
588 | ||
589 | rb_thread_call_with_gvl((gvl_call)glut_ButtonBoxFuncCallback, args); | |
590 | ||
591 | free(args); | |
592 | } | |
593 | ||
594 | static void * | |
595 | glut_DialsFuncCallback(struct callback_args *args) { | |
596 | VALUE func = rb_ary_entry(DialsFunc, glutGetWindow()); | |
597 | VALUE dial = INT2NUM(args->arg0.dial); | |
598 | VALUE value = INT2NUM(args->arg1.value); | |
599 | ||
600 | if (!NIL_P(func)) | |
601 | rb_funcall(func, call_id, 2, dial, value); | |
602 | ||
603 | return NULL; | |
604 | } | |
605 | ||
606 | static void GLUTCALLBACK | |
607 | glut_DialsFuncCallback0(int dial, int value) { | |
608 | struct callback_args *args = alloc_callback_args(); | |
609 | ||
610 | args->arg0.dial = dial; | |
611 | args->arg1.value = value; | |
612 | ||
613 | rb_thread_call_with_gvl((gvl_call)glut_DialsFuncCallback, args); | |
614 | ||
615 | free(args); | |
616 | } | |
617 | ||
618 | static void * | |
619 | glut_TabletMotionFuncCallback(struct callback_args *args) { | |
620 | VALUE func = rb_ary_entry(TabletMotionFunc, glutGetWindow()); | |
621 | VALUE x = INT2NUM(args->arg0.x); | |
622 | VALUE y = INT2NUM(args->arg1.y); | |
623 | ||
624 | if (!NIL_P(func)) | |
625 | rb_funcall(func, call_id, 2, x, y); | |
626 | ||
627 | return NULL; | |
628 | } | |
629 | ||
630 | static void GLUTCALLBACK | |
631 | glut_TabletMotionFuncCallback0(int x, int y) { | |
632 | struct callback_args *args = alloc_callback_args(); | |
633 | ||
634 | args->arg0.x = x; | |
635 | args->arg1.y = y; | |
636 | ||
637 | rb_thread_call_with_gvl((gvl_call)glut_TabletMotionFuncCallback, args); | |
638 | ||
639 | free(args); | |
640 | } | |
641 | ||
642 | static void * | |
643 | glut_TabletButtonFuncCallback(struct callback_args *args) { | |
644 | VALUE func = rb_ary_entry(TabletButtonFunc, glutGetWindow()); | |
645 | VALUE button = INT2NUM(args->arg0.button); | |
646 | VALUE state = INT2NUM(args->arg1.state); | |
647 | VALUE x = INT2NUM(args->arg2.x); | |
648 | VALUE y = INT2NUM(args->arg3.y); | |
649 | ||
650 | if (!NIL_P(func)) | |
651 | rb_funcall(func, call_id, 4, button, state, x, y); | |
652 | ||
653 | return NULL; | |
654 | } | |
655 | ||
656 | static void GLUTCALLBACK | |
657 | glut_TabletButtonFuncCallback0(int button, int state, int x, int y) { | |
658 | struct callback_args *args = alloc_callback_args(); | |
659 | ||
660 | args->arg0.button = button; | |
661 | args->arg1.state = state; | |
662 | args->arg2.x = x; | |
663 | args->arg3.y = y; | |
664 | ||
665 | rb_thread_call_with_gvl((gvl_call)glut_TabletButtonFuncCallback, args); | |
666 | ||
667 | free(args); | |
668 | } | |
669 | ||
670 | static void * | |
671 | glut_OverlayDisplayFuncCallback(void) { | |
672 | VALUE func = rb_ary_entry(OverlayDisplayFunc, glutGetWindow()); | |
673 | ||
674 | if (!NIL_P(func)) | |
675 | rb_funcall(func, call_id, 0); | |
676 | ||
677 | return NULL; | |
678 | } | |
679 | ||
680 | static void GLUTCALLBACK | |
681 | glut_OverlayDisplayFuncCallback0(void) { | |
682 | rb_thread_call_with_gvl((gvl_call)glut_OverlayDisplayFuncCallback, NULL); | |
683 | } | |
684 | ||
685 | static void * | |
686 | glut_WindowStatusFuncCallback(struct callback_args *args) { | |
687 | VALUE func = rb_ary_entry(WindowStatusFunc, glutGetWindow()); | |
688 | VALUE state = INT2NUM(args->arg0.state); | |
689 | ||
690 | if (!NIL_P(func)) | |
691 | rb_funcall(func, call_id, 1, state); | |
692 | ||
693 | return NULL; | |
694 | } | |
695 | ||
696 | static void GLUTCALLBACK | |
697 | glut_WindowStatusFuncCallback0(int state) { | |
698 | struct callback_args *args = alloc_callback_args(); | |
699 | ||
700 | args->arg0.state = state; | |
701 | ||
702 | rb_thread_call_with_gvl((gvl_call)glut_WindowStatusFuncCallback, args); | |
703 | ||
704 | free(args); | |
705 | } | |
706 | ||
707 | static void * | |
708 | glut_JoystickFuncCallback(struct callback_args *args) { | |
709 | VALUE func = rb_ary_entry(joystick_func, glutGetWindow()); | |
710 | VALUE button_mask = UINT2NUM(args->arg0.button_mask); | |
711 | VALUE x = INT2NUM(args->arg1.x); | |
712 | VALUE y = INT2NUM(args->arg2.y); | |
713 | VALUE z = INT2NUM(args->arg3.z); | |
714 | ||
715 | if (!NIL_P(func)) | |
716 | rb_funcall(func, call_id, 4, button_mask, x, y, z); | |
717 | ||
718 | return NULL; | |
719 | } | |
720 | ||
721 | static void GLUTCALLBACK | |
722 | glut_JoystickFuncCallback0(unsigned int button_mask, int x, int y, int z) { | |
723 | struct callback_args *args = alloc_callback_args(); | |
724 | ||
725 | args->arg0.button_mask = button_mask; | |
726 | args->arg1.x = x; | |
727 | args->arg2.y = y; | |
728 | args->arg3.z = z; | |
729 | ||
730 | rb_thread_call_with_gvl((gvl_call)glut_JoystickFuncCallback, args); | |
731 | ||
732 | free(args); | |
733 | } | |
734 | ||
735 | static VALUE | |
736 | glut_JoystickFunc(VALUE self, VALUE callback, VALUE _poll_interval) { | |
737 | int win = glutGetWindow(); | |
738 | int poll_interval = NUM2INT(_poll_interval); | |
739 | ||
740 | if (win == 0) | |
741 | rb_raise(rb_eRuntimeError, "glutJoystickFunc needs current window"); | |
742 | ||
743 | callback = rb_glut_check_callback(self, callback); | |
744 | ||
745 | rb_ary_store(joystick_func, win, callback); | |
746 | ||
747 | if (NIL_P(callback)) | |
748 | glutJoystickFunc(NULL, -1); | |
749 | else | |
750 | glutJoystickFunc(glut_JoystickFuncCallback0, poll_interval); | |
751 | ||
752 | return Qnil; | |
753 | } | |
754 | ||
755 | static VALUE | |
756 | glut_IdleFunc(VALUE self, VALUE callback) { | |
757 | callback = rb_glut_check_callback(self, callback); | |
758 | ||
759 | idle_func = callback; | |
760 | ||
761 | if (NIL_P(callback)) | |
762 | glutIdleFunc(NULL); | |
763 | else | |
764 | glutIdleFunc(glut_IdleFuncCallback0); | |
765 | ||
766 | return Qnil; | |
767 | } | |
768 | ||
769 | static VALUE | |
770 | glut_MenuStateFunc(VALUE self, VALUE callback) { | |
771 | menustate_func = rb_glut_check_callback(self, callback); | |
772 | ||
773 | if (NIL_P(menustate_func)) | |
774 | glutMenuStateFunc(NULL); | |
775 | else | |
776 | glutMenuStateFunc(glut_MenuStateFuncCallback0); | |
777 | ||
778 | return Qnil; | |
779 | } | |
780 | ||
781 | static VALUE | |
782 | glut_MenuStatusFunc(VALUE self, VALUE callback) { | |
783 | menustatus_func = rb_glut_check_callback(self, callback); | |
784 | ||
785 | if (NIL_P(menustatus_func)) | |
786 | glutMenuStatusFunc(NULL); | |
787 | else | |
788 | glutMenuStatusFunc(glut_MenuStatusFuncCallback0); | |
789 | ||
790 | return Qnil; | |
791 | } | |
792 | ||
793 | static VALUE | |
794 | glut_TimerFunc(VALUE self, VALUE _msec, VALUE callback, VALUE _value) { | |
795 | unsigned int msec = NUM2UINT(_msec); | |
796 | int value = NUM2INT(_value); | |
797 | ||
798 | timer_func = rb_glut_check_callback(self, callback); | |
799 | ||
800 | glutTimerFunc(msec, glut_TimerFuncCallback0, value); | |
801 | ||
802 | return Qnil; | |
803 | } | |
804 | ||
805 | void Init_glut_callbacks() { | |
806 | VALUE mGlut = rb_path2class("Glut"); | |
807 | ||
808 | call_id = rb_intern("call"); | |
809 | joystick_func = rb_ary_new(); | |
810 | ||
811 | rb_global_variable(&joystick_func); | |
812 | rb_gc_register_address(&idle_func); | |
813 | rb_gc_register_address(&timer_func); | |
814 | rb_gc_register_address(&menustate_func); | |
815 | ||
816 | rb_define_module_function(mGlut, "glutJoystickFunc", glut_JoystickFunc, 2); | |
817 | rb_define_module_function(mGlut, "glutForceJoystickFunc", glut_ForceJoystickFunc, 0); | |
818 | rb_define_module_function(mGlut, "glutIdleFunc", glut_IdleFunc, 1); | |
819 | rb_define_module_function(mGlut, "glutMenuStateFunc", glut_MenuStateFunc, 1); | |
820 | rb_define_module_function(mGlut, "glutMenuStatusFunc", glut_MenuStatusFunc, 1); | |
821 | rb_define_module_function(mGlut, "glutTimerFunc", glut_TimerFunc, 3); | |
822 | ||
823 | WINDOW_CALLBACK_DEFINE(mGlut, ButtonBoxFunc); | |
824 | WINDOW_CALLBACK_DEFINE(mGlut, DialsFunc); | |
825 | WINDOW_CALLBACK_DEFINE(mGlut, DisplayFunc); | |
826 | WINDOW_CALLBACK_DEFINE(mGlut, EntryFunc); | |
827 | WINDOW_CALLBACK_DEFINE(mGlut, KeyboardFunc); | |
828 | WINDOW_CALLBACK_DEFINE(mGlut, KeyboardUpFunc); | |
829 | WINDOW_CALLBACK_DEFINE(mGlut, MotionFunc); | |
830 | WINDOW_CALLBACK_DEFINE(mGlut, MouseFunc); | |
831 | WINDOW_CALLBACK_DEFINE(mGlut, OverlayDisplayFunc); | |
832 | WINDOW_CALLBACK_DEFINE(mGlut, PassiveMotionFunc); | |
833 | WINDOW_CALLBACK_DEFINE(mGlut, ReshapeFunc); | |
834 | WINDOW_CALLBACK_DEFINE(mGlut, SpaceballButtonFunc); | |
835 | WINDOW_CALLBACK_DEFINE(mGlut, SpaceballMotionFunc); | |
836 | WINDOW_CALLBACK_DEFINE(mGlut, SpaceballRotateFunc); | |
837 | WINDOW_CALLBACK_DEFINE(mGlut, SpecialFunc); | |
838 | WINDOW_CALLBACK_DEFINE(mGlut, SpecialUpFunc); | |
839 | WINDOW_CALLBACK_DEFINE(mGlut, TabletButtonFunc); | |
840 | WINDOW_CALLBACK_DEFINE(mGlut, TabletMotionFunc); | |
841 | WINDOW_CALLBACK_DEFINE(mGlut, VisibilityFunc); | |
842 | WINDOW_CALLBACK_DEFINE(mGlut, WindowStatusFunc); | |
843 | } | |
844 |
0 | /* | |
1 | * Copyright (C) 2013 Blaž Hrastnik <[email protected]> | |
2 | * | |
3 | * This program is distributed under the terms of the MIT license. | |
4 | * See the included COPYRIGHT file for the terms of this license. | |
5 | * | |
6 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
13 | * | |
14 | */ | |
15 | ||
16 | #include "common.h" | |
17 | ||
18 | /* | |
19 | * Process loop function, see freeglut_main.c | |
20 | */ | |
21 | GLUT_SIMPLE_FUNCTION(MainLoopEvent) | |
22 | GLUT_SIMPLE_FUNCTION(LeaveMainLoop) | |
23 | GLUT_SIMPLE_FUNCTION(Exit) | |
24 | ||
25 | /* | |
26 | * Window management functions, see freeglut_window.c | |
27 | */ | |
28 | GLUT_SIMPLE_FUNCTION(FullScreenToggle) | |
29 | GLUT_SIMPLE_FUNCTION(LeaveFullScreen) | |
30 | ||
31 | /* Initialization functions */ | |
32 | static VALUE | |
33 | glut_InitContextVersion(VALUE obj, VALUE majorVersion, VALUE minorVersion) | |
34 | { | |
35 | glutInitContextVersion(NUM2INT(majorVersion), NUM2INT(minorVersion)); | |
36 | return Qnil; | |
37 | } | |
38 | ||
39 | static VALUE | |
40 | glut_InitContextFlags(VALUE obj, VALUE flags) | |
41 | { | |
42 | glutInitContextFlags(NUM2INT(flags)); | |
43 | return Qnil; | |
44 | } | |
45 | ||
46 | static VALUE | |
47 | glut_InitContextProfile(VALUE obj, VALUE profile) | |
48 | { | |
49 | glutInitContextProfile(NUM2INT(profile)); | |
50 | return Qnil; | |
51 | } | |
52 | ||
53 | void Init_glut_ext() { | |
54 | VALUE mGlut = rb_path2class("Glut"); | |
55 | ||
56 | /* Process loop functions */ | |
57 | rb_define_module_function(mGlut, "glutMainLoopEvent", glut_MainLoopEvent, 0); | |
58 | rb_define_module_function(mGlut, "glutLeaveMainLoop", glut_LeaveMainLoop, 0); | |
59 | rb_define_module_function(mGlut, "glutExit", glut_Exit, 0); | |
60 | ||
61 | /* Window management functions */ | |
62 | rb_define_module_function(mGlut, "glutFullScreenToggle", glut_FullScreenToggle, 0); | |
63 | rb_define_module_function(mGlut, "glutLeaveFullScreen", glut_LeaveFullScreen, 0); | |
64 | ||
65 | /* Initialization functions */ | |
66 | rb_define_module_function(mGlut, "glutInitContextVersion", glut_InitContextVersion, 2); | |
67 | rb_define_module_function(mGlut, "glutInitContextFlags", glut_InitContextFlags, 1); | |
68 | rb_define_module_function(mGlut, "glutInitContextProfile", glut_InitContextProfile, 1); | |
69 | ||
70 | /* Context-related flags */ | |
71 | #ifdef GLUT_INIT_MAJOR_VERSION | |
72 | rb_define_const(mGlut, "GLUT_INIT_MAJOR_VERSION", INT2NUM(GLUT_INIT_MAJOR_VERSION)); | |
73 | #endif | |
74 | #ifdef GLUT_INIT_MINOR_VERSION | |
75 | rb_define_const(mGlut, "GLUT_INIT_MINOR_VERSION", INT2NUM(GLUT_INIT_MINOR_VERSION)); | |
76 | #endif | |
77 | #ifdef GLUT_INIT_FLAGS | |
78 | rb_define_const(mGlut, "GLUT_INIT_FLAGS", INT2NUM(GLUT_INIT_FLAGS)); | |
79 | #endif | |
80 | #ifdef GLUT_INIT_PROFILE | |
81 | rb_define_const(mGlut, "GLUT_INIT_PROFILE", INT2NUM(GLUT_INIT_PROFILE)); | |
82 | #endif | |
83 | ||
84 | /* Flags for glutInitContextFlags */ | |
85 | #ifdef GLUT_FORWARD_COMPATIBLE | |
86 | rb_define_const(mGlut, "GLUT_FORWARD_COMPATIBLE", INT2NUM(GLUT_FORWARD_COMPATIBLE)); | |
87 | #endif | |
88 | #ifdef GLUT_DEBUG | |
89 | rb_define_const(mGlut, "GLUT_DEBUG", INT2NUM(GLUT_DEBUG)); | |
90 | #endif | |
91 | ||
92 | /* Flags for glutInitContextProfile */ | |
93 | #ifdef GLUT_CORE_PROFILE | |
94 | rb_define_const(mGlut, "GLUT_CORE_PROFILE", INT2NUM(GLUT_CORE_PROFILE)); | |
95 | #endif | |
96 | #ifdef GLUT_COMPATIBILITY_PROFILE | |
97 | rb_define_const(mGlut, "GLUT_COMPATIBILITY_PROFILE", INT2NUM(GLUT_COMPATIBILITY_PROFILE)); | |
98 | #endif | |
99 | } |
0 | ######################################################### | |
1 | # This file has been automatically generated by gem2tgz # | |
2 | ######################################################### | |
3 | # -*- encoding: utf-8 -*- | |
4 | # stub: glut 8.3.0 ruby lib | |
5 | # stub: ext/glut/extconf.rb | |
6 | ||
7 | Gem::Specification.new do |s| | |
8 | s.name = "glut".freeze | |
9 | s.version = "8.3.0" | |
10 | ||
11 | s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= | |
12 | s.require_paths = ["lib".freeze] | |
13 | s.authors = ["Eric Hodel".freeze, "Lars Kanis".freeze, "Bla\u017E Hrastnik".freeze, "Alain Hoang".freeze, "Jan Dvorak".freeze, "Minh Thu Vo".freeze, "James Adam".freeze] | |
14 | s.date = "2017-06-02" | |
15 | s.description = "Glut bindings for OpenGL. To be used with the {opengl}[https://github.com/larskanis/opengl] gem.".freeze | |
16 | s.email = ["[email protected]".freeze, "[email protected]".freeze, "[email protected]".freeze, "".freeze, "".freeze, "".freeze, "".freeze] | |
17 | s.extensions = ["ext/glut/extconf.rb".freeze] | |
18 | s.extra_rdoc_files = ["History.rdoc".freeze, "Manifest.txt".freeze, "README.rdoc".freeze] | |
19 | s.files = [".autotest".freeze, ".gemtest".freeze, ".gitignore".freeze, ".travis.yml".freeze, "History.rdoc".freeze, "MIT-LICENSE".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "Rakefile".freeze, "ext/glut/common.h".freeze, "ext/glut/extconf.rb".freeze, "ext/glut/glut.c".freeze, "ext/glut/glut_callbacks.c".freeze, "ext/glut/glut_ext.c".freeze, "lib/glut.rb".freeze, "lib/glut/dummy.rb".freeze] | |
20 | s.licenses = ["MIT".freeze] | |
21 | s.rdoc_options = ["--main".freeze, "README.rdoc".freeze] | |
22 | s.required_ruby_version = Gem::Requirement.new(">= 1.9.2".freeze) | |
23 | s.rubygems_version = "2.7.6.2".freeze | |
24 | s.summary = "Glut bindings for OpenGL".freeze | |
25 | ||
26 | if s.respond_to? :specification_version then | |
27 | s.specification_version = 4 | |
28 | ||
29 | if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | |
30 | s.add_development_dependency(%q<hoe>.freeze, ["~> 3.16"]) | |
31 | s.add_development_dependency(%q<mini_portile2>.freeze, ["~> 2.1"]) | |
32 | s.add_development_dependency(%q<rake-compiler>.freeze, ["~> 1.0"]) | |
33 | s.add_development_dependency(%q<rake-compiler-dock>.freeze, ["~> 0.6.0"]) | |
34 | s.add_development_dependency(%q<rdoc>.freeze, ["~> 4.0"]) | |
35 | else | |
36 | s.add_dependency(%q<hoe>.freeze, ["~> 3.16"]) | |
37 | s.add_dependency(%q<mini_portile2>.freeze, ["~> 2.1"]) | |
38 | s.add_dependency(%q<rake-compiler>.freeze, ["~> 1.0"]) | |
39 | s.add_dependency(%q<rake-compiler-dock>.freeze, ["~> 0.6.0"]) | |
40 | s.add_dependency(%q<rdoc>.freeze, ["~> 4.0"]) | |
41 | end | |
42 | else | |
43 | s.add_dependency(%q<hoe>.freeze, ["~> 3.16"]) | |
44 | s.add_dependency(%q<mini_portile2>.freeze, ["~> 2.1"]) | |
45 | s.add_dependency(%q<rake-compiler>.freeze, ["~> 1.0"]) | |
46 | s.add_dependency(%q<rake-compiler-dock>.freeze, ["~> 0.6.0"]) | |
47 | s.add_dependency(%q<rdoc>.freeze, ["~> 4.0"]) | |
48 | end | |
49 | end |
0 | # Unless this file exists, rake-compiler/hoe won't create this folder | |
1 | # and the extension won't build.⏎ |
0 | begin | |
1 | RUBY_VERSION =~ /(\d+.\d+)/ | |
2 | require "glut/#{$1}/glut" | |
3 | rescue LoadError | |
4 | require 'glut/glut' | |
5 | end | |
6 | ||
7 | # (Glut.)glutInit -> GLUT.Init | |
8 | # (Glut::)GLUT_RGBA -> GLUT::RGBA | |
9 | module GLUT | |
10 | extend self | |
11 | include Glut | |
12 | ||
13 | Glut.constants.each do |cn| | |
14 | n = cn.to_s.sub(/^GLUT_/,'') | |
15 | next if n =~ /^[0-9]/ | |
16 | const_set( n, Glut.const_get( cn ) ) | |
17 | end | |
18 | ||
19 | Glut.methods( false ).each do |mn| | |
20 | n = mn.to_s.sub(/^glut/,'') | |
21 | alias_method( n, mn ) | |
22 | public( n ) | |
23 | end | |
24 | end | |
25 | ||
26 | module Glut | |
27 | VERSION = "8.3.0" | |
28 | end |