ruby-opengl 0.33.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/Rakefile +42 -15
  2. data/doc/build_install.txt +70 -25
  3. data/doc/history.txt +4 -0
  4. data/doc/requirements_and_design.txt +2 -3
  5. data/doc/roadmap.txt +15 -2
  6. data/doc/screenshots.txt +23 -0
  7. data/doc/supplies/page_template.html +2 -1
  8. data/doc/thanks.txt +3 -0
  9. data/doc/tutorial.txt +5 -3
  10. data/examples/README +57 -7
  11. data/examples/legacy/COPYRIGHT +8 -0
  12. data/examples/{aaindex.rb → legacy/aaindex.rb} +6 -5
  13. data/examples/legacy/aapoly.rb +153 -0
  14. data/examples/legacy/aargb.rb +139 -0
  15. data/examples/legacy/accanti.rb +159 -0
  16. data/examples/legacy/accpersp.rb +216 -0
  17. data/examples/legacy/alpha.rb +133 -0
  18. data/examples/legacy/alpha3D.rb +165 -0
  19. data/examples/legacy/bezcurve.rb +107 -0
  20. data/examples/legacy/bezmesh.rb +131 -0
  21. data/examples/legacy/checker.rb +121 -0
  22. data/examples/legacy/clip.rb +104 -0
  23. data/examples/legacy/colormat.rb +145 -0
  24. data/examples/legacy/cube.rb +73 -0
  25. data/examples/legacy/depthcue.rb +101 -0
  26. data/examples/legacy/dof.rb +212 -0
  27. data/examples/legacy/double.rb +104 -0
  28. data/examples/legacy/drawf.rb +98 -0
  29. data/examples/legacy/feedback.rb +152 -0
  30. data/examples/legacy/fog.rb +172 -0
  31. data/examples/legacy/font-glut.rb +41 -0
  32. data/examples/legacy/font.rb +158 -0
  33. data/examples/legacy/hello.rb +75 -0
  34. data/examples/legacy/image.rb +145 -0
  35. data/examples/legacy/jitter.rb +209 -0
  36. data/examples/legacy/lines.rb +135 -0
  37. data/examples/legacy/list.rb +120 -0
  38. data/examples/legacy/material.rb +290 -0
  39. data/examples/legacy/mipmap.rb +159 -0
  40. data/examples/legacy/model.rb +119 -0
  41. data/examples/legacy/movelight.rb +140 -0
  42. data/examples/legacy/pickdepth.rb +180 -0
  43. data/examples/legacy/planet.rb +112 -0
  44. data/examples/legacy/quadric.rb +180 -0
  45. data/examples/legacy/readpixel.rb +59 -0
  46. data/examples/legacy/robot.rb +120 -0
  47. data/examples/legacy/select.rb +207 -0
  48. data/examples/{smooth_prev.rb → legacy/smooth.rb} +3 -2
  49. data/examples/legacy/stencil.rb +154 -0
  50. data/examples/legacy/stroke.rb +170 -0
  51. data/examples/legacy/surface.rb +170 -0
  52. data/examples/legacy/teaambient.rb +132 -0
  53. data/examples/legacy/teapots.rb +188 -0
  54. data/examples/legacy/tess.rb +222 -0
  55. data/examples/legacy/texbind.rb +157 -0
  56. data/examples/legacy/texgen.rb +171 -0
  57. data/examples/legacy/texturesurf.rb +128 -0
  58. data/examples/legacy/varray.rb +167 -0
  59. data/examples/legacy/wrap.rb +158 -0
  60. data/examples/nehe_lesson02.rb +117 -0
  61. data/examples/nehe_lesson03.rb +122 -0
  62. data/examples/nehe_lesson04.rb +133 -0
  63. data/examples/nehe_lesson05.rb +186 -0
  64. data/examples/plane.rb +1 -1
  65. data/examples/smooth.rb +4 -2
  66. data/examples/test.rb +3 -2
  67. data/ext/common/{rbogl.c → common.h} +99 -32
  68. data/ext/common/gl-enums.h +39 -1
  69. data/ext/gl/gl-1.0-1.1.c +350 -305
  70. data/ext/gl/gl-1.2.c +933 -38
  71. data/ext/gl/gl-1.3.c +725 -0
  72. data/ext/gl/gl-1.4.c +647 -0
  73. data/ext/gl/gl-1.5.c +362 -0
  74. data/ext/gl/gl-2.0.c +1632 -0
  75. data/ext/gl/gl-2.1.c +154 -0
  76. data/ext/gl/gl-enums.c +1 -2
  77. data/ext/gl/gl.c +58 -2
  78. data/ext/gl/mkrf_conf.rb +4 -1
  79. data/ext/glu/glu.c +5 -4
  80. data/ext/glu/mkrf_conf.rb +4 -1
  81. data/ext/glut/glut.c +7 -1
  82. data/ext/glut/mkrf_conf.rb +5 -0
  83. data/lib/gl_prev.rb +4 -3
  84. data/lib/glu_prev.rb +4 -3
  85. data/lib/glut_prev.rb +3 -3
  86. data/{examples/all_tests.rb → lib/opengl.rb} +9 -12
  87. data/test/README +5 -18
  88. data/test/tc_common.rb +79 -0
  89. data/test/tc_func_10_11.rb +1255 -0
  90. data/test/tc_func_12.rb +186 -0
  91. data/test/tc_func_13.rb +203 -0
  92. data/test/tc_func_14.rb +197 -0
  93. data/test/tc_func_15.rb +82 -0
  94. data/test/tc_func_20.rb +320 -0
  95. data/test/tc_func_21.rb +67 -0
  96. data/test/tc_include_gl.rb +1 -1
  97. data/test/{tc_opengl_namespace.rb → tc_misc.rb} +20 -20
  98. data/test/tc_require_gl.rb +1 -1
  99. metadata +99 -27
  100. data/ext/common/Rakefile +0 -39
  101. data/ext/common/rbogl.h +0 -52
  102. data/test/runtests.sh +0 -7
  103. data/test/tc_gl_vertex.rb +0 -180
