opengl 0.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +29 -0
  5. data/.gemtest +0 -0
  6. data/.gitignore +6 -0
  7. data/.travis.yml +19 -0
  8. data/History.rdoc +77 -0
  9. data/MIT-LICENSE +18 -0
  10. data/Manifest.txt +138 -0
  11. data/README.rdoc +102 -0
  12. data/Rakefile +60 -0
  13. data/examples/NeHe/NeHe.png +0 -0
  14. data/examples/NeHe/crate.png +0 -0
  15. data/examples/NeHe/glass.png +0 -0
  16. data/examples/NeHe/nehe_lesson02.rb +117 -0
  17. data/examples/NeHe/nehe_lesson03.rb +123 -0
  18. data/examples/NeHe/nehe_lesson04.rb +132 -0
  19. data/examples/NeHe/nehe_lesson05.rb +182 -0
  20. data/examples/NeHe/nehe_lesson06.rb +186 -0
  21. data/examples/NeHe/nehe_lesson07.rb +240 -0
  22. data/examples/NeHe/nehe_lesson08.rb +255 -0
  23. data/examples/NeHe/nehe_lesson09.rb +203 -0
  24. data/examples/NeHe/nehe_lesson11.rb +176 -0
  25. data/examples/NeHe/nehe_lesson12.rb +203 -0
  26. data/examples/NeHe/nehe_lesson16.rb +211 -0
  27. data/examples/NeHe/nehe_lesson19.rb +209 -0
  28. data/examples/NeHe/nehe_lesson36.rb +308 -0
  29. data/examples/NeHe/particle.png +0 -0
  30. data/examples/NeHe/star.png +0 -0
  31. data/examples/NeHe/tim.png +0 -0
  32. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  33. data/examples/OrangeBook/brick.frag +36 -0
  34. data/examples/OrangeBook/brick.rb +378 -0
  35. data/examples/OrangeBook/brick.vert +41 -0
  36. data/examples/OrangeBook/particle.frag +17 -0
  37. data/examples/OrangeBook/particle.rb +408 -0
  38. data/examples/OrangeBook/particle.vert +38 -0
  39. data/examples/README +16 -0
  40. data/examples/RedBook/aapoly.rb +143 -0
  41. data/examples/RedBook/aargb.rb +121 -0
  42. data/examples/RedBook/accanti.rb +164 -0
  43. data/examples/RedBook/accpersp.rb +217 -0
  44. data/examples/RedBook/alpha.rb +125 -0
  45. data/examples/RedBook/alpha3D.rb +160 -0
  46. data/examples/RedBook/bezcurve.rb +107 -0
  47. data/examples/RedBook/bezmesh.rb +139 -0
  48. data/examples/RedBook/checker.rb +126 -0
  49. data/examples/RedBook/clip.rb +97 -0
  50. data/examples/RedBook/colormat.rb +137 -0
  51. data/examples/RedBook/cube.rb +71 -0
  52. data/examples/RedBook/depthcue.rb +101 -0
  53. data/examples/RedBook/dof.rb +206 -0
  54. data/examples/RedBook/double.rb +107 -0
  55. data/examples/RedBook/drawf.rb +93 -0
  56. data/examples/RedBook/feedback.rb +147 -0
  57. data/examples/RedBook/fog.rb +168 -0
  58. data/examples/RedBook/font.rb +153 -0
  59. data/examples/RedBook/hello.rb +81 -0
  60. data/examples/RedBook/image.rb +139 -0
  61. data/examples/RedBook/jitter.rb +207 -0
  62. data/examples/RedBook/light.rb +155 -0
  63. data/examples/RedBook/lines.rb +130 -0
  64. data/examples/RedBook/list.rb +113 -0
  65. data/examples/RedBook/material.rb +276 -0
  66. data/examples/RedBook/mipmap.rb +158 -0
  67. data/examples/RedBook/model.rb +115 -0
  68. data/examples/RedBook/movelight.rb +134 -0
  69. data/examples/RedBook/pickdepth.rb +181 -0
  70. data/examples/RedBook/planet.rb +110 -0
  71. data/examples/RedBook/quadric.rb +160 -0
  72. data/examples/RedBook/robot.rb +117 -0
  73. data/examples/RedBook/select.rb +198 -0
  74. data/examples/RedBook/smooth.rb +97 -0
  75. data/examples/RedBook/stencil.rb +165 -0
  76. data/examples/RedBook/stroke.rb +169 -0
  77. data/examples/RedBook/surface.rb +168 -0
  78. data/examples/RedBook/teaambient.rb +134 -0
  79. data/examples/RedBook/teapots.rb +184 -0
  80. data/examples/RedBook/tess.rb +185 -0
  81. data/examples/RedBook/texbind.rb +149 -0
  82. data/examples/RedBook/texgen.rb +171 -0
  83. data/examples/RedBook/texturesurf.rb +130 -0
  84. data/examples/RedBook/varray.rb +161 -0
  85. data/examples/RedBook/wrap.rb +150 -0
  86. data/examples/misc/OGLBench.rb +338 -0
  87. data/examples/misc/anisotropic.rb +196 -0
  88. data/examples/misc/fbo_test.rb +357 -0
  89. data/examples/misc/font-glut.rb +47 -0
  90. data/examples/misc/glfwtest.rb +30 -0
  91. data/examples/misc/plane.rb +161 -0
  92. data/examples/misc/readpixel.rb +66 -0
  93. data/examples/misc/sdltest.rb +36 -0
  94. data/examples/misc/trislam.rb +829 -0
  95. data/ext/opengl/common.h +428 -0
  96. data/ext/opengl/conv.h +244 -0
  97. data/ext/opengl/extconf.rb +47 -0
  98. data/ext/opengl/funcdef.h +313 -0
  99. data/ext/opengl/gl-1.0-1.1.c +3075 -0
  100. data/ext/opengl/gl-1.2.c +155 -0
  101. data/ext/opengl/gl-1.3.c +443 -0
  102. data/ext/opengl/gl-1.4.c +348 -0
  103. data/ext/opengl/gl-1.5.c +224 -0
  104. data/ext/opengl/gl-2.0.c +667 -0
  105. data/ext/opengl/gl-2.1.c +57 -0
  106. data/ext/opengl/gl-3.0.c +493 -0
  107. data/ext/opengl/gl-enums.c +4873 -0
  108. data/ext/opengl/gl-enums.h +14588 -0
  109. data/ext/opengl/gl-error.c +112 -0
  110. data/ext/opengl/gl-error.h +28 -0
  111. data/ext/opengl/gl-ext-3dfx.c +27 -0
  112. data/ext/opengl/gl-ext-arb.c +875 -0
  113. data/ext/opengl/gl-ext-ati.c +41 -0
  114. data/ext/opengl/gl-ext-ext.c +889 -0
  115. data/ext/opengl/gl-ext-gremedy.c +41 -0
  116. data/ext/opengl/gl-ext-nv.c +680 -0
  117. data/ext/opengl/gl-types.h +67 -0
  118. data/ext/opengl/gl.c +220 -0
  119. data/ext/opengl/gl_buffer.c +177 -0
  120. data/ext/opengl/opengl.c +7 -0
  121. data/lib/gl.rb +1 -0
  122. data/lib/opengl.rb +53 -0
  123. data/lib/opengl/2.0/opengl.so +0 -0
  124. data/lib/opengl/2.1/opengl.so +0 -0
  125. data/lib/opengl/test_case.rb +86 -0
  126. data/test/dummy.xorg.conf +140 -0
  127. data/test/test_gl.rb +38 -0
  128. data/test/test_gl_10_11.rb +1363 -0
  129. data/test/test_gl_12.rb +71 -0
  130. data/test/test_gl_13.rb +221 -0
  131. data/test/test_gl_14.rb +218 -0
  132. data/test/test_gl_15.rb +258 -0
  133. data/test/test_gl_20.rb +417 -0
  134. data/test/test_gl_21.rb +436 -0
  135. data/test/test_gl_ext_arb.rb +508 -0
  136. data/test/test_gl_ext_ati.rb +28 -0
  137. data/test/test_gl_ext_ext.rb +608 -0
  138. data/test/test_gl_ext_gremedy.rb +29 -0
  139. data/test/test_gl_ext_nv.rb +349 -0
  140. data/test/test_opengl_buffer.rb +120 -0
  141. data/utils/README +6 -0
  142. data/utils/enumgen.rb +108 -0
  143. data/utils/extlistgen.rb +90 -0
  144. metadata +319 -0
  145. metadata.gz.sig +1 -0
