opengl 0.7.0.pre1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +8 -0
  3. data/History.txt +36 -0
  4. data/MIT-LICENSE +18 -0
  5. data/Manifest.txt +140 -0
  6. data/README.rdoc +51 -0
  7. data/Rakefile +129 -0
  8. data/Rakefile.cross +104 -0
  9. data/doc/build_install.txt +119 -0
  10. data/doc/extensions.txt.in +348 -0
  11. data/doc/history.txt +66 -0
  12. data/doc/requirements_and_design.txt +117 -0
  13. data/doc/roadmap.txt +28 -0
  14. data/doc/scientific_use.txt +35 -0
  15. data/doc/supplies/page_template.html +71 -0
  16. data/doc/thanks.txt +29 -0
  17. data/doc/tutorial.txt +469 -0
  18. data/examples/NeHe/nehe_lesson02.rb +117 -0
  19. data/examples/NeHe/nehe_lesson03.rb +122 -0
  20. data/examples/NeHe/nehe_lesson04.rb +133 -0
  21. data/examples/NeHe/nehe_lesson05.rb +186 -0
  22. data/examples/NeHe/nehe_lesson36.rb +303 -0
  23. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  24. data/examples/OrangeBook/brick.frag +36 -0
  25. data/examples/OrangeBook/brick.rb +376 -0
  26. data/examples/OrangeBook/brick.vert +41 -0
  27. data/examples/OrangeBook/particle.frag +17 -0
  28. data/examples/OrangeBook/particle.rb +406 -0
  29. data/examples/OrangeBook/particle.vert +38 -0
  30. data/examples/README +16 -0
  31. data/examples/RedBook/aapoly.rb +142 -0
  32. data/examples/RedBook/aargb.rb +119 -0
  33. data/examples/RedBook/accanti.rb +162 -0
  34. data/examples/RedBook/accpersp.rb +215 -0
  35. data/examples/RedBook/alpha.rb +123 -0
  36. data/examples/RedBook/alpha3D.rb +158 -0
  37. data/examples/RedBook/bezcurve.rb +105 -0
  38. data/examples/RedBook/bezmesh.rb +137 -0
  39. data/examples/RedBook/checker.rb +124 -0
  40. data/examples/RedBook/clip.rb +95 -0
  41. data/examples/RedBook/colormat.rb +135 -0
  42. data/examples/RedBook/cube.rb +69 -0
  43. data/examples/RedBook/depthcue.rb +99 -0
  44. data/examples/RedBook/dof.rb +205 -0
  45. data/examples/RedBook/double.rb +105 -0
  46. data/examples/RedBook/drawf.rb +91 -0
  47. data/examples/RedBook/feedback.rb +145 -0
  48. data/examples/RedBook/fog.rb +167 -0
  49. data/examples/RedBook/font.rb +151 -0
  50. data/examples/RedBook/hello.rb +79 -0
  51. data/examples/RedBook/image.rb +137 -0
  52. data/examples/RedBook/jitter.rb +207 -0
  53. data/examples/RedBook/lines.rb +128 -0
  54. data/examples/RedBook/list.rb +111 -0
  55. data/examples/RedBook/material.rb +275 -0
  56. data/examples/RedBook/mipmap.rb +156 -0
  57. data/examples/RedBook/model.rb +113 -0
  58. data/examples/RedBook/movelight.rb +132 -0
  59. data/examples/RedBook/pickdepth.rb +179 -0
  60. data/examples/RedBook/planet.rb +108 -0
  61. data/examples/RedBook/quadric.rb +158 -0
  62. data/examples/RedBook/robot.rb +115 -0
  63. data/examples/RedBook/select.rb +196 -0
  64. data/examples/RedBook/smooth.rb +95 -0
  65. data/examples/RedBook/stencil.rb +163 -0
  66. data/examples/RedBook/stroke.rb +167 -0
  67. data/examples/RedBook/surface.rb +166 -0
  68. data/examples/RedBook/teaambient.rb +132 -0
  69. data/examples/RedBook/teapots.rb +182 -0
  70. data/examples/RedBook/tess.rb +183 -0
  71. data/examples/RedBook/texbind.rb +147 -0
  72. data/examples/RedBook/texgen.rb +169 -0
  73. data/examples/RedBook/texturesurf.rb +128 -0
  74. data/examples/RedBook/varray.rb +159 -0
  75. data/examples/RedBook/wrap.rb +148 -0
  76. data/examples/misc/OGLBench.rb +337 -0
  77. data/examples/misc/anisotropic.rb +194 -0
  78. data/examples/misc/fbo_test.rb +356 -0
  79. data/examples/misc/font-glut.rb +46 -0
  80. data/examples/misc/glfwtest.rb +30 -0
  81. data/examples/misc/plane.rb +161 -0
  82. data/examples/misc/readpixel.rb +65 -0
  83. data/examples/misc/sdltest.rb +34 -0
  84. data/examples/misc/trislam.rb +828 -0
  85. data/ext/common/common.h +448 -0
  86. data/ext/common/conv.h +234 -0
  87. data/ext/common/funcdef.h +280 -0
  88. data/ext/common/gl-enums.h +10031 -0
  89. data/ext/common/gl-error.h +23 -0
  90. data/ext/common/gl-types.h +67 -0
  91. data/ext/common/glu-enums.h +463 -0
  92. data/ext/gl/extconf.rb +43 -0
  93. data/ext/gl/gl-1.0-1.1.c +2811 -0
  94. data/ext/gl/gl-1.2.c +814 -0
  95. data/ext/gl/gl-1.3.c +443 -0
  96. data/ext/gl/gl-1.4.c +348 -0
  97. data/ext/gl/gl-1.5.c +225 -0
  98. data/ext/gl/gl-2.0.c +657 -0
  99. data/ext/gl/gl-2.1.c +57 -0
  100. data/ext/gl/gl-enums.c +3354 -0
  101. data/ext/gl/gl-error.c +104 -0
  102. data/ext/gl/gl-ext-3dfx.c +27 -0
  103. data/ext/gl/gl-ext-arb.c +866 -0
  104. data/ext/gl/gl-ext-ati.c +41 -0
  105. data/ext/gl/gl-ext-ext.c +889 -0
  106. data/ext/gl/gl-ext-gremedy.c +41 -0
  107. data/ext/gl/gl-ext-nv.c +679 -0
  108. data/ext/gl/gl.c +216 -0
  109. data/ext/glu/extconf.rb +51 -0
  110. data/ext/glu/glu-enums.c +164 -0
  111. data/ext/glu/glu.c +1530 -0
  112. data/ext/glut/extconf.rb +67 -0
  113. data/ext/glut/glut.c +1624 -0
  114. data/lib/opengl.rb +89 -0
  115. data/test/README +10 -0
  116. data/test/tc_common.rb +98 -0
  117. data/test/tc_ext_arb.rb +467 -0
  118. data/test/tc_ext_ati.rb +33 -0
  119. data/test/tc_ext_ext.rb +551 -0
  120. data/test/tc_ext_gremedy.rb +36 -0
  121. data/test/tc_ext_nv.rb +357 -0
  122. data/test/tc_func_10_11.rb +1281 -0
  123. data/test/tc_func_12.rb +186 -0
  124. data/test/tc_func_13.rb +229 -0
  125. data/test/tc_func_14.rb +197 -0
  126. data/test/tc_func_15.rb +270 -0
  127. data/test/tc_func_20.rb +346 -0
  128. data/test/tc_func_21.rb +541 -0
  129. data/test/tc_glu.rb +310 -0
  130. data/test/tc_include_gl.rb +35 -0
  131. data/test/tc_misc.rb +54 -0
  132. data/test/tc_require_gl.rb +34 -0
  133. data/utils/README +11 -0
  134. data/utils/enumgen.rb +112 -0
  135. data/utils/extlistgen.rb +90 -0
  136. data/utils/mkdn2html.rb +59 -0
  137. data/utils/post-mkdn2html.rb +91 -0
  138. data/website/images/ogl.jpg +0 -0
  139. data/website/images/tab_bottom.gif +0 -0
  140. data/website/style.css +198 -0
  141. metadata +274 -0