@@ -0,0 +1,216 @@
1
+ #/*
2
+ # * Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
+ # * ALL RIGHTS RESERVED
4
+ # * Permission to use, copy, modify, and distribute this software for
5
+ # * any purpose and without fee is hereby granted, provided that the above
6
+ # * copyright notice appear in all copies and that both the copyright notice
7
+ # * and this permission notice appear in supporting documentation, and that
8
+ # * the name of Silicon Graphics, Inc. not be used in advertising
9
+ # * or publicity pertaining to distribution of the software without specific,
10
+ # * written prior permission.
11
+ # *
12
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
+ # *
25
+ # * US Government Users Restricted Rights
26
+ # * Use, duplication, or disclosure by the Government is subject to
27
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
30
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
31
+ # * Unpublished-- rights reserved under the copyright laws of the
32
+ # * United States. Contractor/manufacturer is Silicon Graphics,
33
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
+ # *
35
+ # * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
+ # */
37
+ #
38
+ #/* accpersp.c
39
+ # * Use the accumulation buffer to do full-scene antialiasing
40
+ # * on a scene with perspective projection, using the special
41
+ # * routines accFrustum() and accPerspective().
42
+ # */
43
+ require "gl_prev"
44
+ require "glu_prev"
45
+ require "glut_prev"
46
+
47
+
48
+ $LOAD_PATH.push(File.dirname($0)) # Find jitter in script directory
49
+
50
+ PI_=3.14159265358979323846
51
+
52
+ #/* accFrustum()
53
+ # * The first 6 arguments are identical to the glFrustum() call.
54
+ # *
55
+ # * pixdx and pixdy are anti-alias jitter in pixels.
56
+ # * Set both equal to 0.0 for no anti-alias jitter.
57
+ # * eyedx and eyedy are depth-of field jitter in pixels.
58
+ # * Set both equal to 0.0 for no depth of field effects.
59
+ # *
60
+ # * focus is distance from eye to plane in focus.
61
+ # * focus must be greater than, but not equal to 0.0.
62
+ # *
63
+ # * Note that accFrustum() calls glTranslatef(). You will
64
+ # * probably want to insure that your ModelView matrix has been
65
+ # * initialized to identity before calling accFrustum().
66
+ # */
67
+ def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
68
+
69
+ viewport = GL::GetDoublev(GL::VIEWPORT);
70
+
71
+ xwsize = right - left;
72
+ ywsize = top - bottom;
73
+
74
+ dx = -(pixdx*xwsize/viewport[2] + eyedx*nnear/focus);
75
+ dy = -(pixdy*ywsize/viewport[3] + eyedy*nnear/focus);
76
+
77
+ GL::MatrixMode(GL::PROJECTION);
78
+ GL::LoadIdentity();
79
+ GL::Frustum(left + dx, right + dx, bottom + dy, top + dy, nnear, ffar);
80
+ GL::MatrixMode(GL::MODELVIEW);
81
+ GL::LoadIdentity();
82
+ GL::Translate(-eyedx, -eyedy, 0.0);
83
+ end
84
+
85
+ #/* accPerspective()
86
+ # *
87
+ # * The first 4 arguments are identical to the gluPerspective() call.
88
+ # * pixdx and pixdy are anti-alias jitter in pixels.
89
+ # * Set both equal to 0.0 for no anti-alias jitter.
90
+ # * eyedx and eyedy are depth-of field jitter in pixels.
91
+ # * Set both equal to 0.0 for no depth of field effects.
92
+ # *
93
+ # * focus is distance from eye to plane in focus.
94
+ # * focus must be greater than, but not equal to 0.0.
95
+ # *
96
+ # * Note that accPerspective() calls accFrustum().
97
+ # */
98
+ def accPerspective(fovy, aspect, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
99
+ fov2 = ((fovy*PI_) / 180.0) / 2.0;
100
+
101
+ top = nnear / (Math::cos(fov2) / Math::sin(fov2));
102
+ bottom = -top;
103
+
104
+ right = top * aspect;
105
+ left = -right;
106
+
107
+ accFrustum(left, right, bottom, top, nnear, ffar,
108
+ pixdx, pixdy, eyedx, eyedy, focus);
109
+ end
110
+
111
+ #/* Initialize lighting and other values.
112
+ # */
113
+ def init
114
+ mat_ambient = [ 1.0, 1.0, 1.0, 1.0 ];
115
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ];
116
+ light_position = [ 0.0, 0.0, 10.0, 1.0 ];
117
+ lm_ambient = [ 0.2, 0.2, 0.2, 1.0 ];
118
+
119
+ GL::Material(GL::FRONT, GL::AMBIENT, mat_ambient);
120
+ GL::Material(GL::FRONT, GL::SPECULAR, mat_specular);
121
+ GL::Material(GL::FRONT, GL::SHININESS, 50.0);
122
+ GL::Light(GL::LIGHT0, GL::POSITION, light_position);
123
+ GL::LightModel(GL::LIGHT_MODEL_AMBIENT, lm_ambient);
124
+
125
+ GL::Enable(GL::LIGHTING);
126
+ GL::Enable(GL::LIGHT0);
127
+ GL::Enable(GL::DEPTH_TEST);
128
+ GL::ShadeModel(GL::FLAT);
129
+
130
+ GL::ClearColor(0.0, 0.0, 0.0, 0.0);
131
+ GL::ClearAccum(0.0, 0.0, 0.0, 0.0);
132
+ end
133
+
134
+ def displayObjects
135
+ torus_diffuse = [ 0.7, 0.7, 0.0, 1.0 ];
136
+ cube_diffuse = [ 0.0, 0.7, 0.7, 1.0 ];
137
+ sphere_diffuse = [ 0.7, 0.0, 0.7, 1.0 ];
138
+ octa_diffuse = [ 0.7, 0.4, 0.4, 1.0 ];
139
+
140
+ GL::PushMatrix();
141
+ GL::Translate(0.0, 0.0, -5.0);
142
+ GL::Rotate(30.0, 1.0, 0.0, 0.0);
143
+
144
+ GL::PushMatrix();
145
+ GL::Translate(-0.80, 0.35, 0.0);
146
+ GL::Rotate(100.0, 1.0, 0.0, 0.0);
147
+ GL::Material(GL::FRONT, GL::DIFFUSE, torus_diffuse);
148
+ GLUT::SolidTorus(0.275, 0.85, 16, 16);
149
+ GL::PopMatrix();
150
+
151
+ GL::PushMatrix();
152
+ GL::Translate(-0.75, -0.50, 0.0);
153
+ GL::Rotate(45.0, 0.0, 0.0, 1.0);
154
+ GL::Rotate(45.0, 1.0, 0.0, 0.0);
155
+ GL::Material(GL::FRONT, GL::DIFFUSE, cube_diffuse);
156
+ GLUT::SolidCube(1.5);
157
+ GL::PopMatrix();
158
+
159
+ GL::PushMatrix();
160
+ GL::Translate(0.75, 0.60, 0.0);
161
+ GL::Rotate(30.0, 1.0, 0.0, 0.0);
162
+ GL::Material(GL::FRONT, GL::DIFFUSE, sphere_diffuse);
163
+ GLUT::SolidSphere(1.0, 16, 16);
164
+ GL::PopMatrix();
165
+
166
+ GL::PushMatrix();
167
+ GL::Translate(0.70, -0.90, 0.25);
168
+ GL::Material(GL::FRONT, GL::DIFFUSE, octa_diffuse);
169
+ GLUT::SolidOctahedron();
170
+ GL::PopMatrix();
171
+
172
+ GL::PopMatrix();
173
+ end
174
+
175
+ ACSIZE=8
176
+
177
+ display = proc {
178
+ viewport = GL::GetDoublev(GL::VIEWPORT);
179
+
180
+ GL::Clear(GL::ACCUM_BUFFER_BIT);
181
+ for jitter in 0...ACSIZE
182
+ GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
183
+ accPerspective(50.0, viewport[2]/ viewport[3],
184
+ 1.0, 15.0, $j8[jitter][0], $j8[jitter][1], 0.0, 0.0, 1.0);
185
+ displayObjects();
186
+ GL::Accum(GL::ACCUM, 1.0/ACSIZE);
187
+ end
188
+ GL::Accum(GL::RETURN, 1.0);
189
+ GL::Flush();
190
+ }
191
+
192
+ reshape = proc {|w, h|
193
+ GL::Viewport(0, 0, w, h);
194
+ }
195
+
196
+ # /* ARGSUSED1 */
197
+ keyboard = proc {|key, x, y|
198
+ case (key)
199
+ when 27
200
+ exit(0);
201
+ end
202
+ }
203
+
204
+ #/* Main Loop
205
+ # * Be certain you request an accumulation buffer.
206
+ # */
207
+ GLUT.Init
208
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::ACCUM | GLUT::DEPTH);
209
+ GLUT::InitWindowSize(250, 250);
210
+ GLUT::InitWindowPosition(100, 100);
211
+ GLUT::CreateWindow($0)
212
+ init();
213
+ GLUT::ReshapeFunc(reshape);
214
+ GLUT::DisplayFunc(display);
215
+ GLUT::KeyboardFunc(keyboard);
216
+ GLUT::MainLoop();
@@ -0,0 +1,133 @@
1
+ #/*
2
+ # * Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
+ # * ALL RIGHTS RESERVED
4
+ # * Permission to use, copy, modify, and distribute this software for
5
+ # * any purpose and without fee is hereby granted, provided that the above
6
+ # * copyright notice appear in all copies and that both the copyright notice
7
+ # * and this permission notice appear in supporting documentation, and that
8
+ # * the name of Silicon Graphics, Inc. not be used in advertising
9
+ # * or publicity pertaining to distribution of the software without specific,
10
+ # * written prior permission.
11
+ # *
12
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
+ # *
25
+ # * US Government Users Restricted Rights
26
+ # * Use, duplication, or disclosure by the Government is subject to
27
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
30
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
31
+ # * Unpublished-- rights reserved under the copyright laws of the
32
+ # * United States. Contractor/manufacturer is Silicon Graphics,
33
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
+ # *
35
+ # * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
+ # */
37
+ #
38
+ #/*
39
+ # * alpha.c
40
+ # * This program draws several overlapping filled polygons
41
+ # * to demonstrate the effect order has on alpha blending results.
42
+ # * Use the 't' key to toggle the order of drawing polygons.
43
+ # */
44
+
45
+ require "gl_prev"
46
+ require "glu_prev"
47
+ require "glut_prev"
48
+ require "mathn"
49
+
50
+ $leftFirst = GL::TRUE;
51
+
52
+ #/* Initialize alpha blending function.
53
+ # */
54
+ def init
55
+ GL.Enable(GL::BLEND);
56
+ GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA);
57
+ GL.ShadeModel(GL::FLAT);
58
+ GL.ClearColor(0.0, 0.0, 0.0, 0.0);
59
+ end
60
+
61
+ def drawLeftTriangle
62
+ #/* draw yellow triangle on LHS of screen */
63
+
64
+ GL.Begin(GL::TRIANGLES);
65
+ GL.Color(1.0, 1.0, 0.0, 0.75);
66
+ GL.Vertex(0.1, 0.9, 0.0);
67
+ GL.Vertex(0.1, 0.1, 0.0);
68
+ GL.Vertex(0.7, 0.5, 0.0);
69
+ GL.End();
70
+ end
71
+
72
+ def drawRightTriangle
73
+ #/* draw cyan triangle on RHS of screen */
74
+
75
+ GL.Begin(GL::TRIANGLES);
76
+ GL.Color(0.0, 1.0, 1.0, 0.75);
77
+ GL.Vertex(0.9, 0.9, 0.0);
78
+ GL.Vertex(0.3, 0.5, 0.0);
79
+ GL.Vertex(0.9, 0.1, 0.0);
80
+ GL.End();
81
+ end
82
+
83
+ display = Proc.new {
84
+ GL.Clear(GL::COLOR_BUFFER_BIT);
85
+
86
+ if ($leftFirst)
87
+ drawLeftTriangle();
88
+ drawRightTriangle();
89
+ else
90
+ drawRightTriangle();
91
+ drawLeftTriangle();
92
+ end
93
+
94
+ GL.Flush();
95
+ }
96
+
97
+ reshape = Proc.new {|w, h|
98
+ GL.Viewport(0, 0, w, h);
99
+ GL.MatrixMode(GL::PROJECTION);
100
+ GL.LoadIdentity();
101
+ if (w <= h)
102
+ GLU.Ortho2D(0.0, 1.0, 0.0, 1.0*h/w);
103
+ else
104
+ GLU.Ortho2D(0.0, 1.0*w/h, 0.0, 1.0);
105
+ end
106
+ }
107
+
108
+ # /* ARGSUSED1 */
109
+ keyboard = Proc.new {|key, x, y|
110
+ case (key)
111
+ when 't'[0],'T'[0]
112
+ $leftFirst = !$leftFirst;
113
+ GLUT.PostRedisplay();
114
+ when 27 # /* Escape key */
115
+ exit(0);
116
+ end
117
+ }
118
+
119
+ #/* Main Loop
120
+ # * Open window with initial window size, title bar,
121
+ # * RGBA display mode, and handle input events.
122
+ # */
123
+ #int main(int argc, char** argv)
124
+ #{
125
+ GLUT.Init
126
+ GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB);
127
+ GLUT.InitWindowSize(200, 200);
128
+ GLUT.CreateWindow($0);
129
+ init();
130
+ GLUT.ReshapeFunc(reshape);
131
+ GLUT.KeyboardFunc(keyboard);
132
+ GLUT.DisplayFunc(display);
133
+ GLUT.MainLoop();
@@ -0,0 +1,165 @@
1
+ #/*
2
+ # * Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
+ # * ALL RIGHTS RESERVED
4
+ # * Permission to use, copy, modify, and distribute this software for
5
+ # * any purpose and without fee is hereby granted, provided that the above
6
+ # * copyright notice appear in all copies and that both the copyright notice
7
+ # * and this permission notice appear in supporting documentation, and that
8
+ # * the name of Silicon Graphics, Inc. not be used in advertising
9
+ # * or publicity pertaining to distribution of the software without specific,
10
+ # * written prior permission.
11
+ # *
12
+ # * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
+ # * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14
+ # * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15
+ # * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16
+ # * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17
+ # * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18
+ # * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19
+ # * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20
+ # * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21
+ # * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
+ # * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
+ # * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
+ # *
25
+ # * US Government Users Restricted Rights
26
+ # * Use, duplication, or disclosure by the Government is subject to
27
+ # * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
+ # * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29
+ # * clause at DFARS 252.227-7013 and/or in similar or successor
30
+ # * clauses in the FAR or the DOD or NASA FAR Supplement.
31
+ # * Unpublished-- rights reserved under the copyright laws of the
32
+ # * United States. Contractor/manufacturer is Silicon Graphics,
33
+ # * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
+ # *
35
+ # * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
+ # */
37
+ #
38
+ #/*
39
+ # * alpha3D.c
40
+ # * This program demonstrates how to intermix opaque and
41
+ # * alpha blended polygons in the same scene, by using
42
+ # * glDepthMask. Press the 'a' key to animate moving the
43
+ # * transparent object through the opaque object. Press
44
+ # * the 'r' key to reset the scene.
45
+ # */
46
+ require "gl_prev"
47
+ require "glu_prev"
48
+ require "glut_prev"
49
+
50
+
51
+ MAXZ=8.0
52
+ MINZ=-8.0
53
+ ZINC=0.4
54
+
55
+ $solidZ = MAXZ;
56
+ $transparentZ = MINZ;
57
+ $sphereList=nil
58
+ $cubeList=nil
59
+
60
+ def init
61
+ mat_specular = [ 1.0, 1.0, 1.0, 0.15 ];
62
+ mat_shininess = [ 100.0 ];
63
+ position = [ 0.5, 0.5, 1.0, 0.0 ];
64
+
65
+ GL::Material(GL::FRONT, GL::SPECULAR, mat_specular);
66
+ GL::Material(GL::FRONT, GL::SHININESS, mat_shininess);
67
+ GL::Light(GL::LIGHT0, GL::POSITION, position);
68
+
69
+ GL::Enable(GL::LIGHTING);
70
+ GL::Enable(GL::LIGHT0);
71
+ GL::Enable(GL::DEPTH_TEST);
72
+
73
+ $sphereList = GL::GenLists(1);
74
+ GL::NewList($sphereList, GL::COMPILE);
75
+ GLUT::SolidSphere(0.4, 16, 16);
76
+ GL::EndList();
77
+
78
+ $cubeList = GL::GenLists(1);
79
+ GL::NewList($cubeList, GL::COMPILE);
80
+ GLUT::SolidCube(0.6);
81
+ GL::EndList();
82
+ end
83
+
84
+ display = proc {
85
+ mat_solid = [ 0.75, 0.75, 0.0, 1.0 ];
86
+ mat_zero = [ 0.0, 0.0, 0.0, 1.0 ];
87
+ mat_transparent = [ 0.0, 0.8, 0.8, 0.6 ];
88
+ mat_emission = [ 0.0, 0.3, 0.3, 0.6 ];
89
+
90
+ GL::Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT);
91
+
92
+ GL::PushMatrix();
93
+ GL::Translate(-0.15, -0.15, $solidZ);
94
+ GL::Material(GL::FRONT, GL::EMISSION, mat_zero);
95
+ GL::Material(GL::FRONT, GL::DIFFUSE, mat_solid);
96
+ GL::CallList($sphereList);
97
+ GL::PopMatrix();
98
+
99
+ GL::PushMatrix();
100
+ GL::Translate(0.15, 0.15, $transparentZ);
101
+ GL::Rotate(15.0, 1.0, 1.0, 0.0);
102
+ GL::Rotate(30.0, 0.0, 1.0, 0.0);
103
+ GL::Material(GL::FRONT, GL::EMISSION, mat_emission);
104
+ GL::Material(GL::FRONT, GL::DIFFUSE, mat_transparent);
105
+ GL::Enable(GL::BLEND);
106
+ GL::DepthMask(GL::FALSE);
107
+ GL::BlendFunc(GL::SRC_ALPHA, GL::ONE);
108
+ GL::CallList($cubeList);
109
+ GL::DepthMask(GL::TRUE);
110
+ GL::Disable(GL::BLEND);
111
+ GL::PopMatrix();
112
+
113
+ GL::Flush();
114
+ }
115
+
116
+ reshape = proc {|w, h|
117
+ GL::Viewport(0, 0, w, h);
118
+ GL::MatrixMode(GL::PROJECTION);
119
+ GL::LoadIdentity();
120
+ if (w <= h)
121
+ GL::Ortho(-1.5, 1.5, -1.5*h.to_f/w,
122
+ 1.5*h.to_f/w, -10.0, 10.0);
123
+ else
124
+ GL::Ortho(-1.5*w.to_f/h,
125
+ 1.5*w.to_f/h, -1.5, 1.5, -10.0, 10.0);
126
+ end
127
+ GL::MatrixMode(GL::MODELVIEW);
128
+ GL::LoadIdentity();
129
+ }
130
+
131
+ animate = proc {
132
+ if ($solidZ <= MINZ || $transparentZ >= MAXZ)
133
+ GLUT::IdleFunc(nil);
134
+ else
135
+ $solidZ -= ZINC;
136
+ $transparentZ += ZINC;
137
+ GLUT::PostRedisplay();
138
+ end
139
+ }
140
+
141
+ # /* ARGSUSED1 */
142
+ keyboard = proc {|key, x, y|
143
+ case (key)
144
+ when ?a,?A
145
+ $solidZ = MAXZ;
146
+ $transparentZ = MINZ;
147
+ GLUT::IdleFunc(animate);
148
+ when ?r, ?R
149
+ $solidZ = MAXZ;
150
+ $transparentZ = MINZ;
151
+ GLUT::PostRedisplay();
152
+ when 27
153
+ exit(0);
154
+ end
155
+ }
156
+
157
+ GLUT::Init()
158
+ GLUT::InitDisplayMode(GLUT::SINGLE | GLUT::RGB | GLUT::DEPTH);
159
+ GLUT::InitWindowSize(500, 500);
160
+ GLUT::CreateWindow($0)
161
+ init();
162
+ GLUT::ReshapeFunc(reshape);
163
+ GLUT::KeyboardFunc(keyboard);
164
+ GLUT::DisplayFunc(display);
165
+ GLUT::MainLoop();