@@ -0,0 +1,217 @@
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
+ # accpersp.c
38
+ # Use the accumulation buffer to do full-scene antialiasing
39
+ # on a scene with perspective projection, using the special
40
+ # routines accFrustum() and accPerspective().
41
+
42
+ require 'opengl'
43
+ require 'glu'
44
+ require 'glut'
45
+ include Gl,Glu,Glut
46
+
47
+ $j8 = [
48
+ [-0.334818, 0.435331],
49
+ [ 0.286438, -0.393495],
50
+ [ 0.459462, 0.141540],
51
+ [-0.414498, -0.192829],
52
+ [-0.183790, 0.082102],
53
+ [-0.079263, -0.317383],
54
+ [ 0.102254, 0.299133],
55
+ [ 0.164216, -0.054399]
56
+ ]
57
+
58
+ # accFrustum()
59
+ # The first 6 arguments are identical to the glFrustum() call.
60
+ #
61
+ # pixdx and pixdy are anti-alias jitter in pixels.
62
+ # Set both equal to 0.0 for no anti-alias jitter.
63
+ # eyedx and eyedy are depth-of field jitter in pixels.
64
+ # Set both equal to 0.0 for no depth of field effects.
65
+ #
66
+ # focus is distance from eye to plane in focus.
67
+ # focus must be greater than, but not equal to 0.0.
68
+ #
69
+ # Note that accFrustum() calls glTranslatef(). You will
70
+ # probably want to insure that your ModelView matrix has been
71
+ # initialized to identity before calling accFrustum().
72
+
73
+ def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
74
+ viewport = glGetDoublev(GL_VIEWPORT)
75
+
76
+ xwsize = right - left
77
+ ywsize = top - bottom
78
+
79
+ dx = -(pixdx*xwsize/viewport[2] + eyedx*nnear/focus)
80
+ dy = -(pixdy*ywsize/viewport[3] + eyedy*nnear/focus)
81
+
82
+ glMatrixMode(GL_PROJECTION)
83
+ glLoadIdentity()
84
+ glFrustum(left + dx, right + dx, bottom + dy, top + dy, nnear, ffar)
85
+ glMatrixMode(GL_MODELVIEW)
86
+ glLoadIdentity()
87
+ glTranslate(-eyedx, -eyedy, 0.0)
88
+ end
89
+
90
+ # accPerspective()
91
+ #
92
+ # The first 4 arguments are identical to the gluPerspective() call.
93
+ # pixdx and pixdy are anti-alias jitter in pixels.
94
+ # Set both equal to 0.0 for no anti-alias jitter.
95
+ # eyedx and eyedy are depth-of field jitter in pixels.
96
+ # Set both equal to 0.0 for no depth of field effects.
97
+ #
98
+ # focus is distance from eye to plane in focus.
99
+ # focus must be greater than, but not equal to 0.0.
100
+ #
101
+ # Note that accPerspective() calls accFrustum().
102
+
103
+ def accPerspective(fovy, aspect, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
104
+ fov2 = ((fovy*Math::PI) / 180.0) / 2.0
105
+
106
+ top = nnear / (Math::cos(fov2) / Math::sin(fov2))
107
+ bottom = -top
108
+
109
+ right = top * aspect
110
+ left = -right
111
+
112
+ accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
113
+ end
114
+
115
+ # Initialize lighting and other values.
116
+ def init
117
+ mat_ambient = [ 1.0, 1.0, 1.0, 1.0 ]
118
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
119
+ light_position = [ 0.0, 0.0, 10.0, 1.0 ]
120
+ lm_ambient = [ 0.2, 0.2, 0.2, 1.0 ]
121
+
122
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
123
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
124
+ glMaterial(GL_FRONT, GL_SHININESS, 50.0)
125
+ glLight(GL_LIGHT0, GL_POSITION, light_position)
126
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, lm_ambient)
127
+
128
+ glEnable(GL_LIGHTING)
129
+ glEnable(GL_LIGHT0)
130
+ glEnable(GL_DEPTH_TEST)
131
+ glShadeModel(GL_FLAT)
132
+
133
+ glClearColor(0.0, 0.0, 0.0, 0.0)
134
+ glClearAccum(0.0, 0.0, 0.0, 0.0)
135
+ end
136
+
137
+ def displayObjects
138
+ torus_diffuse = [ 0.7, 0.7, 0.0, 1.0 ]
139
+ cube_diffuse = [ 0.0, 0.7, 0.7, 1.0 ]
140
+ sphere_diffuse = [ 0.7, 0.0, 0.7, 1.0 ]
141
+ octa_diffuse = [ 0.7, 0.4, 0.4, 1.0 ]
142
+
143
+ glPushMatrix()
144
+ glTranslate(0.0, 0.0, -5.0)
145
+ glRotate(30.0, 1.0, 0.0, 0.0)
146
+
147
+ glPushMatrix()
148
+ glTranslate(-0.80, 0.35, 0.0)
149
+ glRotate(100.0, 1.0, 0.0, 0.0)
150
+ glMaterial(GL_FRONT, GL_DIFFUSE, torus_diffuse)
151
+ glutSolidTorus(0.275, 0.85, 16, 16)
152
+ glPopMatrix()
153
+
154
+ glPushMatrix()
155
+ glTranslate(-0.75, -0.50, 0.0)
156
+ glRotate(45.0, 0.0, 0.0, 1.0)
157
+ glRotate(45.0, 1.0, 0.0, 0.0)
158
+ glMaterial(GL_FRONT, GL_DIFFUSE, cube_diffuse)
159
+ glutSolidCube(1.5)
160
+ glPopMatrix()
161
+
162
+ glPushMatrix()
163
+ glTranslate(0.75, 0.60, 0.0)
164
+ glRotate(30.0, 1.0, 0.0, 0.0)
165
+ glMaterial(GL_FRONT, GL_DIFFUSE, sphere_diffuse)
166
+ glutSolidSphere(1.0, 16, 16)
167
+ glPopMatrix()
168
+
169
+ glPushMatrix()
170
+ glTranslate(0.70, -0.90, 0.25)
171
+ glMaterial(GL_FRONT, GL_DIFFUSE, octa_diffuse)
172
+ glutSolidOctahedron()
173
+ glPopMatrix()
174
+
175
+ glPopMatrix()
176
+ end
177
+
178
+ ACSIZE=8
179
+
180
+ display = proc do
181
+ viewport = glGetDoublev(GL_VIEWPORT)
182
+
183
+ glClear(GL_ACCUM_BUFFER_BIT)
184
+ for jitter in 0...ACSIZE
185
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
186
+ accPerspective(50.0, viewport[2]/ viewport[3], 1.0, 15.0, $j8[jitter][0], $j8[jitter][1], 0.0, 0.0, 1.0)
187
+ displayObjects()
188
+ glAccum(GL_ACCUM, 1.0/ACSIZE)
189
+ end
190
+ glAccum(GL_RETURN, 1.0)
191
+ glutSwapBuffers()
192
+ end
193
+
194
+ reshape = proc do |w, h|
195
+ glViewport(0, 0, w, h)
196
+ end
197
+
198
+ keyboard = proc do |key, x, y|
199
+ case (key)
200
+ when ?\e
201
+ exit(0)
202
+ end
203
+ end
204
+
205
+ # Main Loop
206
+ # Be certain you request an accumulation buffer.
207
+
208
+ glutInit()
209
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ACCUM | GLUT_DEPTH)
210
+ glutInitWindowSize(500, 500)
211
+ glutInitWindowPosition(100, 100)
212
+ glutCreateWindow($0)
213
+ init()
214
+ glutReshapeFunc(reshape)
215
+ glutDisplayFunc(display)
216
+ glutKeyboardFunc(keyboard)
217
+ glutMainLoop()
@@ -0,0 +1,125 @@
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
+ # alpha.c
38
+ # This program draws several overlapping filled polygons
39
+ # to demonstrate the effect order has on alpha blending results.
40
+ # Use the 't' key to toggle the order of drawing polygons.
41
+ require 'opengl'
42
+ require 'glu'
43
+ require 'glut'
44
+ require 'mathn'
45
+ include Gl,Glu,Glut
46
+
47
+ $leftFirst = GL_TRUE
48
+
49
+ # Initialize alpha blending function.
50
+ def init
51
+ glEnable(GL_BLEND)
52
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
53
+ glShadeModel(GL_FLAT)
54
+ glClearColor(0.0, 0.0, 0.0, 0.0)
55
+ end
56
+
57
+ def drawLeftTriangle
58
+ # draw yellow triangle on LHS of screen
59
+
60
+ glBegin(GL_TRIANGLES)
61
+ glColor(1.0, 1.0, 0.0, 0.75)
62
+ glVertex(0.1, 0.9, 0.0)
63
+ glVertex(0.1, 0.1, 0.0)
64
+ glVertex(0.7, 0.5, 0.0)
65
+ glEnd()
66
+ end
67
+
68
+ def drawRightTriangle
69
+ # draw cyan triangle on RHS of screen
70
+
71
+ glBegin(GL_TRIANGLES)
72
+ glColor(0.0, 1.0, 1.0, 0.75)
73
+ glVertex(0.9, 0.9, 0.0)
74
+ glVertex(0.3, 0.5, 0.0)
75
+ glVertex(0.9, 0.1, 0.0)
76
+ glEnd()
77
+ end
78
+
79
+ display = Proc.new do
80
+ glClear(GL_COLOR_BUFFER_BIT)
81
+
82
+ if ($leftFirst)
83
+ drawLeftTriangle()
84
+ drawRightTriangle()
85
+ else
86
+ drawRightTriangle()
87
+ drawLeftTriangle()
88
+ end
89
+ glutSwapBuffers()
90
+ end
91
+
92
+ reshape = Proc.new do |w, h|
93
+ glViewport(0, 0, w, h)
94
+ glMatrixMode(GL_PROJECTION)
95
+ glLoadIdentity()
96
+ if (w <= h)
97
+ gluOrtho2D(0.0, 1.0, 0.0, 1.0*h/w)
98
+ else
99
+ gluOrtho2D(0.0, 1.0*w/h, 0.0, 1.0)
100
+ end
101
+ end
102
+
103
+ keyboard = Proc.new do|key, x, y|
104
+ case (key)
105
+ when ?t,?T
106
+ $leftFirst = !$leftFirst
107
+ glutPostRedisplay()
108
+ when ?\e # Escape key
109
+ exit(0)
110
+ end
111
+ end
112
+
113
+ # Main Loop
114
+ # Open window with initial window size, title bar,
115
+ # RGBA display mode, and handle input events.
116
+ glutInit
117
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
118
+ glutInitWindowSize(500, 500)
119
+ glutInitWindowPosition(100, 100)
120
+ glutCreateWindow($0)
121
+ init()
122
+ glutReshapeFunc(reshape)
123
+ glutKeyboardFunc(keyboard)
124
+ glutDisplayFunc(display)
125
+ glutMainLoop()
@@ -0,0 +1,160 @@
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
+ # alpha3D.c
38
+ # This program demonstrates how to intermix opaque and
39
+ # alpha blended polygons in the same scene, by using
40
+ # glDepthMask. Press the 'a' key to animate moving the
41
+ # transparent object through the opaque object. Press
42
+ # the 'r' key to reset the scene.
43
+ require 'opengl'
44
+ require 'glu'
45
+ require 'glut'
46
+ include Gl,Glu,Glut
47
+
48
+ MAXZ=1.0
49
+ MINZ=-2.0
50
+ ZINC=0.1
51
+
52
+ $solidZ = MAXZ
53
+ $transparentZ = MINZ
54
+ $sphereList=nil
55
+ $cubeList=nil
56
+
57
+ def init
58
+ mat_specular = [ 1.0, 1.0, 1.0, 0.15 ]
59
+ mat_shininess = [ 100.0 ]
60
+ position = [ 0.5, 0.5, 1.0, 0.0 ]
61
+
62
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
63
+ glMaterial(GL_FRONT, GL_SHININESS, mat_shininess)
64
+ glLight(GL_LIGHT0, GL_POSITION, position)
65
+
66
+ glEnable(GL_LIGHTING)
67
+ glEnable(GL_LIGHT0)
68
+ glEnable(GL_DEPTH_TEST)
69
+
70
+ $sphereList = glGenLists(1)
71
+ glNewList($sphereList, GL_COMPILE)
72
+ glutSolidSphere(0.4, 16, 16)
73
+ glEndList()
74
+
75
+ $cubeList = glGenLists(1)
76
+ glNewList($cubeList, GL_COMPILE)
77
+ glutSolidCube(0.6)
78
+ glEndList()
79
+ end
80
+
81
+ display = proc do
82
+ mat_solid = [ 0.75, 0.75, 0.0, 1.0 ]
83
+ mat_zero = [ 0.0, 0.0, 0.0, 1.0 ]
84
+ mat_transparent = [ 0.0, 0.8, 0.8, 0.6 ]
85
+ mat_emission = [ 0.0, 0.3, 0.3, 0.6 ]
86
+
87
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
88
+
89
+ glPushMatrix()
90
+ glTranslate(-0.15, -0.15, $solidZ)
91
+ glMaterial(GL_FRONT, GL_EMISSION, mat_zero)
92
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_solid)
93
+ glCallList($sphereList)
94
+ glPopMatrix()
95
+
96
+ glPushMatrix()
97
+ glTranslate(0.15, 0.15, $transparentZ)
98
+ glRotate(15.0, 1.0, 1.0, 0.0)
99
+ glRotate(30.0, 0.0, 1.0, 0.0)
100
+ glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
101
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_transparent)
102
+ glEnable(GL_BLEND)
103
+ glDepthMask(GL_FALSE)
104
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE)
105
+ glCallList($cubeList)
106
+ glDepthMask(GL_TRUE)
107
+ glDisable(GL_BLEND)
108
+ glPopMatrix()
109
+
110
+ glutSwapBuffers()
111
+ end
112
+
113
+ reshape = proc do |w, h|
114
+ glViewport(0, 0, w, h)
115
+ glMatrixMode(GL_PROJECTION)
116
+ glLoadIdentity()
117
+ if (w <= h)
118
+ glOrtho(-1.5, 1.5, -1.5*h.to_f/w, 1.5*h.to_f/w, -10.0, 10.0)
119
+ else
120
+ glOrtho(-1.5*w.to_f/h, 1.5*w.to_f/h, -1.5, 1.5, -10.0, 10.0)
121
+ end
122
+ glMatrixMode(GL_MODELVIEW)
123
+ glLoadIdentity()
124
+ end
125
+
126
+ animate = proc do
127
+ if ($solidZ <= MINZ || $transparentZ >= MAXZ)
128
+ glutIdleFunc(nil)
129
+ else
130
+ $solidZ -= ZINC
131
+ $transparentZ += ZINC
132
+ glutPostRedisplay()
133
+ end
134
+ end
135
+
136
+ keyboard = proc do |key, x, y|
137
+ case (key)
138
+ when ?a,?A
139
+ $solidZ = MAXZ
140
+ $transparentZ = MINZ
141
+ glutIdleFunc(animate)
142
+ when ?r, ?R
143
+ $solidZ = MAXZ
144
+ $transparentZ = MINZ
145
+ glutPostRedisplay()
146
+ when ?\e
147
+ exit(0)
148
+ end
149
+ end
150
+
151
+ glutInit()
152
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
153
+ glutInitWindowSize(500, 500)
154
+ glutInitWindowPosition(100, 100)
155
+ glutCreateWindow($0)
156
+ init()
157
+ glutReshapeFunc(reshape)
158
+ glutKeyboardFunc(keyboard)
159
+ glutDisplayFunc(display)
160
+ glutMainLoop()