data/ext/gl/gl.c ADDED
@@ -0,0 +1,216 @@
1
+ /*
2
+ * Copyright (C) 1999 - 2005 Yoshi <yoshi@giganet.net>
3
+ * Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
4
+ * Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
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
+
18
+ #include "../common/common.h"
19
+
20
+ static const char *VERSION = "0.7.0.pre1";
21
+
22
+ static VALUE module;
23
+
24
+ void gl_init_enums(VALUE);
25
+ void gl_init_functions_1_0__1_1(VALUE);
26
+ void gl_init_functions_1_2(VALUE);
27
+ void gl_init_functions_1_3(VALUE);
28
+ void gl_init_functions_1_4(VALUE);
29
+ void gl_init_functions_1_5(VALUE);
30
+ void gl_init_functions_2_0(VALUE);
31
+ void gl_init_functions_2_1(VALUE);
32
+ void gl_init_functions_ext_3dfx(VALUE);
33
+ void gl_init_functions_ext_arb(VALUE);
34
+ void gl_init_functions_ext_ati(VALUE);
35
+ void gl_init_functions_ext_ext(VALUE);
36
+ void gl_init_functions_ext_gremedy(VALUE);
37
+ void gl_init_functions_ext_nv(VALUE);
38
+
39
+
40
+ static int opengl_version[2]; /* major, minor */
41
+ static char *opengl_extensions = NULL;
42
+
43
+ /* Returns current OpenGL version as major, minor or 0,0 if
44
+ * unknown (context not yet initialised etc.) The version is
45
+ * cached for subsequent calls.
46
+ */
47
+ const int *GetOpenglVersion(void)
48
+ {
49
+ if (opengl_version[0]==0) { /* not cached, query */
50
+ const char *vstr = (const char *) glGetString(GL_VERSION);
51
+ CHECK_GLERROR
52
+ if (vstr)
53
+ sscanf( vstr, "%d.%d", &opengl_version[0], &opengl_version[1] );
54
+ }
55
+ return opengl_version;
56
+ }
57
+
58
+ /* Checks if OpenGL version is at least the same or higher than
59
+ * major.minor
60
+ */
61
+ GLboolean CheckOpenglVersion(int major, int minor)
62
+ {
63
+ const int *version;
64
+
65
+ version = GetOpenglVersion();
66
+
67
+ if (version[0]>major || (version[0]==major && version[1] >=minor))
68
+ return GL_TRUE;
69
+ else
70
+ return GL_FALSE;
71
+ }
72
+
73
+ /* Returns supported OpenGL extensions as char* or NULL
74
+ * if unknown (context not yet initialised etc.) The list is
75
+ * cached for subsequent calls.
76
+ */
77
+ const char *GetOpenglExtensions(void)
78
+ {
79
+ if (opengl_extensions == NULL) {
80
+ const char *estr = (const char *) glGetString(GL_EXTENSIONS);
81
+ CHECK_GLERROR
82
+ if (estr) {
83
+ long len = strlen(estr);
84
+ opengl_extensions = ALLOC_N(GLchar,len+1+1); /* terminating null and added space */
85
+ strcpy(opengl_extensions,estr);
86
+ opengl_extensions[len] = ' '; /* add space char for easy searchs */
87
+ opengl_extensions[len+1] = '\0';
88
+ }
89
+ }
90
+ return opengl_extensions;
91
+ }
92
+
93
+ /* Checks if extension is supported by the current OpenGL implementation
94
+ */
95
+ GLboolean CheckExtension(const char *name)
96
+ {
97
+ const char *extensions;
98
+ char *name_tmp;
99
+ long name_len;
100
+ GLboolean res;
101
+
102
+ extensions = GetOpenglExtensions();
103
+
104
+ if(extensions==NULL)
105
+ return GL_FALSE;
106
+
107
+ /* add trailing space */
108
+ name_len = strlen(name);
109
+ name_tmp = ALLOC_N(GLchar,name_len+1+1); /* terminating null and added space */
110
+ strcpy(name_tmp,name);
111
+ name_tmp[name_len] = ' '; /* add space char for search */
112
+ name_tmp[name_len+1] = '\0';
113
+
114
+ if (strstr(extensions,name_tmp))
115
+ res = GL_TRUE;
116
+ else
117
+ res = GL_FALSE;
118
+
119
+ xfree(name_tmp);
120
+ return res;
121
+ }
122
+
123
+ /* wrapper for CheckOpenglVersion and CheckExtension, also used by macros
124
+ */
125
+ GLboolean CheckVersionExtension(const char *name)
126
+ {
127
+ if (name && name[0] && name[0]>='0' && name[0]<='9') { /* GL version query */
128
+ int major,minor;
129
+
130
+ if (sscanf( name, "%d.%d", &major, &minor ) != 2)
131
+ return GL_FALSE;
132
+
133
+ return (CheckOpenglVersion(major,minor));
134
+ } else {
135
+ return (CheckExtension(name));
136
+ }
137
+ }
138
+
139
+ /* Checks if given OpenGL version or extension is available
140
+ */
141
+ static VALUE
142
+ IsAvailable(obj,arg1)
143
+ VALUE obj,arg1;
144
+ {
145
+ char *name = NULL;
146
+ VALUE s;
147
+ GLboolean res;
148
+
149
+ s = rb_funcall(arg1, rb_intern("to_s"),0);
150
+ name = RSTRING_PTR(s);
151
+
152
+ res = CheckVersionExtension(name);
153
+
154
+ return GLBOOL2RUBY(res);
155
+ }
156
+
157
+ /* Checks whether non-zero buffer of type $buffer is bound
158
+ * - this affects several functions that pass data from/to OpenGL.
159
+ */
160
+ GLint CheckBufferBinding(GLint buffer)
161
+ {
162
+ GLint result = 0;
163
+
164
+ /* check if the buffer functionality is supported */
165
+ switch(buffer) {
166
+ case GL_ARRAY_BUFFER_BINDING:
167
+ case GL_ELEMENT_ARRAY_BUFFER_BINDING:
168
+ if (!CheckOpenglVersion(1,5))
169
+ return 0;
170
+ break;
171
+ case GL_PIXEL_PACK_BUFFER_BINDING:
172
+ case GL_PIXEL_UNPACK_BUFFER_BINDING:
173
+ if (!CheckOpenglVersion(2,1))
174
+ return 0;
175
+ break;
176
+ default:
177
+ rb_raise(rb_eRuntimeError,"Internal Error: buffer type '%i' does not exist", buffer);
178
+ break;
179
+ }
180
+ glGetIntegerv(buffer,&result);
181
+ CHECK_GLERROR
182
+ return result;
183
+ }
184
+
185
+ DLLEXPORT void Init_gl()
186
+ {
187
+ VALUE vVERSION = rb_str_new2(VERSION);
188
+
189
+ module = rb_define_module("Gl");
190
+
191
+ rb_define_const(module, "BINDINGS_VERSION", vVERSION);
192
+ rb_define_const(module, "RUBY_OPENGL_VERSION", vVERSION);
193
+
194
+ gl_init_error(module);
195
+ gl_init_enums(module);
196
+ gl_init_functions_1_0__1_1(module);
197
+ gl_init_functions_1_2(module);
198
+ gl_init_functions_1_3(module);
199
+ gl_init_functions_1_4(module);
200
+ gl_init_functions_1_5(module);
201
+ gl_init_functions_2_0(module);
202
+ gl_init_functions_2_1(module);
203
+ gl_init_functions_ext_3dfx(module);
204
+ gl_init_functions_ext_arb(module);
205
+ gl_init_functions_ext_ati(module);
206
+ gl_init_functions_ext_ext(module);
207
+ gl_init_functions_ext_gremedy(module);
208
+ gl_init_functions_ext_nv(module);
209
+
210
+ rb_define_module_function(module, "is_available?", IsAvailable, 1);
211
+ rb_define_module_function(module, "is_supported?", IsAvailable, 1);
212
+ rb_define_module_function(module, "extension_available?", IsAvailable, 1);
213
+ rb_define_module_function(module, "extension_supported?", IsAvailable, 1);
214
+ rb_define_module_function(module, "version_available?", IsAvailable, 1);
215
+ rb_define_module_function(module, "version_supported?", IsAvailable, 1);
216
+ }
@@ -0,0 +1,51 @@
1
+ require 'mkmf'
2
+
3
+ def have_framework(fw, &b)
4
+ checking_for fw do
5
+ src = cpp_include("#{fw}/#{fw}.h") << "\n" "int main(void){return 0;}"
6
+ if try_link(src, opt = "-ObjC -framework #{fw}", &b)
7
+ $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp))
8
+ $LDFLAGS << " " << opt
9
+ true
10
+ else
11
+ false
12
+ end
13
+ end
14
+ end unless respond_to? :have_framework
15
+
16
+ ok =
17
+ (have_library('opengl32.lib') &&
18
+ have_library('glu32.lib')) ||
19
+ (have_library('opengl32') &&
20
+ have_library('glu32')) ||
21
+ (have_library('GL', 'glVertex3d') &&
22
+ have_library('GLU', 'gluLookAt')) ||
23
+ have_framework('OpenGL')
24
+
25
+ ok &&=
26
+ have_header('GL/gl.h') ||
27
+ have_header('OpenGL/gl.h') # OS X
28
+
29
+ ok &&=
30
+ have_header('GL/glu.h') ||
31
+ have_header('OpenGL/glu.h') # OS X
32
+
33
+ have_header 'GL/glx.h' # *NIX only?
34
+ have_header 'dlfcn.h' # OS X dynamic loader
35
+ have_header 'windows.h'
36
+
37
+ have_header 'stdint.h'
38
+ have_header 'inttypes.h'
39
+
40
+ have_func 'wglGetProcAddress', 'wingdi.h' # Windows extension loader
41
+
42
+ have_struct_member 'struct RFloat', 'float_value'
43
+
44
+ have_type 'int64_t', 'stdint.h'
45
+ have_type 'uint64_t', 'stdint.h'
46
+
47
+ if ok then
48
+ create_header
49
+ create_makefile 'glu'
50
+ end
51
+
@@ -0,0 +1,164 @@
1
+ /* This file was genereated on Mon Feb 16 18:08:57 +0100 2009
2
+ source: http://oss.sgi.com/cgi-bin/cvsweb.cgi/~checkout~/projects/ogl-sample/main/doc/registry/specs/enumglu.spec
3
+ */
4
+
5
+ #include "../common/common.h"
6
+ void glu_init_enums(VALUE module)
7
+ {
8
+ rb_define_const(module, "GLU_TRUE", Qtrue);
9
+ rb_define_const(module, "GLU_FALSE", Qfalse);
10
+
11
+ rb_define_const(module, "GLU_AUTO_LOAD_MATRIX", INT2NUM(GLU_AUTO_LOAD_MATRIX));
12
+ rb_define_const(module, "GLU_BEGIN", INT2NUM(GLU_BEGIN));
13
+ rb_define_const(module, "GLU_CCW", INT2NUM(GLU_CCW));
14
+ rb_define_const(module, "GLU_CULLING", INT2NUM(GLU_CULLING));
15
+ rb_define_const(module, "GLU_CW", INT2NUM(GLU_CW));
16
+ rb_define_const(module, "GLU_DISPLAY_MODE", INT2NUM(GLU_DISPLAY_MODE));
17
+ rb_define_const(module, "GLU_DOMAIN_DISTANCE", INT2NUM(GLU_DOMAIN_DISTANCE));
18
+ rb_define_const(module, "GLU_EDGE_FLAG", INT2NUM(GLU_EDGE_FLAG));
19
+ rb_define_const(module, "GLU_END", INT2NUM(GLU_END));
20
+ rb_define_const(module, "GLU_ERROR", INT2NUM(GLU_ERROR));
21
+ rb_define_const(module, "GLU_EXTENSIONS", INT2NUM(GLU_EXTENSIONS));
22
+ rb_define_const(module, "GLU_EXTERIOR", INT2NUM(GLU_EXTERIOR));
23
+ rb_define_const(module, "GLU_EXT_nurbs_tessellator", INT2NUM(GLU_EXT_nurbs_tessellator));
24
+ rb_define_const(module, "GLU_EXT_object_space_tess", INT2NUM(GLU_EXT_object_space_tess));
25
+ rb_define_const(module, "GLU_FILL", INT2NUM(GLU_FILL));
26
+ rb_define_const(module, "GLU_FLAT", INT2NUM(GLU_FLAT));
27
+ rb_define_const(module, "GLU_INSIDE", INT2NUM(GLU_INSIDE));
28
+ rb_define_const(module, "GLU_INTERIOR", INT2NUM(GLU_INTERIOR));
29
+ rb_define_const(module, "GLU_INVALID_ENUM", INT2NUM(GLU_INVALID_ENUM));
30
+ rb_define_const(module, "GLU_INVALID_OPERATION", INT2NUM(GLU_INVALID_OPERATION));
31
+ rb_define_const(module, "GLU_INVALID_VALUE", INT2NUM(GLU_INVALID_VALUE));
32
+ rb_define_const(module, "GLU_LAGRANGIAN_SGI", INT2NUM(GLU_LAGRANGIAN_SGI));
33
+ rb_define_const(module, "GLU_LINE", INT2NUM(GLU_LINE));
34
+ rb_define_const(module, "GLU_MAP1_TRIM_2", INT2NUM(GLU_MAP1_TRIM_2));
35
+ rb_define_const(module, "GLU_MAP1_TRIM_3", INT2NUM(GLU_MAP1_TRIM_3));
36
+ rb_define_const(module, "GLU_MITCHELL_NETRAVALI_SGI", INT2NUM(GLU_MITCHELL_NETRAVALI_SGI));
37
+ rb_define_const(module, "GLU_NONE", INT2NUM(GLU_NONE));
38
+ rb_define_const(module, "GLU_NURBS_BEGIN", INT2NUM(GLU_NURBS_BEGIN));
39
+ rb_define_const(module, "GLU_NURBS_BEGIN_DATA", INT2NUM(GLU_NURBS_BEGIN_DATA));
40
+ rb_define_const(module, "GLU_NURBS_BEGIN_DATA_EXT", INT2NUM(GLU_NURBS_BEGIN_DATA_EXT));
41
+ rb_define_const(module, "GLU_NURBS_BEGIN_EXT", INT2NUM(GLU_NURBS_BEGIN_EXT));
42
+ rb_define_const(module, "GLU_NURBS_COLOR", INT2NUM(GLU_NURBS_COLOR));
43
+ rb_define_const(module, "GLU_NURBS_COLOR_DATA", INT2NUM(GLU_NURBS_COLOR_DATA));
44
+ rb_define_const(module, "GLU_NURBS_COLOR_DATA_EXT", INT2NUM(GLU_NURBS_COLOR_DATA_EXT));
45
+ rb_define_const(module, "GLU_NURBS_COLOR_EXT", INT2NUM(GLU_NURBS_COLOR_EXT));
46
+ rb_define_const(module, "GLU_NURBS_END", INT2NUM(GLU_NURBS_END));
47
+ rb_define_const(module, "GLU_NURBS_END_DATA", INT2NUM(GLU_NURBS_END_DATA));
48
+ rb_define_const(module, "GLU_NURBS_END_DATA_EXT", INT2NUM(GLU_NURBS_END_DATA_EXT));
49
+ rb_define_const(module, "GLU_NURBS_END_EXT", INT2NUM(GLU_NURBS_END_EXT));
50
+ rb_define_const(module, "GLU_NURBS_ERROR", INT2NUM(GLU_NURBS_ERROR));
51
+ rb_define_const(module, "GLU_NURBS_ERROR1", INT2NUM(GLU_NURBS_ERROR1));
52
+ rb_define_const(module, "GLU_NURBS_ERROR10", INT2NUM(GLU_NURBS_ERROR10));
53
+ rb_define_const(module, "GLU_NURBS_ERROR11", INT2NUM(GLU_NURBS_ERROR11));
54
+ rb_define_const(module, "GLU_NURBS_ERROR12", INT2NUM(GLU_NURBS_ERROR12));
55
+ rb_define_const(module, "GLU_NURBS_ERROR13", INT2NUM(GLU_NURBS_ERROR13));
56
+ rb_define_const(module, "GLU_NURBS_ERROR14", INT2NUM(GLU_NURBS_ERROR14));
57
+ rb_define_const(module, "GLU_NURBS_ERROR15", INT2NUM(GLU_NURBS_ERROR15));
58
+ rb_define_const(module, "GLU_NURBS_ERROR16", INT2NUM(GLU_NURBS_ERROR16));
59
+ rb_define_const(module, "GLU_NURBS_ERROR17", INT2NUM(GLU_NURBS_ERROR17));
60
+ rb_define_const(module, "GLU_NURBS_ERROR18", INT2NUM(GLU_NURBS_ERROR18));
61
+ rb_define_const(module, "GLU_NURBS_ERROR19", INT2NUM(GLU_NURBS_ERROR19));
62
+ rb_define_const(module, "GLU_NURBS_ERROR2", INT2NUM(GLU_NURBS_ERROR2));
63
+ rb_define_const(module, "GLU_NURBS_ERROR20", INT2NUM(GLU_NURBS_ERROR20));
64
+ rb_define_const(module, "GLU_NURBS_ERROR21", INT2NUM(GLU_NURBS_ERROR21));
65
+ rb_define_const(module, "GLU_NURBS_ERROR22", INT2NUM(GLU_NURBS_ERROR22));
66
+ rb_define_const(module, "GLU_NURBS_ERROR23", INT2NUM(GLU_NURBS_ERROR23));
67
+ rb_define_const(module, "GLU_NURBS_ERROR24", INT2NUM(GLU_NURBS_ERROR24));
68
+ rb_define_const(module, "GLU_NURBS_ERROR25", INT2NUM(GLU_NURBS_ERROR25));
69
+ rb_define_const(module, "GLU_NURBS_ERROR26", INT2NUM(GLU_NURBS_ERROR26));
70
+ rb_define_const(module, "GLU_NURBS_ERROR27", INT2NUM(GLU_NURBS_ERROR27));
71
+ rb_define_const(module, "GLU_NURBS_ERROR28", INT2NUM(GLU_NURBS_ERROR28));
72
+ rb_define_const(module, "GLU_NURBS_ERROR29", INT2NUM(GLU_NURBS_ERROR29));
73
+ rb_define_const(module, "GLU_NURBS_ERROR3", INT2NUM(GLU_NURBS_ERROR3));
74
+ rb_define_const(module, "GLU_NURBS_ERROR30", INT2NUM(GLU_NURBS_ERROR30));
75
+ rb_define_const(module, "GLU_NURBS_ERROR31", INT2NUM(GLU_NURBS_ERROR31));
76
+ rb_define_const(module, "GLU_NURBS_ERROR32", INT2NUM(GLU_NURBS_ERROR32));
77
+ rb_define_const(module, "GLU_NURBS_ERROR33", INT2NUM(GLU_NURBS_ERROR33));
78
+ rb_define_const(module, "GLU_NURBS_ERROR34", INT2NUM(GLU_NURBS_ERROR34));
79
+ rb_define_const(module, "GLU_NURBS_ERROR35", INT2NUM(GLU_NURBS_ERROR35));
80
+ rb_define_const(module, "GLU_NURBS_ERROR36", INT2NUM(GLU_NURBS_ERROR36));
81
+ rb_define_const(module, "GLU_NURBS_ERROR37", INT2NUM(GLU_NURBS_ERROR37));
82
+ rb_define_const(module, "GLU_NURBS_ERROR4", INT2NUM(GLU_NURBS_ERROR4));
83
+ rb_define_const(module, "GLU_NURBS_ERROR5", INT2NUM(GLU_NURBS_ERROR5));
84
+ rb_define_const(module, "GLU_NURBS_ERROR6", INT2NUM(GLU_NURBS_ERROR6));
85
+ rb_define_const(module, "GLU_NURBS_ERROR7", INT2NUM(GLU_NURBS_ERROR7));
86
+ rb_define_const(module, "GLU_NURBS_ERROR8", INT2NUM(GLU_NURBS_ERROR8));
87
+ rb_define_const(module, "GLU_NURBS_ERROR9", INT2NUM(GLU_NURBS_ERROR9));
88
+ rb_define_const(module, "GLU_NURBS_MODE", INT2NUM(GLU_NURBS_MODE));
89
+ rb_define_const(module, "GLU_NURBS_MODE_EXT", INT2NUM(GLU_NURBS_MODE_EXT));
90
+ rb_define_const(module, "GLU_NURBS_NORMAL", INT2NUM(GLU_NURBS_NORMAL));
91
+ rb_define_const(module, "GLU_NURBS_NORMAL_DATA", INT2NUM(GLU_NURBS_NORMAL_DATA));
92
+ rb_define_const(module, "GLU_NURBS_NORMAL_DATA_EXT", INT2NUM(GLU_NURBS_NORMAL_DATA_EXT));
93
+ rb_define_const(module, "GLU_NURBS_NORMAL_EXT", INT2NUM(GLU_NURBS_NORMAL_EXT));
94
+ rb_define_const(module, "GLU_NURBS_RENDERER", INT2NUM(GLU_NURBS_RENDERER));
95
+ rb_define_const(module, "GLU_NURBS_RENDERER_EXT", INT2NUM(GLU_NURBS_RENDERER_EXT));
96
+ rb_define_const(module, "GLU_NURBS_TESSELLATOR", INT2NUM(GLU_NURBS_TESSELLATOR));
97
+ rb_define_const(module, "GLU_NURBS_TESSELLATOR_EXT", INT2NUM(GLU_NURBS_TESSELLATOR_EXT));
98
+ rb_define_const(module, "GLU_NURBS_TEXTURE_COORD", INT2NUM(GLU_NURBS_TEXTURE_COORD));
99
+ rb_define_const(module, "GLU_NURBS_TEXTURE_COORD_DATA", INT2NUM(GLU_NURBS_TEXTURE_COORD_DATA));
100
+ rb_define_const(module, "GLU_NURBS_TEXTURE_COORD_DATA_EXT", INT2NUM(GLU_NURBS_TEXTURE_COORD_DATA_EXT));
101
+ rb_define_const(module, "GLU_NURBS_TEXTURE_COORD_EXT", INT2NUM(GLU_NURBS_TEXTURE_COORD_EXT));
102
+ rb_define_const(module, "GLU_NURBS_VERTEX", INT2NUM(GLU_NURBS_VERTEX));
103
+ rb_define_const(module, "GLU_NURBS_VERTEX_DATA", INT2NUM(GLU_NURBS_VERTEX_DATA));
104
+ rb_define_const(module, "GLU_NURBS_VERTEX_DATA_EXT", INT2NUM(GLU_NURBS_VERTEX_DATA_EXT));
105
+ rb_define_const(module, "GLU_NURBS_VERTEX_EXT", INT2NUM(GLU_NURBS_VERTEX_EXT));
106
+ rb_define_const(module, "GLU_OBJECT_PARAMETRIC_ERROR", INT2NUM(GLU_OBJECT_PARAMETRIC_ERROR));
107
+ rb_define_const(module, "GLU_OBJECT_PARAMETRIC_ERROR_EXT", INT2NUM(GLU_OBJECT_PARAMETRIC_ERROR_EXT));
108
+ rb_define_const(module, "GLU_OBJECT_PATH_LENGTH", INT2NUM(GLU_OBJECT_PATH_LENGTH));
109
+ rb_define_const(module, "GLU_OBJECT_PATH_LENGTH_EXT", INT2NUM(GLU_OBJECT_PATH_LENGTH_EXT));
110
+ rb_define_const(module, "GLU_OUTLINE_PATCH", INT2NUM(GLU_OUTLINE_PATCH));
111
+ rb_define_const(module, "GLU_OUTLINE_POLYGON", INT2NUM(GLU_OUTLINE_POLYGON));
112
+ rb_define_const(module, "GLU_OUTSIDE", INT2NUM(GLU_OUTSIDE));
113
+ rb_define_const(module, "GLU_OUT_OF_MEMORY", INT2NUM(GLU_OUT_OF_MEMORY));
114
+ rb_define_const(module, "GLU_PARAMETRIC_ERROR", INT2NUM(GLU_PARAMETRIC_ERROR));
115
+ rb_define_const(module, "GLU_PARAMETRIC_TOLERANCE", INT2NUM(GLU_PARAMETRIC_TOLERANCE));
116
+ rb_define_const(module, "GLU_PATH_LENGTH", INT2NUM(GLU_PATH_LENGTH));
117
+ rb_define_const(module, "GLU_POINT", INT2NUM(GLU_POINT));
118
+ rb_define_const(module, "GLU_SAMPLING_METHOD", INT2NUM(GLU_SAMPLING_METHOD));
119
+ rb_define_const(module, "GLU_SAMPLING_TOLERANCE", INT2NUM(GLU_SAMPLING_TOLERANCE));
120
+ rb_define_const(module, "GLU_SILHOUETTE", INT2NUM(GLU_SILHOUETTE));
121
+ rb_define_const(module, "GLU_SMOOTH", INT2NUM(GLU_SMOOTH));
122
+ rb_define_const(module, "GLU_TESS_BEGIN", INT2NUM(GLU_TESS_BEGIN));
123
+ rb_define_const(module, "GLU_TESS_BEGIN_DATA", INT2NUM(GLU_TESS_BEGIN_DATA));
124
+ rb_define_const(module, "GLU_TESS_BOUNDARY_ONLY", INT2NUM(GLU_TESS_BOUNDARY_ONLY));
125
+ rb_define_const(module, "GLU_TESS_COMBINE", INT2NUM(GLU_TESS_COMBINE));
126
+ rb_define_const(module, "GLU_TESS_COMBINE_DATA", INT2NUM(GLU_TESS_COMBINE_DATA));
127
+ rb_define_const(module, "GLU_TESS_COORD_TOO_LARGE", INT2NUM(GLU_TESS_COORD_TOO_LARGE));
128
+ rb_define_const(module, "GLU_TESS_EDGE_FLAG", INT2NUM(GLU_TESS_EDGE_FLAG));
129
+ rb_define_const(module, "GLU_TESS_EDGE_FLAG_DATA", INT2NUM(GLU_TESS_EDGE_FLAG_DATA));
130
+ rb_define_const(module, "GLU_TESS_END", INT2NUM(GLU_TESS_END));
131
+ rb_define_const(module, "GLU_TESS_END_DATA", INT2NUM(GLU_TESS_END_DATA));
132
+ rb_define_const(module, "GLU_TESS_ERROR", INT2NUM(GLU_TESS_ERROR));
133
+ rb_define_const(module, "GLU_TESS_ERROR1", INT2NUM(GLU_TESS_ERROR1));
134
+ rb_define_const(module, "GLU_TESS_ERROR2", INT2NUM(GLU_TESS_ERROR2));
135
+ rb_define_const(module, "GLU_TESS_ERROR3", INT2NUM(GLU_TESS_ERROR3));
136
+ rb_define_const(module, "GLU_TESS_ERROR4", INT2NUM(GLU_TESS_ERROR4));
137
+ rb_define_const(module, "GLU_TESS_ERROR5", INT2NUM(GLU_TESS_ERROR5));
138
+ rb_define_const(module, "GLU_TESS_ERROR6", INT2NUM(GLU_TESS_ERROR6));
139
+ rb_define_const(module, "GLU_TESS_ERROR7", INT2NUM(GLU_TESS_ERROR7));
140
+ rb_define_const(module, "GLU_TESS_ERROR8", INT2NUM(GLU_TESS_ERROR8));
141
+ rb_define_const(module, "GLU_TESS_ERROR_DATA", INT2NUM(GLU_TESS_ERROR_DATA));
142
+ rb_define_const(module, "GLU_TESS_MISSING_BEGIN_CONTOUR", INT2NUM(GLU_TESS_MISSING_BEGIN_CONTOUR));
143
+ rb_define_const(module, "GLU_TESS_MISSING_BEGIN_POLYGON", INT2NUM(GLU_TESS_MISSING_BEGIN_POLYGON));
144
+ rb_define_const(module, "GLU_TESS_MISSING_END_CONTOUR", INT2NUM(GLU_TESS_MISSING_END_CONTOUR));
145
+ rb_define_const(module, "GLU_TESS_MISSING_END_POLYGON", INT2NUM(GLU_TESS_MISSING_END_POLYGON));
146
+ rb_define_const(module, "GLU_TESS_NEED_COMBINE_CALLBACK", INT2NUM(GLU_TESS_NEED_COMBINE_CALLBACK));
147
+ rb_define_const(module, "GLU_TESS_TOLERANCE", INT2NUM(GLU_TESS_TOLERANCE));
148
+ rb_define_const(module, "GLU_TESS_VERTEX", INT2NUM(GLU_TESS_VERTEX));
149
+ rb_define_const(module, "GLU_TESS_VERTEX_DATA", INT2NUM(GLU_TESS_VERTEX_DATA));
150
+ rb_define_const(module, "GLU_TESS_WINDING_ABS_GEQ_TWO", INT2NUM(GLU_TESS_WINDING_ABS_GEQ_TWO));
151
+ rb_define_const(module, "GLU_TESS_WINDING_NEGATIVE", INT2NUM(GLU_TESS_WINDING_NEGATIVE));
152
+ rb_define_const(module, "GLU_TESS_WINDING_NONZERO", INT2NUM(GLU_TESS_WINDING_NONZERO));
153
+ rb_define_const(module, "GLU_TESS_WINDING_ODD", INT2NUM(GLU_TESS_WINDING_ODD));
154
+ rb_define_const(module, "GLU_TESS_WINDING_POSITIVE", INT2NUM(GLU_TESS_WINDING_POSITIVE));
155
+ rb_define_const(module, "GLU_TESS_WINDING_RULE", INT2NUM(GLU_TESS_WINDING_RULE));
156
+ rb_define_const(module, "GLU_UNKNOWN", INT2NUM(GLU_UNKNOWN));
157
+ rb_define_const(module, "GLU_U_STEP", INT2NUM(GLU_U_STEP));
158
+ rb_define_const(module, "GLU_VERSION", INT2NUM(GLU_VERSION));
159
+ rb_define_const(module, "GLU_VERSION_1_1", INT2NUM(GLU_VERSION_1_1));
160
+ rb_define_const(module, "GLU_VERSION_1_2", INT2NUM(GLU_VERSION_1_2));
161
+ rb_define_const(module, "GLU_VERSION_1_3", INT2NUM(GLU_VERSION_1_3));
162
+ rb_define_const(module, "GLU_VERTEX", INT2NUM(GLU_VERTEX));
163
+ rb_define_const(module, "GLU_V_STEP", INT2NUM(GLU_V_STEP));
164
+ }
data/ext/glu/glu.c ADDED
@@ -0,0 +1,1530 @@
1
+ /*
2
+ * Last edit by previous maintainer:
3
+ * 2003/10/25 15:25:05, yoshi
4
+ *
5
+ * Copyright (C) 1999 - 2005 Yoshi <yoshi@giganet.net>
6
+ * Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
7
+ *
8
+ * This program is distributed under the terms of the MIT license.
9
+ * See the included COPYRIGHT file for the terms of this license.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
15
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+ */
19
+
20
+ #include "../common/common.h"
21
+
22
+ static VALUE module;
23
+
24
+ VALUE Class_GLUError;
25
+
26
+ void glu_init_enums(VALUE);
27
+
28
+ typedef GLUtesselator tesselatorObj;
29
+
30
+ /* pointers passed to gluNurbsCurve/Surface etc.,
31
+ - some implementations (Mesa) needs these to be valid
32
+ at EndCurve/Surface etc. call., so we store them here
33
+ and free them after that call */
34
+
35
+ struct glu_MesaStack {
36
+ int len;
37
+ GLfloat **ptr;
38
+ };
39
+
40
+ static struct glu_MesaStack gms = {0, NULL};
41
+
42
+ struct nurbsdata {
43
+ GLUnurbsObj *nobj;
44
+ VALUE n_ref;
45
+ };
46
+ struct tessdata {
47
+ tesselatorObj *tobj;
48
+ VALUE t_ref;
49
+ };
50
+
51
+ struct quaddata {
52
+ GLUquadricObj *qobj;
53
+ VALUE q_ref;
54
+ };
55
+
56
+ static VALUE cNurbs;
57
+ static VALUE cTess;
58
+ static VALUE cQuad;
59
+
60
+ #define REF_LAST 15
61
+
62
+ #define GetNURBS(obj, ndata) {\
63
+ Data_Get_Struct(obj, struct nurbsdata, ndata);\
64
+ if (ndata->nobj == NULL) rb_raise(rb_eRuntimeError, "Nurbs Object already deleted!");\
65
+ }
66
+
67
+ #define GetTESS(obj, tdata) {\
68
+ Data_Get_Struct(obj, struct tessdata, tdata);\
69
+ if (tdata->tobj == NULL) rb_raise(rb_eRuntimeError, "Triangulator Object already deleted!");\
70
+ }
71
+
72
+ #define GetQUAD(obj, qdata) {\
73
+ Data_Get_Struct(obj, struct quaddata, qdata);\
74
+ if (qdata->qobj == NULL) rb_raise(rb_eRuntimeError, "Quadric Object already deleted!");\
75
+ }
76
+
77
+ static ID callId;
78
+ static ID refId;
79
+
80
+ /*
81
+ * GLU Implementation
82
+ */
83
+
84
+ /*
85
+ * Nurbs
86
+ */
87
+ /* from nurbscrv.c */
88
+ static int
89
+ get_curve_dim(type)
90
+ GLenum type;
91
+ {
92
+ switch(type)
93
+ {
94
+ case GL_MAP1_VERTEX_3: return 3;
95
+ case GL_MAP1_VERTEX_4: return 4;
96
+ case GL_MAP1_INDEX: return 1;
97
+ case GL_MAP1_COLOR_4: return 4;
98
+ case GL_MAP1_NORMAL: return 3;
99
+ case GL_MAP1_TEXTURE_COORD_1: return 1;
100
+ case GL_MAP1_TEXTURE_COORD_2: return 2;
101
+ case GL_MAP1_TEXTURE_COORD_3: return 3;
102
+ case GL_MAP1_TEXTURE_COORD_4: return 4;
103
+ default:
104
+ rb_raise(rb_eArgError,"Unknown curve type '%i'",type);
105
+ }
106
+ return 0; /* never gets here */
107
+ }
108
+ /* from nurbssrf.c */
109
+ static int
110
+ get_surface_dim(GLenum type)
111
+ {
112
+ switch(type)
113
+ {
114
+ case GL_MAP2_VERTEX_3: return 3;
115
+ case GL_MAP2_VERTEX_4: return 4;
116
+ case GL_MAP2_INDEX: return 1;
117
+ case GL_MAP2_COLOR_4: return 4;
118
+ case GL_MAP2_NORMAL: return 3;
119
+ case GL_MAP2_TEXTURE_COORD_1: return 1;
120
+ case GL_MAP2_TEXTURE_COORD_2: return 2;
121
+ case GL_MAP2_TEXTURE_COORD_3: return 3;
122
+ case GL_MAP2_TEXTURE_COORD_4: return 4;
123
+ default:
124
+ rb_raise(rb_eArgError,"Unknown surface type '%i'",type);
125
+ }
126
+ return 0; /* never gets here */
127
+ }
128
+
129
+ VALUE GLUError_initialize(VALUE obj,VALUE message, VALUE error_id)
130
+ {
131
+ rb_call_super(1, &message);
132
+ rb_iv_set(obj, "@id", error_id);
133
+
134
+ return obj;
135
+ }
136
+
137
+ void check_for_gluerror(GLenum error)
138
+ {
139
+ const char *error_string;
140
+ VALUE exc;
141
+
142
+ /* no error */
143
+ if (error==0)
144
+ return;
145
+
146
+ switch(error) {
147
+ case GLU_INVALID_ENUM: error_string = "invalid enumerant"; break;
148
+ case GLU_INVALID_VALUE: error_string = "invalid value"; break;
149
+ case GLU_INVALID_OPERATION: error_string = "invalid operation"; break;
150
+ case GLU_OUT_OF_MEMORY: error_string = "out of memory"; break;
151
+ default: error_string = "unknown error"; break;
152
+ }
153
+
154
+ exc = rb_funcall(Class_GLUError, rb_intern("new"), 2, rb_str_new2(error_string), RETCONV_GLenum(error));
155
+ rb_funcall(rb_cObject, rb_intern("raise"), 1, exc);
156
+ }
157
+
158
+ /*
159
+ * NURBS API
160
+ */
161
+ static VALUE n_current;
162
+
163
+ static void
164
+ free_nurbs(ndata)
165
+ struct nurbsdata *ndata;
166
+ {
167
+ if (ndata->nobj) gluDeleteNurbsRenderer(ndata->nobj);
168
+ ndata->nobj = NULL;
169
+ ndata->n_ref = Qnil;
170
+ }
171
+ static void
172
+ mark_nurbs(ndata)
173
+ struct nurbsdata* ndata;
174
+ {
175
+ if (ndata->nobj)
176
+ rb_gc_mark(ndata->n_ref);
177
+ }
178
+
179
+ static void CALLBACK
180
+ n_error(errorno)
181
+ GLenum errorno;
182
+ {
183
+ VALUE nurbs;
184
+ struct nurbsdata *ndata;
185
+ nurbs = rb_ary_entry(n_current, -1);
186
+ if (nurbs == Qnil)
187
+ return;
188
+ GetNURBS(nurbs, ndata);
189
+ rb_funcall(rb_ary_entry(ndata->n_ref, GLU_ERROR), callId, 1, INT2NUM(errorno));
190
+ }
191
+
192
+ static VALUE
193
+ glu_NurbsCallback(obj, arg1, arg2, arg3)
194
+ VALUE obj, arg1, arg2, arg3;
195
+ {
196
+ struct nurbsdata* ndata;
197
+ GLenum type;
198
+ GetNURBS(arg1, ndata);
199
+ type = (GLenum)NUM2INT(arg2);
200
+ if (!rb_obj_is_kind_of(arg3,rb_cProc) && !NIL_P(arg3))
201
+ rb_raise(rb_eTypeError, "gluNurbsCallback needs Proc Object:%s",rb_class2name(CLASS_OF(arg3)));
202
+
203
+ if (type!=GLU_ERROR)
204
+ return Qnil;
205
+
206
+ rb_ary_store(ndata->n_ref, type, arg3);
207
+ if (NIL_P(arg3))
208
+ gluNurbsCallback(ndata->nobj, type, NULL);
209
+ else
210
+ gluNurbsCallback(ndata->nobj, type, n_error);
211
+
212
+ return Qnil;
213
+ }
214
+
215
+
216
+ static VALUE
217
+ glu_NewNurbsRenderer(obj)
218
+ VALUE obj;
219
+ {
220
+ VALUE ret;
221
+ struct nurbsdata *ndata;
222
+ ret = Data_Make_Struct(cNurbs, struct nurbsdata, mark_nurbs, free_nurbs, ndata);
223
+ ndata->nobj = gluNewNurbsRenderer();
224
+ ndata->n_ref = rb_ary_new2(REF_LAST);
225
+
226
+ return ret;
227
+ }
228
+ static VALUE
229
+ glu_DeleteNurbsRenderer(obj, arg1)
230
+ VALUE obj, arg1;
231
+ {
232
+ struct nurbsdata *ndata;
233
+ GetNURBS(arg1, ndata);
234
+ free_nurbs(ndata);
235
+
236
+ return Qnil;
237
+ }
238
+ static VALUE
239
+ glu_NurbsProperty(obj, arg1, arg2, arg3)
240
+ VALUE obj, arg1, arg2, arg3;
241
+ {
242
+ struct nurbsdata *ndata;
243
+ GLenum property;
244
+ GLfloat value;
245
+ GetNURBS(arg1, ndata);
246
+ property = (GLenum)NUM2INT(arg2);
247
+ value = (GLfloat)NUM2DBL(arg3);
248
+ gluNurbsProperty(ndata->nobj, property, value);
249
+
250
+ return Qnil;
251
+ }
252
+ static VALUE
253
+ glu_GetNurbsProperty(obj, arg1, arg2)
254
+ VALUE obj, arg1, arg2;
255
+ {
256
+ struct nurbsdata *ndata;
257
+ GLenum property;
258
+ GLfloat value;
259
+ GetNURBS(arg1, ndata);
260
+ property = (GLenum)NUM2INT(arg2);
261
+ gluGetNurbsProperty(ndata->nobj, property, &value);
262
+
263
+ return cond_GLBOOL2RUBY_F(property,value);
264
+ }
265
+ static VALUE
266
+ glu_BeginCurve(obj, arg1)
267
+ VALUE obj, arg1;
268
+ {
269
+ struct nurbsdata *ndata;
270
+ GetNURBS(arg1, ndata);
271
+ rb_ary_push(n_current, arg1);
272
+ gluBeginCurve(ndata->nobj);
273
+
274
+ return Qnil;
275
+ }
276
+ static VALUE
277
+ glu_EndCurve(obj, arg1)
278
+ VALUE obj, arg1;
279
+ {
280
+ struct nurbsdata *ndata;
281
+ GetNURBS(arg1, ndata);
282
+ gluEndCurve(ndata->nobj);
283
+
284
+ for (;gms.len>0;gms.len--)
285
+ free(gms.ptr[gms.len-1]);
286
+ free(gms.ptr);
287
+ gms.ptr = NULL;
288
+
289
+ rb_ary_pop(n_current);
290
+
291
+
292
+ return Qnil;
293
+ }
294
+ static VALUE
295
+ glu_NurbsCurve(argc,argv,obj)
296
+ int argc;
297
+ VALUE *argv;
298
+ VALUE obj;
299
+ {
300
+ struct nurbsdata *ndata;
301
+ GLint uknot_count;
302
+ GLfloat *uknot;
303
+ GLint u_stride;
304
+ GLint uorder;
305
+ GLfloat *ctlarray;
306
+ GLenum type;
307
+
308
+ VALUE args[7];
309
+ VALUE ary_ctl1;
310
+
311
+ switch (rb_scan_args(argc, argv, "52", &args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6])) {
312
+ case 5:
313
+ uknot_count = (GLint)RARRAY_LENINT(args[1]);
314
+ uorder = (GLenum)NUM2INT(args[3]);
315
+ type = (GLenum)NUM2INT(args[4]);
316
+ u_stride = get_curve_dim(type);
317
+
318
+ uknot = ALLOC_N(GLfloat, uknot_count);
319
+ ary2cflt(args[1], uknot, uknot_count);
320
+
321
+ ary_ctl1 = rb_funcall(args[2],rb_intern("flatten"),0);
322
+ break;
323
+ case 7:
324
+ uknot_count = (GLint)NUM2INT(args[1]);
325
+ u_stride = (GLint)NUM2INT(args[3]);
326
+ uorder = (GLint)NUM2INT(args[5]);
327
+ type = (GLenum)NUM2INT(args[6]);
328
+
329
+ uknot = ALLOC_N(GLfloat, uknot_count);
330
+ ary2cflt(args[2], uknot, uknot_count);
331
+
332
+ ary_ctl1 = rb_funcall(args[4],rb_intern("flatten"),0);
333
+ break;
334
+ default:
335
+ rb_raise(rb_eArgError, "gluNurbsCurve needs 5 or 7 arguments");
336
+ }
337
+ ctlarray = ALLOC_N(GLfloat, u_stride*(uknot_count-uorder));
338
+ ary2cflt((VALUE)ary_ctl1, ctlarray, (uknot_count-uorder)*u_stride);
339
+
340
+ GetNURBS(args[0], ndata);
341
+ gluNurbsCurve(ndata->nobj, uknot_count, uknot, u_stride, ctlarray, uorder, type);
342
+
343
+ /* store the pointers */
344
+ gms.ptr = REALLOC_N(gms.ptr, GLfloat*, gms.len+=2);
345
+ gms.ptr[gms.len - 2] = uknot;
346
+ gms.ptr[gms.len - 1] = ctlarray;
347
+
348
+ return Qnil;
349
+ }
350
+ static VALUE
351
+ glu_BeginSurface(obj, arg1)
352
+ VALUE obj, arg1;
353
+ {
354
+ struct nurbsdata *ndata;
355
+ GetNURBS(arg1, ndata);
356
+ rb_ary_push(n_current, arg1);
357
+ gluBeginSurface(ndata->nobj);
358
+
359
+ return Qnil;
360
+ }
361
+ static VALUE
362
+ glu_EndSurface(obj, arg1)
363
+ VALUE obj, arg1;
364
+ {
365
+ struct nurbsdata *ndata;
366
+ GetNURBS(arg1, ndata);
367
+ gluEndSurface(ndata->nobj);
368
+
369
+ for(; gms.len>0; gms.len--)
370
+ free(gms.ptr[gms.len-1]);
371
+ free(gms.ptr);
372
+ gms.ptr = NULL;
373
+
374
+ rb_ary_pop(n_current);
375
+
376
+
377
+ return Qnil;
378
+ }
379
+
380
+ static VALUE
381
+ glu_NurbsSurface(argc, argv, obj)
382
+ int argc;
383
+ VALUE *argv;
384
+ VALUE obj;
385
+ {
386
+ struct nurbsdata *ndata;
387
+ GLint sknot_count;
388
+ GLfloat *sknot;
389
+ GLint tknot_count;
390
+ GLfloat *tknot;
391
+ GLint s_stride;
392
+ GLint t_stride;
393
+ GLfloat *ctlarray;
394
+ GLint sorder;
395
+ GLint torder;
396
+ GLenum type;
397
+
398
+ VALUE args[11];
399
+ VALUE ary_ctl1;
400
+ int type_len;
401
+
402
+ switch (rb_scan_args(argc, argv, "74", &args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6], &args[7], &args[8], &args[9], &args[10])) {
403
+ case 7:
404
+ sknot_count = (GLint)RARRAY_LENINT(args[1]);
405
+ sknot = ALLOC_N(GLfloat, sknot_count);
406
+ ary2cflt(args[1], sknot, sknot_count);
407
+
408
+ tknot_count = (GLint)RARRAY_LENINT(args[2]);
409
+ tknot = ALLOC_N(GLfloat, tknot_count);
410
+ ary2cflt(args[2], tknot, tknot_count);
411
+
412
+ sorder = (GLint)NUM2INT(args[4]);
413
+ torder = (GLint)NUM2INT(args[5]);
414
+ type = (GLenum)NUM2INT(args[6]);
415
+
416
+ t_stride = get_surface_dim(type);
417
+ s_stride = t_stride * sorder;
418
+
419
+ ctlarray = ALLOC_N(GLfloat, (sknot_count-sorder)*(tknot_count-torder)*t_stride);
420
+ ary_ctl1 = rb_funcall(args[3],rb_intern("flatten"),0);
421
+ ary2cflt(ary_ctl1, ctlarray, (sknot_count-sorder)*(tknot_count-torder)*t_stride);
422
+ break;
423
+ case 11:
424
+ sknot_count = (GLint)NUM2INT(args[1]);
425
+ sknot = ALLOC_N(GLfloat, sknot_count);
426
+ ary2cflt(args[2], sknot, sknot_count);
427
+
428
+ tknot_count = (GLint)NUM2INT(args[3]);
429
+ tknot = ALLOC_N(GLfloat, tknot_count);
430
+ ary2cflt(args[4], tknot, tknot_count);
431
+
432
+ s_stride = (GLint)NUM2INT(args[5]);
433
+ t_stride = (GLint)NUM2INT(args[6]);
434
+ sorder = (GLint)NUM2INT(args[8]);
435
+ torder = (GLint)NUM2INT(args[9]);
436
+ type = (GLint)NUM2INT(args[10]);
437
+ type_len = get_surface_dim(type);
438
+
439
+ ctlarray = ALLOC_N(GLfloat, (sknot_count-sorder)*(tknot_count-torder)*type_len);
440
+ ary_ctl1 = rb_funcall(args[7],rb_intern("flatten"),0);
441
+ ary2cflt(ary_ctl1, ctlarray, (sknot_count-sorder)*(tknot_count-torder)*type_len);
442
+ break;
443
+ default:
444
+ rb_raise(rb_eArgError, "gluNurbsSurface needs 7 or 11 arguments");
445
+ return Qnil; /* not reached */
446
+ }
447
+ GetNURBS(args[0], ndata);
448
+ gluNurbsSurface(ndata->nobj, sknot_count, sknot, tknot_count, tknot,
449
+ s_stride, t_stride, ctlarray, sorder, torder, type);
450
+
451
+ /* store the pointers */
452
+
453
+ gms.ptr = REALLOC_N(gms.ptr, GLfloat*, gms.len+=3);
454
+ gms.ptr[gms.len-3] = sknot;
455
+ gms.ptr[gms.len-2] = tknot;
456
+ gms.ptr[gms.len-1] = ctlarray;
457
+
458
+
459
+ return Qnil;
460
+ }
461
+ static VALUE
462
+ glu_BeginTrim(obj, arg1)
463
+ VALUE obj, arg1;
464
+ {
465
+ struct nurbsdata *ndata;
466
+ GetNURBS(arg1, ndata);
467
+ rb_ary_push(n_current, arg1);
468
+ gluBeginTrim(ndata->nobj);
469
+
470
+ return Qnil;
471
+ }
472
+ static VALUE
473
+ glu_EndTrim(obj, arg1)
474
+ VALUE obj, arg1;
475
+ {
476
+ struct nurbsdata *ndata;
477
+ GetNURBS(arg1, ndata);
478
+ gluEndTrim(ndata->nobj);
479
+ rb_ary_pop(n_current);
480
+
481
+ return Qnil;
482
+ }
483
+ static VALUE
484
+ glu_PwlCurve(argc, argv, obj)
485
+ int argc;
486
+ VALUE *argv;
487
+ VALUE obj;
488
+ {
489
+ struct nurbsdata *ndata;
490
+ GLint count;
491
+ GLfloat *array;
492
+ GLint stride;
493
+ GLenum type;
494
+
495
+ VALUE args[5];
496
+ VALUE ary_ctl1;
497
+
498
+ switch (rb_scan_args(argc, argv, "32", &args[0], &args[1], &args[2], &args[3], &args[4])) {
499
+ case 3:
500
+ count = (GLint)RARRAY_LENINT(args[1]);
501
+ type = NUM2INT(args[2]);
502
+ stride = (type == GLU_MAP1_TRIM_2 ? 2 : 3);
503
+
504
+ array = ALLOC_N(GLfloat, count*stride);
505
+ ary_ctl1 = rb_funcall(args[1],rb_intern("flatten"),0);
506
+ ary2cflt(ary_ctl1, array, count*stride);
507
+ break;
508
+ case 5:
509
+ count = NUM2INT(args[1]);
510
+ stride = NUM2INT(args[3]);
511
+ type = NUM2INT(args[4]);
512
+
513
+ array = ALLOC_N(GLfloat, count*stride);
514
+ ary_ctl1 = rb_funcall(args[2],rb_intern("flatten"),0);
515
+ ary2cflt(ary_ctl1, array, count*stride);
516
+ break;
517
+ default:
518
+ rb_raise(rb_eArgError, "gluPwlCurve needs 3 or 5 arguments");
519
+ return Qnil; /* not reached */
520
+ }
521
+
522
+ GetNURBS(args[0], ndata);
523
+ gluPwlCurve(ndata->nobj, count, array, stride, type);
524
+ free(array);
525
+
526
+ return Qnil;
527
+ }
528
+
529
+ static VALUE glu_LoadSamplingMatrices(obj,arg1,arg2,arg3,arg4)
530
+ VALUE obj, arg1,arg2,arg3,arg4;
531
+ {
532
+ struct nurbsdata *ndata;
533
+ GLfloat mdl_mtx[4*4];
534
+ GLfloat persp_mtx[4*4];
535
+ GLint viewport[4];
536
+
537
+ GetNURBS(arg1, ndata);
538
+ ary2cmatfloat(arg2,mdl_mtx,4,4);
539
+ ary2cmatfloat(arg3,persp_mtx,4,4);
540
+ ary2cint(arg4,viewport,4);
541
+
542
+ gluLoadSamplingMatrices(ndata->nobj,mdl_mtx,persp_mtx,viewport);
543
+
544
+
545
+ return Qnil;
546
+ }
547
+
548
+ /*
549
+ * Tesselation API
550
+ */
551
+ static VALUE t_current;
552
+ #define TESS_DATA 0
553
+ #define TESS_BEGIN 1
554
+ #define TESS_VERTEX 2
555
+ #define TESS_END 3
556
+ #define TESS_ERROR 4
557
+ #define TESS_EDGE_FLAG 5
558
+ #define TESS_OUTDATA 6
559
+ #define TESS_COMBINE 7
560
+ #define TESS_BEGIN_DATA 8
561
+ #define TESS_VERTEX_DATA 9
562
+ #define TESS_END_DATA 10
563
+ #define TESS_ERROR_DATA 11
564
+ #define TESS_EDGE_FLAG_DATA 12
565
+ #define TESS_COMBINE_DATA 13
566
+ #define TESS_USERDATA 14
567
+
568
+ static void
569
+ mark_tess(tdata)
570
+ struct tessdata* tdata;
571
+ {
572
+ if (tdata->tobj)
573
+ rb_gc_mark(tdata->t_ref);
574
+ }
575
+ static void
576
+ free_tess(tdata)
577
+ struct tessdata *tdata;
578
+ {
579
+ if (tdata->tobj)
580
+ gluDeleteTess(tdata->tobj);
581
+ tdata->t_ref = Qnil;
582
+ tdata->tobj = NULL;
583
+ }
584
+ static VALUE
585
+ glu_NewTess(obj)
586
+ VALUE obj;
587
+ {
588
+ VALUE ret;
589
+ struct tessdata *tdata;
590
+ ret = Data_Make_Struct(cTess, struct tessdata, mark_tess, free_tess, tdata);
591
+ tdata->tobj = gluNewTess();
592
+ tdata->t_ref = rb_ary_new2(REF_LAST);
593
+
594
+ return ret;
595
+ }
596
+ static VALUE
597
+ glu_DeleteTess(obj, arg1)
598
+ VALUE obj, arg1;
599
+ {
600
+ struct tessdata *tdata;
601
+ GetTESS(arg1, tdata);
602
+ free_tess(tdata);
603
+
604
+ return Qnil;
605
+ }
606
+
607
+ /* tess* callback function wrappers */
608
+ #define TESS_CALLBACK_COMMON \
609
+ VALUE tess; \
610
+ struct tessdata *tdata; \
611
+ tess = rb_ary_entry(t_current, -1); \
612
+ if (tess == Qnil) \
613
+ return; \
614
+ GetTESS(tess, tdata);
615
+
616
+ static void CALLBACK
617
+ t_begin(type)
618
+ GLenum type;
619
+ {
620
+ TESS_CALLBACK_COMMON
621
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_BEGIN), callId, 1, INT2NUM(type));
622
+ }
623
+ static void CALLBACK
624
+ t_edgeFlag(flag)
625
+ GLboolean flag;
626
+ {
627
+ TESS_CALLBACK_COMMON
628
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_EDGE_FLAG), callId, 1, GLBOOL2RUBY(flag));
629
+ }
630
+ static void CALLBACK
631
+ t_vertex(data)
632
+ void* data;
633
+ {
634
+ TESS_CALLBACK_COMMON
635
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_VERTEX), callId, 1, data);
636
+ }
637
+ static void CALLBACK
638
+ t_end()
639
+ {
640
+ TESS_CALLBACK_COMMON
641
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_END), callId, 0);
642
+ }
643
+ static void CALLBACK
644
+ t_error(errorno)
645
+ GLenum errorno;
646
+ {
647
+ TESS_CALLBACK_COMMON
648
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_ERROR), callId, 1, INT2NUM(errorno));
649
+ }
650
+ static void CALLBACK
651
+ t_begin_data(type, user_data)
652
+ GLenum type;
653
+ void* user_data;
654
+ {
655
+ TESS_CALLBACK_COMMON
656
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_BEGIN_DATA), callId, 2, INT2NUM(type), user_data);
657
+ }
658
+ static void CALLBACK
659
+ t_edgeFlag_data(flag, user_data)
660
+ GLboolean flag;
661
+ void* user_data;
662
+ {
663
+ TESS_CALLBACK_COMMON
664
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_EDGE_FLAG_DATA), callId, 2, GLBOOL2RUBY(flag), user_data);
665
+ }
666
+ static void CALLBACK
667
+ t_vertex_data(data, user_data)
668
+ void* data;
669
+ void* user_data;
670
+ {
671
+ TESS_CALLBACK_COMMON
672
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_VERTEX_DATA), callId, 2, data, user_data);
673
+ }
674
+ static void CALLBACK
675
+ t_end_data(user_data)
676
+ void* user_data;
677
+ {
678
+ TESS_CALLBACK_COMMON
679
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_END_DATA), callId, 1, user_data);
680
+ }
681
+ static void CALLBACK
682
+ t_error_data(errorno, user_data)
683
+ GLenum errorno;
684
+ void* user_data;
685
+ {
686
+ TESS_CALLBACK_COMMON
687
+ rb_funcall(rb_ary_entry(tdata->t_ref, TESS_ERROR_DATA), callId, 2, INT2NUM(errorno), user_data);
688
+ }
689
+
690
+ static void CALLBACK
691
+ t_combine(coords, vertex_data, weight, outData)
692
+ GLdouble coords[3];
693
+ void* vertex_data[4];
694
+ GLfloat weight[4];
695
+ void** outData;
696
+ {
697
+ VALUE rb_coord, rb_vertex_data, rb_weight;
698
+ int i;
699
+ TESS_CALLBACK_COMMON
700
+
701
+ rb_coord = rb_ary_new2(3);
702
+ for (i = 0; i < 3; i++)
703
+ rb_ary_store(rb_coord, i, rb_float_new(coords[i]));
704
+ rb_vertex_data = rb_ary_new2(4);
705
+ for (i = 0; i < 4; i++)
706
+ rb_ary_store(rb_vertex_data, i, (VALUE)vertex_data[i]);
707
+ rb_weight = rb_ary_new2(4);
708
+ for (i = 0; i < 4; i++)
709
+ rb_ary_store(rb_weight, i, rb_float_new(weight[i]));
710
+ *outData = (void*)rb_funcall(rb_ary_entry(tdata->t_ref, TESS_COMBINE), callId, 3, rb_coord, rb_vertex_data, rb_weight);
711
+ rb_ary_push(rb_ary_entry(tdata->t_ref, TESS_OUTDATA), (VALUE)*outData);
712
+ }
713
+
714
+ static void CALLBACK
715
+ t_combine_data(coords, vertex_data, weight, outData, user_data)
716
+ GLdouble coords[3];
717
+ void* vertex_data[4];
718
+ GLfloat weight[4];
719
+ void** outData;
720
+ void* user_data;
721
+ {
722
+ VALUE rb_coord, rb_vertex_data, rb_weight;
723
+ int i;
724
+ TESS_CALLBACK_COMMON
725
+
726
+ rb_coord = rb_ary_new2(3);
727
+ for (i = 0; i < 3; i++)
728
+ rb_ary_store(rb_coord, i, rb_float_new(coords[i]));
729
+ rb_vertex_data = rb_ary_new2(4);
730
+ for (i = 0; i < 4; i++)
731
+ rb_ary_store(rb_vertex_data, i, (VALUE)vertex_data[i]);
732
+ rb_weight = rb_ary_new2(4);
733
+ for (i = 0; i < 4; i++)
734
+ rb_ary_store(rb_weight, i, rb_float_new(weight[i]));
735
+
736
+ *outData = (void*)rb_funcall(rb_ary_entry(tdata->t_ref, TESS_COMBINE_DATA), callId, 4, rb_coord, rb_vertex_data, rb_weight, (VALUE)user_data);
737
+
738
+ rb_ary_push(rb_ary_entry(tdata->t_ref, TESS_OUTDATA), (VALUE)*outData);
739
+ }
740
+
741
+ #undef TESS_CALLBACK_COMMON
742
+
743
+ static VALUE
744
+ glu_TessProperty(obj, arg1, arg2, arg3)
745
+ VALUE obj, arg1, arg2, arg3;
746
+ {
747
+ struct tessdata* tdata;
748
+ GLenum property;
749
+ GLdouble value;
750
+ GetTESS(arg1, tdata);
751
+ property = (GLenum)NUM2INT(arg2);
752
+ value = (GLdouble)NUM2DBL(arg3);
753
+ gluTessProperty(tdata->tobj, property, value);
754
+
755
+ return Qnil;
756
+ }
757
+ static VALUE
758
+ glu_GetTessProperty(obj, arg1, arg2)
759
+ VALUE obj, arg1, arg2;
760
+ {
761
+ struct tessdata* tdata;
762
+ GLenum property;
763
+ GLdouble value;
764
+ GetTESS(arg1, tdata);
765
+ property = (GLenum)NUM2INT(arg2);
766
+ gluGetTessProperty(tdata->tobj, property, &value);
767
+
768
+ return cond_GLBOOL2RUBY_D(property,value);
769
+ }
770
+ static VALUE
771
+ glu_TessNormal(obj, arg1, arg2, arg3, arg4)
772
+ VALUE obj, arg1, arg2, arg3, arg4;
773
+ {
774
+ struct tessdata* tdata;
775
+ GLdouble x, y, z;
776
+ GetTESS(arg1, tdata);
777
+ x = (GLdouble)NUM2DBL(arg2);
778
+ y = (GLdouble)NUM2DBL(arg3);
779
+ z = (GLdouble)NUM2DBL(arg4);
780
+ gluTessNormal(tdata->tobj, x, y, z);
781
+
782
+ return Qnil;
783
+ }
784
+ static VALUE
785
+ glu_TessBeginPolygon(obj, arg1, arg2)
786
+ VALUE obj, arg1, arg2;
787
+ {
788
+ struct tessdata* tdata;
789
+ GetTESS(arg1, tdata);
790
+ rb_ary_store(tdata->t_ref, TESS_USERDATA, arg2);
791
+ rb_ary_store(tdata->t_ref, TESS_OUTDATA, rb_ary_new());
792
+ rb_ary_store(tdata->t_ref, TESS_DATA, rb_ary_new());
793
+ rb_ary_push(t_current, arg1);
794
+ gluTessBeginPolygon(tdata->tobj, (void*)arg2);
795
+
796
+ return Qnil;
797
+ }
798
+ static VALUE
799
+ glu_TessEndPolygon(obj, arg1)
800
+ VALUE obj, arg1;
801
+ {
802
+ struct tessdata* tdata;
803
+ GetTESS(arg1, tdata);
804
+ gluTessEndPolygon(tdata->tobj);
805
+ rb_ary_store(tdata->t_ref, TESS_USERDATA, Qnil);
806
+ rb_ary_store(tdata->t_ref, TESS_OUTDATA, Qnil);
807
+ rb_ary_store(tdata->t_ref, TESS_DATA, Qnil);
808
+ rb_ary_pop(t_current);
809
+
810
+ return Qnil;
811
+ }
812
+ static VALUE
813
+ glu_TessBeginContour(obj, arg1)
814
+ VALUE obj, arg1;
815
+ {
816
+ struct tessdata* tdata;
817
+ GetTESS(arg1, tdata);
818
+ gluTessBeginContour(tdata->tobj);
819
+
820
+ return Qnil;
821
+ }
822
+ static VALUE
823
+ glu_TessEndContour(obj, arg1)
824
+ VALUE obj, arg1;
825
+ {
826
+ struct tessdata* tdata;
827
+ GetTESS(arg1, tdata);
828
+ gluTessEndContour(tdata->tobj);
829
+
830
+ return Qnil;
831
+ }
832
+
833
+ #define TESS_CALLBACK_CASE(_type_,_function_) \
834
+ case GLU_##_type_: \
835
+ rb_ary_store(tdata->t_ref, _type_, arg3); \
836
+ if (NIL_P(arg3)) \
837
+ gluTessCallback(tdata->tobj, type, NULL); \
838
+ else \
839
+ gluTessCallback(tdata->tobj, type, _function_); \
840
+ break;
841
+
842
+ static VALUE
843
+ glu_TessCallback(obj, arg1, arg2, arg3)
844
+ VALUE obj, arg1, arg2, arg3;
845
+ {
846
+ struct tessdata* tdata;
847
+ GLenum type;
848
+ GetTESS(arg1, tdata);
849
+ type = (GLenum)NUM2INT(arg2);
850
+ if (!rb_obj_is_kind_of(arg3,rb_cProc) && !NIL_P(arg3))
851
+ rb_raise(rb_eTypeError, "gluTessCallback needs Proc Object:%s",rb_class2name(CLASS_OF(arg3)));
852
+
853
+ switch (type) {
854
+ TESS_CALLBACK_CASE(TESS_BEGIN,t_begin)
855
+ TESS_CALLBACK_CASE(TESS_BEGIN_DATA,t_begin_data)
856
+ TESS_CALLBACK_CASE(TESS_EDGE_FLAG,t_edgeFlag)
857
+ TESS_CALLBACK_CASE(TESS_EDGE_FLAG_DATA,t_edgeFlag_data)
858
+ TESS_CALLBACK_CASE(TESS_VERTEX,t_vertex)
859
+ TESS_CALLBACK_CASE(TESS_VERTEX_DATA,t_vertex_data)
860
+ TESS_CALLBACK_CASE(TESS_END,t_end)
861
+ TESS_CALLBACK_CASE(TESS_END_DATA,t_end_data)
862
+ TESS_CALLBACK_CASE(TESS_ERROR,t_error)
863
+ TESS_CALLBACK_CASE(TESS_ERROR_DATA,t_error_data)
864
+ TESS_CALLBACK_CASE(TESS_COMBINE,t_combine)
865
+ TESS_CALLBACK_CASE(TESS_COMBINE_DATA,t_combine_data)
866
+ }
867
+
868
+ return Qnil;
869
+ }
870
+ #undef TESS_CALLBACK_CASE
871
+
872
+ static VALUE
873
+ glu_BeginPolygon(obj, arg1)
874
+ VALUE obj, arg1;
875
+ {
876
+ struct tessdata* tdata;
877
+ GetTESS(arg1, tdata);
878
+ rb_ary_store(tdata->t_ref, TESS_DATA, rb_ary_new());
879
+ rb_ary_push(t_current, arg1);
880
+ gluBeginPolygon(tdata->tobj);
881
+
882
+ return Qnil;
883
+ }
884
+ static VALUE
885
+ glu_TessVertex(obj, arg1, arg2, arg3)
886
+ VALUE obj, arg1, arg2, arg3;
887
+ {
888
+ struct tessdata* tdata;
889
+ GLdouble v[3] = {0.0,0.0,0.0};
890
+ GetTESS(arg1, tdata);
891
+ rb_ary_push(rb_ary_entry(tdata->t_ref, TESS_DATA), arg3);
892
+ Check_Type(arg2,T_ARRAY);
893
+ ary2cdbl(arg2, v, 3);
894
+ gluTessVertex(tdata->tobj, v,(void *)arg3);
895
+
896
+ return Qnil;
897
+ }
898
+ static VALUE
899
+ glu_NextContour(obj, arg1, arg2)
900
+ VALUE obj, arg1, arg2;
901
+ {
902
+ struct tessdata* tdata;
903
+ GLenum type;
904
+ GetTESS(arg1, tdata);
905
+ type = (GLenum)NUM2INT(arg2);
906
+ gluNextContour(tdata->tobj, type);
907
+
908
+ return Qnil;
909
+ }
910
+ static VALUE
911
+ glu_EndPolygon(obj, arg1)
912
+ VALUE obj, arg1;
913
+ {
914
+ struct tessdata* tdata;
915
+ GetTESS(arg1, tdata);
916
+ gluEndPolygon(tdata->tobj);
917
+ rb_ary_store(tdata->t_ref, TESS_DATA, Qnil);
918
+ rb_ary_pop(t_current);
919
+
920
+ return Qnil;
921
+ }
922
+
923
+ /*
924
+ * Quadric API
925
+ */
926
+ static VALUE q_current;
927
+
928
+ static void CALLBACK
929
+ q_error(errorno)
930
+ GLenum errorno;
931
+ {
932
+ VALUE quad;
933
+ struct quaddata *qdata;
934
+ quad = rb_ary_entry(q_current, -1);
935
+ if (quad == Qnil)
936
+ return;
937
+ GetQUAD(quad, qdata);
938
+ rb_funcall(rb_ary_entry(qdata->q_ref, GLU_ERROR), callId, 1, INT2NUM(errorno));
939
+ }
940
+
941
+ static VALUE
942
+ glu_QuadricCallback(obj, arg1, arg2, arg3)
943
+ VALUE obj, arg1, arg2, arg3;
944
+ {
945
+ struct quaddata* qdata;
946
+ GLenum type;
947
+ GetQUAD(arg1, qdata);
948
+ type = (GLenum)NUM2INT(arg2);
949
+ if (!rb_obj_is_kind_of(arg3,rb_cProc) && !NIL_P(arg3))
950
+ rb_raise(rb_eTypeError, "gluQuadricCallback needs Proc Object:%s",rb_class2name(CLASS_OF(arg3)));
951
+
952
+
953
+ if (type!=GLU_ERROR)
954
+ return Qnil;
955
+
956
+ rb_ary_store(qdata->q_ref, type, arg3);
957
+ if (NIL_P(arg3))
958
+ gluQuadricCallback(qdata->qobj, type, NULL);
959
+ else
960
+ gluQuadricCallback(qdata->qobj, type, q_error);
961
+
962
+
963
+ return Qnil;
964
+ }
965
+
966
+ static void
967
+ free_quad(qdata)
968
+ struct quaddata *qdata;
969
+ {
970
+ if (qdata->qobj) gluDeleteQuadric(qdata->qobj);
971
+ qdata->qobj = NULL;
972
+ qdata->q_ref = Qnil;
973
+ }
974
+ static void
975
+ mark_quad(qdata)
976
+ struct quaddata* qdata;
977
+ {
978
+ if (qdata->qobj)
979
+ rb_gc_mark(qdata->q_ref);
980
+ }
981
+ static VALUE
982
+ glu_NewQuadric(obj)
983
+ VALUE obj;
984
+ {
985
+ VALUE ret;
986
+ struct quaddata *qdata;
987
+ ret = Data_Make_Struct(cQuad, struct quaddata, mark_quad, free_quad, qdata);
988
+ qdata->qobj = gluNewQuadric();
989
+ qdata->q_ref = rb_ary_new2(REF_LAST);
990
+
991
+ return ret;
992
+ }
993
+ static VALUE
994
+ glu_DeleteQuadric(obj, arg1)
995
+ VALUE obj, arg1;
996
+ {
997
+ struct quaddata *qdata;
998
+ GetQUAD(arg1, qdata);
999
+ free_quad(qdata);
1000
+
1001
+ return Qnil;
1002
+ }
1003
+ static VALUE
1004
+ glu_QuadricNormals(obj, arg1, arg2)
1005
+ VALUE obj, arg1, arg2;
1006
+ {
1007
+ struct quaddata* qdata;
1008
+ GLenum normals;
1009
+ GetQUAD(arg1, qdata);
1010
+ normals = (GLenum)NUM2INT(arg2);
1011
+ gluQuadricNormals(qdata->qobj, normals);
1012
+
1013
+ return Qnil;
1014
+ }
1015
+ static VALUE
1016
+ glu_QuadricTexture(obj, arg1, arg2)
1017
+ VALUE obj, arg1, arg2;
1018
+ {
1019
+ struct quaddata* qdata;
1020
+ GLboolean textureCoords;
1021
+ GetQUAD(arg1, qdata);
1022
+ textureCoords = (GLboolean)NUM2INT(arg2);
1023
+ gluQuadricTexture(qdata->qobj, textureCoords);
1024
+
1025
+ return Qnil;
1026
+ }
1027
+ static VALUE
1028
+ glu_QuadricOrientation(obj, arg1, arg2)
1029
+ VALUE obj, arg1, arg2;
1030
+ {
1031
+ struct quaddata* qdata;
1032
+ GLenum orientation;
1033
+ GetQUAD(arg1, qdata);
1034
+ orientation = (GLenum)NUM2INT(arg2);
1035
+ gluQuadricOrientation(qdata->qobj, orientation);
1036
+
1037
+ return Qnil;
1038
+ }
1039
+ static VALUE
1040
+ glu_QuadricDrawStyle(obj, arg1, arg2)
1041
+ VALUE obj, arg1, arg2;
1042
+ {
1043
+ struct quaddata* qdata;
1044
+ GLenum drawStyle;
1045
+ GetQUAD(arg1, qdata);
1046
+ drawStyle = (GLenum)NUM2INT(arg2);
1047
+ gluQuadricDrawStyle(qdata->qobj, drawStyle);
1048
+
1049
+ return Qnil;
1050
+ }
1051
+ static VALUE
1052
+ glu_Cylinder(obj, arg1, arg2, arg3, arg4, arg5, arg6)
1053
+ VALUE obj, arg1, arg2, arg3, arg4, arg5, arg6;
1054
+ {
1055
+ struct quaddata* qdata;
1056
+ GLdouble baseRadius;
1057
+ GLdouble topRadius;
1058
+ GLdouble height;
1059
+ GLint slices;
1060
+ GLint stacks;
1061
+
1062
+ GetQUAD(arg1, qdata);
1063
+ baseRadius = (GLdouble)NUM2DBL(arg2);
1064
+ topRadius = (GLdouble)NUM2DBL(arg3);
1065
+ height = (GLdouble)NUM2DBL(arg4);
1066
+ slices = (GLint)NUM2INT(arg5);
1067
+ stacks = (GLint)NUM2INT(arg6);
1068
+
1069
+ rb_ary_push(q_current, arg1);
1070
+ gluCylinder(qdata->qobj, baseRadius, topRadius, height, slices, stacks);
1071
+ rb_ary_pop(q_current);
1072
+
1073
+ return Qnil;
1074
+ }
1075
+ static VALUE
1076
+ glu_Disk(obj, arg1, arg2, arg3, arg4, arg5)
1077
+ VALUE obj, arg1, arg2, arg3, arg4, arg5;
1078
+ {
1079
+ struct quaddata* qdata;
1080
+ GLdouble innerRadius;
1081
+ GLdouble outerRadius;
1082
+ GLint slices;
1083
+ GLint loops;
1084
+
1085
+ GetQUAD(arg1, qdata);
1086
+ innerRadius = (GLdouble)NUM2DBL(arg2);
1087
+ outerRadius = (GLdouble)NUM2DBL(arg3);
1088
+ slices = (GLint)NUM2INT(arg4);
1089
+ loops = (GLint)NUM2INT(arg5);
1090
+
1091
+ rb_ary_push(q_current, arg1);
1092
+
1093
+ gluDisk(qdata->qobj, innerRadius, outerRadius, slices, loops);
1094
+ rb_ary_pop(q_current);
1095
+
1096
+ return Qnil;
1097
+ }
1098
+ static VALUE
1099
+ glu_PartialDisk(obj, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
1100
+ VALUE obj, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
1101
+ {
1102
+ struct quaddata* qdata;
1103
+ GLdouble innerRadius;
1104
+ GLdouble outerRadius;
1105
+ GLint slices;
1106
+ GLint loops;
1107
+ GLdouble startAngle;
1108
+ GLdouble sweepAngle;
1109
+
1110
+ GetQUAD(arg1, qdata);
1111
+ innerRadius = (GLdouble)NUM2DBL(arg2);
1112
+ outerRadius = (GLdouble)NUM2DBL(arg3);
1113
+ slices = (GLint)NUM2INT(arg4);
1114
+ loops = (GLint)NUM2INT(arg5);
1115
+ startAngle = (GLdouble)NUM2DBL(arg6);
1116
+ sweepAngle = (GLdouble)NUM2DBL(arg7);
1117
+
1118
+ rb_ary_push(q_current, arg1);
1119
+ gluPartialDisk(qdata->qobj, innerRadius, outerRadius, slices, loops, startAngle, sweepAngle);
1120
+ rb_ary_pop(q_current);
1121
+
1122
+ return Qnil;
1123
+ }
1124
+ static VALUE
1125
+ glu_Sphere(obj, arg1, arg2, arg3, arg4)
1126
+ VALUE obj, arg1, arg2, arg3, arg4;
1127
+ {
1128
+ struct quaddata* qdata;
1129
+ GLdouble radius;
1130
+ GLint slices;
1131
+ GLint stacks;
1132
+
1133
+ GetQUAD(arg1, qdata);
1134
+ radius = (GLdouble)NUM2DBL(arg2);
1135
+ slices = (GLint)NUM2INT(arg3);
1136
+ stacks = (GLint)NUM2INT(arg4);
1137
+
1138
+ rb_ary_push(q_current, arg1);
1139
+ gluSphere(qdata->qobj, radius, slices, stacks);
1140
+ rb_ary_pop(q_current);
1141
+
1142
+ return Qnil;
1143
+ }
1144
+
1145
+ /* */
1146
+
1147
+ static VALUE
1148
+ glu_LookAt(obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
1149
+ VALUE obj,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9;
1150
+ {
1151
+ GLdouble eyex;
1152
+ GLdouble eyey;
1153
+ GLdouble eyez;
1154
+ GLdouble centerx;
1155
+ GLdouble centery;
1156
+ GLdouble centerz;
1157
+ GLdouble upx;
1158
+ GLdouble upy;
1159
+ GLdouble upz;
1160
+ eyex = (GLdouble)NUM2DBL(arg1);
1161
+ eyey = (GLdouble)NUM2DBL(arg2);
1162
+ eyez = (GLdouble)NUM2DBL(arg3);
1163
+ centerx = (GLdouble)NUM2DBL(arg4);
1164
+ centery = (GLdouble)NUM2DBL(arg5);
1165
+ centerz = (GLdouble)NUM2DBL(arg6);
1166
+ upx = (GLdouble)NUM2DBL(arg7);
1167
+ upy = (GLdouble)NUM2DBL(arg8);
1168
+ upz = (GLdouble)NUM2DBL(arg9);
1169
+ gluLookAt( eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz );
1170
+
1171
+ return Qnil;
1172
+ }
1173
+ static VALUE
1174
+ glu_Ortho2D(obj,arg1,arg2,arg3,arg4)
1175
+ VALUE obj,arg1,arg2,arg3,arg4;
1176
+ {
1177
+ GLdouble left;
1178
+ GLdouble right;
1179
+ GLdouble bottom;
1180
+ GLdouble top;
1181
+ left = (GLdouble)NUM2DBL(arg1);
1182
+ right = (GLdouble)NUM2DBL(arg2);
1183
+ bottom = (GLdouble)NUM2DBL(arg3);
1184
+ top = (GLdouble)NUM2DBL(arg4);
1185
+ gluOrtho2D(left,right,bottom,top);
1186
+
1187
+ return Qnil;
1188
+ }
1189
+ static VALUE
1190
+ glu_Perspective(obj,arg1,arg2,arg3,arg4)
1191
+ VALUE obj,arg1,arg2,arg3,arg4;
1192
+ {
1193
+ GLdouble fovy;
1194
+ GLdouble aspect;
1195
+ GLdouble zNear;
1196
+ GLdouble zFar;
1197
+ fovy = (GLdouble)NUM2DBL(arg1);
1198
+ aspect = (GLdouble)NUM2DBL(arg2);
1199
+ zNear = (GLdouble)NUM2DBL(arg3);
1200
+ zFar = (GLdouble)NUM2DBL(arg4);
1201
+ gluPerspective(fovy,aspect,zNear,zFar);
1202
+
1203
+ return Qnil;
1204
+ }
1205
+ static VALUE
1206
+ glu_PickMatrix(argc,argv,obj)
1207
+ int argc;
1208
+ VALUE* argv;
1209
+ VALUE obj;
1210
+ {
1211
+ GLdouble x;
1212
+ GLdouble y;
1213
+ GLdouble width;
1214
+ GLdouble height;
1215
+ GLint viewport[4];
1216
+
1217
+ VALUE args[5];
1218
+
1219
+ switch (rb_scan_args(argc, argv, "23", &args[0], &args[1], &args[2], &args[3], &args[4])) {
1220
+ case 2:
1221
+ width = 5.0f;
1222
+ height = 5.0f;
1223
+ glGetIntegerv(GL_VIEWPORT, viewport);
1224
+ break;
1225
+ case 4:
1226
+ width = (GLdouble)NUM2DBL(args[2]);
1227
+ height = (GLdouble)NUM2DBL(args[3]);
1228
+ glGetIntegerv(GL_VIEWPORT, viewport);
1229
+ break;
1230
+ case 5:
1231
+ width = (GLdouble)NUM2DBL(args[2]);
1232
+ height = (GLdouble)NUM2DBL(args[3]);
1233
+ ary2cint(args[4], viewport, 4);
1234
+ break;
1235
+ default:
1236
+ rb_raise(rb_eArgError, "gluPickMatrix needs 2,4 or 5 parameters");
1237
+ }
1238
+ x = (GLdouble)NUM2DBL(args[0]);
1239
+ y = (GLdouble)NUM2DBL(args[1]);
1240
+ gluPickMatrix(x, y, width, height, viewport);
1241
+
1242
+ return Qnil;
1243
+ }
1244
+
1245
+ static VALUE
1246
+ glu_Project(argc,argv,obj)
1247
+ int argc;
1248
+ VALUE* argv;
1249
+ VALUE obj;
1250
+ {
1251
+ GLdouble ox;
1252
+ GLdouble oy;
1253
+ GLdouble oz;
1254
+ GLdouble mdl_mtx[4*4];
1255
+ GLdouble prj_mtx[4*4];
1256
+ GLint vport[4];
1257
+ GLdouble wx;
1258
+ GLdouble wy;
1259
+ GLdouble wz;
1260
+
1261
+ VALUE args[6];
1262
+
1263
+ switch (rb_scan_args(argc, argv, "33", &args[0], &args[1], &args[2], &args[3], &args[4], &args[5])) {
1264
+ case 3:
1265
+ glGetDoublev(GL_MODELVIEW_MATRIX, mdl_mtx);
1266
+ glGetDoublev(GL_PROJECTION_MATRIX, prj_mtx);
1267
+ glGetIntegerv(GL_VIEWPORT, vport);
1268
+ break;
1269
+ case 6:
1270
+ ary2cmatdouble(args[3], mdl_mtx, 4, 4);
1271
+ ary2cmatdouble(args[4], prj_mtx, 4, 4);
1272
+ ary2cint(args[5], vport, 4);
1273
+ break;
1274
+ default:
1275
+ rb_raise(rb_eArgError, "gluProject needs 3 or 6 parameters");
1276
+ }
1277
+ ox = (GLdouble)NUM2DBL(args[0]);
1278
+ oy = (GLdouble)NUM2DBL(args[1]);
1279
+ oz = (GLdouble)NUM2DBL(args[2]);
1280
+
1281
+ if (gluProject(ox, oy, oz, mdl_mtx, prj_mtx, vport, &wx, &wy, &wz) == GL_TRUE) {
1282
+
1283
+ return rb_ary_new3(3, rb_float_new(wx), rb_float_new(wy), rb_float_new(wz));
1284
+ } else {
1285
+
1286
+ check_for_gluerror(GLU_INVALID_VALUE);
1287
+ return Qnil; /* not reached */
1288
+ }
1289
+ }
1290
+ static VALUE
1291
+ glu_UnProject(argc,argv,obj)
1292
+ int argc;
1293
+ VALUE* argv;
1294
+ VALUE obj;
1295
+ {
1296
+ GLdouble wx;
1297
+ GLdouble wy;
1298
+ GLdouble wz;
1299
+ GLdouble mdl_mtx[4*4];
1300
+ GLdouble prj_mtx[4*4];
1301
+ GLint vport[4];
1302
+ GLdouble ox;
1303
+ GLdouble oy;
1304
+ GLdouble oz;
1305
+
1306
+ VALUE args[6];
1307
+
1308
+ switch (rb_scan_args(argc, argv, "33", &args[0], &args[1], &args[2], &args[3], &args[4], &args[5])) {
1309
+ case 3:
1310
+ glGetDoublev(GL_MODELVIEW_MATRIX, mdl_mtx);
1311
+ glGetDoublev(GL_PROJECTION_MATRIX, prj_mtx);
1312
+ glGetIntegerv(GL_VIEWPORT, vport);
1313
+ break;
1314
+ case 6:
1315
+ ary2cmatdouble(args[3], mdl_mtx, 4, 4);
1316
+ ary2cmatdouble(args[4], prj_mtx, 4, 4);
1317
+ ary2cint(args[5], vport, 4);
1318
+ break;
1319
+ default:
1320
+ rb_raise(rb_eArgError, "gluUnProject needs 3 or 6 parameters");
1321
+ }
1322
+ wx = (GLdouble)NUM2DBL(args[0]);
1323
+ wy = (GLdouble)NUM2DBL(args[1]);
1324
+ wz = (GLdouble)NUM2DBL(args[2]);
1325
+
1326
+ if (gluUnProject(wx, wy, wz, mdl_mtx, prj_mtx, vport, &ox, &oy, &oz) == GL_TRUE) {
1327
+
1328
+ return rb_ary_new3(3, rb_float_new(ox), rb_float_new(oy), rb_float_new(oz));
1329
+ } else {
1330
+
1331
+ check_for_gluerror(GLU_INVALID_VALUE);
1332
+ return Qnil; /* not reached */
1333
+ }
1334
+ }
1335
+
1336
+ static VALUE
1337
+ glu_Build1DMipmaps(obj, arg1, arg2, arg3, arg4, arg5, arg6)
1338
+ VALUE obj, arg1, arg2, arg3, arg4, arg5, arg6;
1339
+ {
1340
+ GLenum target;
1341
+ GLint components;
1342
+ GLint width;
1343
+ GLenum format;
1344
+ GLenum type;
1345
+ int ret;
1346
+
1347
+ target = (GLenum)NUM2INT(arg1);
1348
+ components = (GLint)NUM2INT(arg2);
1349
+ width = (GLint)NUM2INT(arg3);
1350
+ format = (GLenum)NUM2INT(arg4);
1351
+ type = (GLenum)NUM2INT(arg5);
1352
+ Check_Type(arg6,T_STRING);
1353
+ CheckDataSize(type,format,width,arg6);
1354
+
1355
+ ret = gluBuild1DMipmaps(target, components, width, format, type, RSTRING_PTR(arg6));
1356
+ check_for_gluerror(ret);
1357
+
1358
+ return INT2NUM(ret);
1359
+ }
1360
+
1361
+ static VALUE
1362
+ glu_Build2DMipmaps(obj, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
1363
+ VALUE obj, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
1364
+ {
1365
+ GLenum target;
1366
+ GLint components;
1367
+ GLint width;
1368
+ GLint height;
1369
+ GLenum format;
1370
+ GLenum type;
1371
+ int ret;
1372
+
1373
+ target = (GLenum)NUM2INT(arg1);
1374
+ components = (GLint)NUM2INT(arg2);
1375
+ width = (GLint)NUM2INT(arg3);
1376
+ height = (GLint)NUM2INT(arg4);
1377
+ format = (GLenum)NUM2INT(arg5);
1378
+ type = (GLenum)NUM2INT(arg6);
1379
+ Check_Type(arg7,T_STRING);
1380
+ CheckDataSize(type,format,width*height,arg7);
1381
+
1382
+ ret = gluBuild2DMipmaps(target, components, width, height, format, type, RSTRING_PTR(arg7));
1383
+ check_for_gluerror(ret);
1384
+
1385
+ return INT2NUM(ret);
1386
+ }
1387
+
1388
+ static VALUE
1389
+ glu_ScaleImage(obj, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
1390
+ VALUE obj, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8;
1391
+ {
1392
+ GLenum format;
1393
+ GLint widthin;
1394
+ GLint heightin;
1395
+ GLenum typein;
1396
+ void* datain;
1397
+ GLint widthout;
1398
+ GLint heightout;
1399
+ GLenum typeout;
1400
+ VALUE ret;
1401
+ GLint retcode;
1402
+
1403
+ format = (GLenum)NUM2INT(arg1);
1404
+ widthin = (GLint)NUM2INT(arg2);
1405
+ heightin = (GLint)NUM2INT(arg3);
1406
+ typein = (GLenum)NUM2INT(arg4);
1407
+ Check_Type(arg5,T_STRING);
1408
+ CheckDataSize(typein,format,heightin*widthin,arg5);
1409
+ datain = RSTRING_PTR(arg5);
1410
+ widthout = (GLint)NUM2INT(arg6);
1411
+ heightout = (GLint)NUM2INT(arg7);
1412
+ typeout = (GLenum)NUM2INT(arg8);
1413
+ ret = allocate_buffer_with_string(GetDataSize(typeout,format,widthout*heightout));
1414
+ retcode = gluScaleImage(format, widthin, heightin, typein, datain,
1415
+ widthout, heightout, typeout, (GLvoid*)RSTRING_PTR(ret));
1416
+
1417
+ check_for_gluerror(retcode);
1418
+
1419
+ return ret;
1420
+ }
1421
+
1422
+ static VALUE
1423
+ glu_ErrorString(obj, arg1)
1424
+ VALUE obj, arg1;
1425
+ {
1426
+ GLenum errorCode;
1427
+ GLubyte* error;
1428
+ errorCode = (GLenum)NUM2INT(arg1);
1429
+ error = (GLubyte*)gluErrorString(errorCode);
1430
+
1431
+ if (error)
1432
+ return rb_str_new2((char *)error);
1433
+ else
1434
+ return Qnil;
1435
+ }
1436
+ static VALUE
1437
+ glu_GetString(obj, arg1)
1438
+ VALUE obj, arg1;
1439
+ {
1440
+ GLenum name;
1441
+ GLubyte* str;
1442
+ name = (GLenum)NUM2INT(arg1);
1443
+ str = (GLubyte*)gluGetString(name);
1444
+
1445
+ if (str)
1446
+ return rb_str_new2((char *)str);
1447
+ else
1448
+ return Qnil;
1449
+ }
1450
+
1451
+ static VALUE module;
1452
+
1453
+ DLLEXPORT void Init_glu()
1454
+ {
1455
+ callId = rb_intern("call");
1456
+ refId = rb_intern("[]");
1457
+ module = rb_define_module("Glu");
1458
+
1459
+ glu_init_enums(module);
1460
+
1461
+ rb_define_module_function(module, "gluNewNurbsRenderer", glu_NewNurbsRenderer, 0);
1462
+ rb_define_module_function(module, "gluDeleteNurbsRenderer", glu_DeleteNurbsRenderer, 1);
1463
+ rb_define_module_function(module, "gluNurbsProperty", glu_NurbsProperty, 3);
1464
+ rb_define_module_function(module, "gluGetNurbsProperty", glu_GetNurbsProperty, 2);
1465
+ rb_define_module_function(module, "gluBeginCurve", glu_BeginCurve, 1);
1466
+ rb_define_module_function(module, "gluEndCurve", glu_EndCurve, 1);
1467
+ rb_define_module_function(module, "gluNurbsCurve", glu_NurbsCurve, -1);
1468
+ rb_define_module_function(module, "gluBeginSurface", glu_BeginSurface, 1);
1469
+ rb_define_module_function(module, "gluEndSurface", glu_EndSurface, 1);
1470
+ rb_define_module_function(module, "gluNurbsSurface", glu_NurbsSurface, -1);
1471
+ rb_define_module_function(module, "gluBeginTrim", glu_BeginTrim, 1);
1472
+ rb_define_module_function(module, "gluEndTrim", glu_EndTrim, 1);
1473
+ rb_define_module_function(module, "gluPwlCurve", glu_PwlCurve, -1);
1474
+ rb_define_module_function(module, "gluNewTess", glu_NewTess, 0);
1475
+ rb_define_module_function(module, "gluDeleteTess", glu_DeleteTess, 1);
1476
+ rb_define_module_function(module, "gluTessCallback", glu_TessCallback, 3);
1477
+ rb_define_module_function(module, "gluBeginPolygon", glu_BeginPolygon, 1);
1478
+ rb_define_module_function(module, "gluTessVertex", glu_TessVertex, 3);
1479
+ rb_define_module_function(module, "gluNextContour", glu_NextContour, 2);
1480
+ rb_define_module_function(module, "gluEndPolygon", glu_EndPolygon, 1);
1481
+ rb_define_module_function(module, "gluTessBeginPolygon", glu_TessBeginPolygon, 2);
1482
+ rb_define_module_function(module, "gluTessBeginContour", glu_TessBeginContour, 1);
1483
+ rb_define_module_function(module, "gluTessEndContour", glu_TessEndContour, 1);
1484
+ rb_define_module_function(module, "gluTessEndPolygon", glu_TessEndPolygon, 1);
1485
+ rb_define_module_function(module, "gluTessProperty", glu_TessProperty, 3);
1486
+ rb_define_module_function(module, "gluTessNormal", glu_TessNormal, 4);
1487
+ rb_define_module_function(module, "gluGetTessProperty", glu_GetTessProperty, 2);
1488
+ rb_define_module_function(module, "gluNewQuadric", glu_NewQuadric, 0);
1489
+ rb_define_module_function(module, "gluDeleteQuadric", glu_DeleteQuadric, 1);
1490
+ rb_define_module_function(module, "gluQuadricNormals", glu_QuadricNormals, 2);
1491
+ rb_define_module_function(module, "gluQuadricTexture", glu_QuadricTexture, 2);
1492
+ rb_define_module_function(module, "gluQuadricOrientation", glu_QuadricOrientation, 2);
1493
+ rb_define_module_function(module, "gluQuadricDrawStyle", glu_QuadricDrawStyle, 2);
1494
+ rb_define_module_function(module, "gluCylinder", glu_Cylinder, 6);
1495
+ rb_define_module_function(module, "gluDisk", glu_Disk, 5);
1496
+ rb_define_module_function(module, "gluPartialDisk", glu_PartialDisk, 7);
1497
+ rb_define_module_function(module, "gluSphere", glu_Sphere, 4);
1498
+
1499
+ rb_define_module_function(module, "gluLookAt", glu_LookAt, 9);
1500
+ rb_define_module_function(module, "gluOrtho2D", glu_Ortho2D, 4);
1501
+ rb_define_module_function(module, "gluPerspective", glu_Perspective, 4);
1502
+ rb_define_module_function(module, "gluPickMatrix", glu_PickMatrix, -1);
1503
+ rb_define_module_function(module, "gluProject", glu_Project, -1);
1504
+ rb_define_module_function(module, "gluUnProject", glu_UnProject, -1);
1505
+ rb_define_module_function(module, "gluBuild1DMipmaps", glu_Build1DMipmaps, 6);
1506
+ rb_define_module_function(module, "gluBuild2DMipmaps", glu_Build2DMipmaps, 7);
1507
+ rb_define_module_function(module, "gluScaleImage", glu_ScaleImage, 8);
1508
+ rb_define_module_function(module, "gluErrorString", glu_ErrorString, 1);
1509
+ rb_define_module_function(module, "gluGetString", glu_GetString, 1);
1510
+
1511
+ rb_define_module_function(module, "gluLoadSamplingMatrices",glu_LoadSamplingMatrices,4);
1512
+ rb_define_module_function(module, "gluQuadricCallback", glu_QuadricCallback, 3);
1513
+ rb_define_module_function(module, "gluNurbsCallback", glu_NurbsCallback, 3);
1514
+
1515
+ Class_GLUError = rb_define_class_under(module, "Error", rb_eStandardError);
1516
+
1517
+ rb_define_method(Class_GLUError, "initialize", GLUError_initialize, 2);
1518
+ rb_define_attr(Class_GLUError, "id", 1, 0);
1519
+
1520
+ cNurbs = rb_define_class("Nurbs", rb_cObject);
1521
+ cTess = rb_define_class("Tess", rb_cObject);
1522
+ cQuad = rb_define_class("Quadric", rb_cObject);
1523
+
1524
+ rb_global_variable(&t_current); /* current active tesselator, nurbs and quadric, used for callbacks */
1525
+ t_current = rb_ary_new();
1526
+ rb_global_variable(&n_current);
1527
+ n_current = rb_ary_new();
1528
+ rb_global_variable(&q_current);
1529
+ q_current = rb_ary_new();
1530
+ }