opengl 0.8.0 → 0.9.0

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 +1 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +2 -1
  5. data/.travis.yml +19 -0
  6. data/History.rdoc +26 -0
  7. data/Manifest.txt +3 -23
  8. data/README.rdoc +43 -37
  9. data/Rakefile +6 -62
  10. data/examples/NeHe/nehe_lesson02.rb +3 -2
  11. data/examples/NeHe/nehe_lesson03.rb +3 -2
  12. data/examples/NeHe/nehe_lesson04.rb +3 -1
  13. data/examples/NeHe/nehe_lesson05.rb +4 -1
  14. data/examples/NeHe/nehe_lesson06.rb +9 -6
  15. data/examples/NeHe/nehe_lesson07.rb +9 -6
  16. data/examples/NeHe/nehe_lesson08.rb +9 -6
  17. data/examples/NeHe/nehe_lesson09.rb +10 -6
  18. data/examples/NeHe/nehe_lesson11.rb +9 -6
  19. data/examples/NeHe/nehe_lesson12.rb +9 -6
  20. data/examples/NeHe/nehe_lesson16.rb +50 -47
  21. data/examples/NeHe/nehe_lesson19.rb +10 -7
  22. data/examples/NeHe/nehe_lesson36.rb +234 -229
  23. data/examples/OrangeBook/brick.rb +227 -225
  24. data/examples/OrangeBook/particle.rb +233 -231
  25. data/examples/RedBook/aapoly.rb +71 -70
  26. data/examples/RedBook/aargb.rb +54 -52
  27. data/examples/RedBook/accanti.rb +96 -94
  28. data/examples/RedBook/accpersp.rb +106 -104
  29. data/examples/RedBook/alpha.rb +54 -52
  30. data/examples/RedBook/alpha3D.rb +90 -88
  31. data/examples/RedBook/bezcurve.rb +48 -46
  32. data/examples/RedBook/bezmesh.rb +71 -69
  33. data/examples/RedBook/checker.rb +57 -55
  34. data/examples/RedBook/clip.rb +41 -39
  35. data/examples/RedBook/colormat.rb +72 -70
  36. data/examples/RedBook/cube.rb +39 -37
  37. data/examples/RedBook/depthcue.rb +37 -35
  38. data/examples/RedBook/dof.rb +110 -109
  39. data/examples/RedBook/double.rb +40 -38
  40. data/examples/RedBook/drawf.rb +30 -28
  41. data/examples/RedBook/feedback.rb +79 -77
  42. data/examples/RedBook/fog.rb +90 -89
  43. data/examples/RedBook/font.rb +78 -76
  44. data/examples/RedBook/hello.rb +29 -27
  45. data/examples/RedBook/image.rb +57 -55
  46. data/examples/RedBook/jitter.rb +131 -131
  47. data/examples/RedBook/light.rb +2 -1
  48. data/examples/RedBook/lines.rb +70 -68
  49. data/examples/RedBook/list.rb +48 -46
  50. data/examples/RedBook/material.rb +200 -199
  51. data/examples/RedBook/mipmap.rb +84 -82
  52. data/examples/RedBook/model.rb +55 -53
  53. data/examples/RedBook/movelight.rb +52 -50
  54. data/examples/RedBook/pickdepth.rb +103 -101
  55. data/examples/RedBook/planet.rb +46 -44
  56. data/examples/RedBook/quadric.rb +97 -95
  57. data/examples/RedBook/robot.rb +55 -53
  58. data/examples/RedBook/select.rb +118 -116
  59. data/examples/RedBook/smooth.rb +35 -33
  60. data/examples/RedBook/stencil.rb +96 -94
  61. data/examples/RedBook/stroke.rb +75 -73
  62. data/examples/RedBook/surface.rb +93 -91
  63. data/examples/RedBook/teaambient.rb +71 -69
  64. data/examples/RedBook/teapots.rb +105 -103
  65. data/examples/RedBook/tess.rb +96 -94
  66. data/examples/RedBook/texbind.rb +79 -77
  67. data/examples/RedBook/texgen.rb +88 -86
  68. data/examples/RedBook/texturesurf.rb +57 -55
  69. data/examples/RedBook/varray.rb +85 -83
  70. data/examples/RedBook/wrap.rb +76 -74
  71. data/examples/misc/OGLBench.rb +114 -113
  72. data/examples/misc/anisotropic.rb +154 -152
  73. data/examples/misc/fbo_test.rb +37 -36
  74. data/examples/misc/font-glut.rb +47 -46
  75. data/examples/misc/glfwtest.rb +16 -16
  76. data/examples/misc/plane.rb +13 -13
  77. data/examples/misc/readpixel.rb +66 -65
  78. data/examples/misc/sdltest.rb +21 -19
  79. data/examples/misc/trislam.rb +548 -547
  80. data/ext/opengl/common.h +16 -38
  81. data/ext/opengl/conv.h +39 -41
  82. data/ext/opengl/extconf.rb +4 -31
  83. data/ext/opengl/funcdef.h +126 -124
  84. data/ext/opengl/gl-1.0-1.1.c +1917 -1917
  85. data/ext/opengl/gl-1.2.c +4 -667
  86. data/ext/opengl/gl-1.3.c +9 -9
  87. data/ext/opengl/gl-1.4.c +8 -8
  88. data/ext/opengl/gl-1.5.c +1 -1
  89. data/ext/opengl/gl-2.0.c +392 -388
  90. data/ext/opengl/gl-3.0.c +493 -0
  91. data/ext/opengl/gl-enums.c +1523 -5
  92. data/ext/opengl/gl-enums.h +4679 -122
  93. data/ext/opengl/gl-error.c +7 -7
  94. data/ext/opengl/gl-error.h +4 -4
  95. data/ext/opengl/gl-ext-arb.c +468 -464
  96. data/ext/opengl/gl-ext-ext.c +18 -18
  97. data/ext/opengl/gl-ext-nv.c +15 -15
  98. data/ext/opengl/gl.c +2 -0
  99. data/ext/opengl/gl_buffer.c +92 -92
  100. data/ext/opengl/opengl.c +1 -7
  101. data/lib/opengl.rb +23 -59
  102. data/lib/opengl/test_case.rb +1 -2
  103. data/test/dummy.xorg.conf +140 -0
  104. data/test/test_gl.rb +18 -22
  105. data/test/test_gl_10_11.rb +220 -220
  106. data/test/test_gl_12.rb +11 -122
  107. data/test/test_gl_13.rb +202 -210
  108. data/test/test_gl_14.rb +16 -19
  109. data/test/test_gl_15.rb +2 -4
  110. data/test/test_gl_20.rb +45 -58
  111. data/test/test_gl_21.rb +46 -163
  112. data/test/test_gl_ext_arb.rb +54 -72
  113. data/test/test_gl_ext_ati.rb +0 -2
  114. data/test/test_gl_ext_ext.rb +66 -66
  115. data/test/test_gl_ext_gremedy.rb +8 -15
  116. data/test/test_gl_ext_nv.rb +109 -112
  117. data/test/test_opengl_buffer.rb +8 -25
  118. data/utils/README +0 -5
  119. data/utils/enumgen.rb +72 -76
  120. data/utils/extlistgen.rb +55 -55
  121. metadata +87 -66
  122. metadata.gz.sig +2 -0
  123. data/Rakefile.cross +0 -107
  124. data/docs/build_install.txt +0 -119
  125. data/docs/extensions.txt.in +0 -348
  126. data/docs/history.txt +0 -66
  127. data/docs/requirements_and_design.txt +0 -117
  128. data/docs/roadmap.txt +0 -28
  129. data/docs/scientific_use.txt +0 -35
  130. data/docs/supplies/page_template.html +0 -71
  131. data/docs/thanks.txt +0 -29
  132. data/docs/tutorial.txt +0 -469
  133. data/ext/opengl/glu-enums.c +0 -164
  134. data/ext/opengl/glu-enums.h +0 -463
  135. data/ext/opengl/glu.c +0 -1534
  136. data/ext/opengl/glut.c +0 -1145
  137. data/ext/opengl/glut_callbacks.c +0 -845
  138. data/lib/glu.rb +0 -1
  139. data/lib/glut.rb +0 -1
  140. data/test/test_glu.rb +0 -309
  141. data/utils/mkdn2html.rb +0 -59
  142. data/utils/post-mkdn2html.rb +0 -91
  143. data/website/images/ogl.jpg +0 -0
  144. data/website/images/tab_bottom.gif +0 -0
  145. data/website/style.css +0 -198
@@ -1,13 +1,13 @@
1
1
  #
2
2
  # Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
- # ALL RIGHTS RESERVED
4
- # Permission to use, copy, modify, and distribute this software for
3
+ # ALL RIGHTS RESERVED
4
+ # Permission to use, copy, modify, and distribute this software for
5
5
  # any purpose and without fee is hereby granted, provided that the above
6
6
  # copyright notice appear in all copies and that both the copyright notice
7
- # and this permission notice appear in supporting documentation, and that
7
+ # and this permission notice appear in supporting documentation, and that
8
8
  # the name of Silicon Graphics, Inc. not be used in advertising
9
9
  # or publicity pertaining to distribution of the software without specific,
10
- # written prior permission.
10
+ # written prior permission.
11
11
  #
12
12
  # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
13
  # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
@@ -21,8 +21,8 @@
21
21
  # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
22
  # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
23
  # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
- #
25
- # US Government Users Restricted Rights
24
+ #
25
+ # US Government Users Restricted Rights
26
26
  # Use, duplication, or disclosure by the Government is subject to
27
27
  # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
28
  # (c)(1)(ii) of the Rights in Technical Data and Computer Software
@@ -40,43 +40,45 @@
40
40
  # routines accFrustum() and accPerspective().
41
41
 
42
42
  require 'opengl'
43
+ require 'glu'
44
+ require 'glut'
43
45
  include Gl,Glu,Glut
44
46
 
45
47
  $j8 = [
46
- [-0.334818, 0.435331],
47
- [ 0.286438, -0.393495],
48
- [ 0.459462, 0.141540],
49
- [-0.414498, -0.192829],
50
- [-0.183790, 0.082102],
51
- [-0.079263, -0.317383],
52
- [ 0.102254, 0.299133],
53
- [ 0.164216, -0.054399]
54
- ]
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
+ ]
55
57
 
56
58
  # accFrustum()
57
59
  # The first 6 arguments are identical to the glFrustum() call.
58
- #
59
- # pixdx and pixdy are anti-alias jitter in pixels.
60
+ #
61
+ # pixdx and pixdy are anti-alias jitter in pixels.
60
62
  # Set both equal to 0.0 for no anti-alias jitter.
61
- # eyedx and eyedy are depth-of field jitter in pixels.
63
+ # eyedx and eyedy are depth-of field jitter in pixels.
62
64
  # Set both equal to 0.0 for no depth of field effects.
63
65
  #
64
- # focus is distance from eye to plane in focus.
66
+ # focus is distance from eye to plane in focus.
65
67
  # focus must be greater than, but not equal to 0.0.
66
68
  #
67
- # Note that accFrustum() calls glTranslatef(). You will
68
- # probably want to insure that your ModelView matrix has been
69
+ # Note that accFrustum() calls glTranslatef(). You will
70
+ # probably want to insure that your ModelView matrix has been
69
71
  # initialized to identity before calling accFrustum().
70
72
 
71
73
  def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
72
74
  viewport = glGetDoublev(GL_VIEWPORT)
73
-
75
+
74
76
  xwsize = right - left
75
77
  ywsize = top - bottom
76
-
78
+
77
79
  dx = -(pixdx*xwsize/viewport[2] + eyedx*nnear/focus)
78
80
  dy = -(pixdy*ywsize/viewport[3] + eyedy*nnear/focus)
79
-
81
+
80
82
  glMatrixMode(GL_PROJECTION)
81
83
  glLoadIdentity()
82
84
  glFrustum(left + dx, right + dx, bottom + dy, top + dy, nnear, ffar)
@@ -86,107 +88,107 @@ def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy
86
88
  end
87
89
 
88
90
  # accPerspective()
89
- #
91
+ #
90
92
  # The first 4 arguments are identical to the gluPerspective() call.
91
- # pixdx and pixdy are anti-alias jitter in pixels.
93
+ # pixdx and pixdy are anti-alias jitter in pixels.
92
94
  # Set both equal to 0.0 for no anti-alias jitter.
93
- # eyedx and eyedy are depth-of field jitter in pixels.
95
+ # eyedx and eyedy are depth-of field jitter in pixels.
94
96
  # Set both equal to 0.0 for no depth of field effects.
95
97
  #
96
- # focus is distance from eye to plane in focus.
98
+ # focus is distance from eye to plane in focus.
97
99
  # focus must be greater than, but not equal to 0.0.
98
100
  #
99
101
  # Note that accPerspective() calls accFrustum().
100
102
 
101
103
  def accPerspective(fovy, aspect, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
102
- fov2 = ((fovy*Math::PI) / 180.0) / 2.0
103
-
104
- top = nnear / (Math::cos(fov2) / Math::sin(fov2))
105
- bottom = -top
106
-
107
- right = top * aspect
108
- left = -right
109
-
110
- accFrustum(left, right, bottom, top, 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)
111
113
  end
112
114
 
113
115
  # Initialize lighting and other values.
114
116
  def init
115
- mat_ambient = [ 1.0, 1.0, 1.0, 1.0 ]
116
- mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
117
- light_position = [ 0.0, 0.0, 10.0, 1.0 ]
118
- lm_ambient = [ 0.2, 0.2, 0.2, 1.0 ]
119
-
120
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
121
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
122
- glMaterial(GL_FRONT, GL_SHININESS, 50.0)
123
- glLight(GL_LIGHT0, GL_POSITION, light_position)
124
- glLightModel(GL_LIGHT_MODEL_AMBIENT, lm_ambient)
125
-
126
- glEnable(GL_LIGHTING)
127
- glEnable(GL_LIGHT0)
128
- glEnable(GL_DEPTH_TEST)
129
- glShadeModel(GL_FLAT)
130
-
131
- glClearColor(0.0, 0.0, 0.0, 0.0)
132
- glClearAccum(0.0, 0.0, 0.0, 0.0)
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)
133
135
  end
134
136
 
135
137
  def displayObjects
136
- torus_diffuse = [ 0.7, 0.7, 0.0, 1.0 ]
137
- cube_diffuse = [ 0.0, 0.7, 0.7, 1.0 ]
138
- sphere_diffuse = [ 0.7, 0.0, 0.7, 1.0 ]
139
- octa_diffuse = [ 0.7, 0.4, 0.4, 1.0 ]
140
-
141
- glPushMatrix()
142
- glTranslate(0.0, 0.0, -5.0)
143
- glRotate(30.0, 1.0, 0.0, 0.0)
144
-
145
- glPushMatrix()
146
- glTranslate(-0.80, 0.35, 0.0)
147
- glRotate(100.0, 1.0, 0.0, 0.0)
148
- glMaterial(GL_FRONT, GL_DIFFUSE, torus_diffuse)
149
- glutSolidTorus(0.275, 0.85, 16, 16)
150
- glPopMatrix()
151
-
152
- glPushMatrix()
153
- glTranslate(-0.75, -0.50, 0.0)
154
- glRotate(45.0, 0.0, 0.0, 1.0)
155
- glRotate(45.0, 1.0, 0.0, 0.0)
156
- glMaterial(GL_FRONT, GL_DIFFUSE, cube_diffuse)
157
- glutSolidCube(1.5)
158
- glPopMatrix()
159
-
160
- glPushMatrix()
161
- glTranslate(0.75, 0.60, 0.0)
162
- glRotate(30.0, 1.0, 0.0, 0.0)
163
- glMaterial(GL_FRONT, GL_DIFFUSE, sphere_diffuse)
164
- glutSolidSphere(1.0, 16, 16)
165
- glPopMatrix()
166
-
167
- glPushMatrix()
168
- glTranslate(0.70, -0.90, 0.25)
169
- glMaterial(GL_FRONT, GL_DIFFUSE, octa_diffuse)
170
- glutSolidOctahedron()
171
- glPopMatrix()
172
-
173
- glPopMatrix()
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()
174
176
  end
175
177
 
176
178
  ACSIZE=8
177
179
 
178
180
  display = proc do
179
- viewport = glGetDoublev(GL_VIEWPORT)
180
-
181
- glClear(GL_ACCUM_BUFFER_BIT)
182
- for jitter in 0...ACSIZE
183
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
184
- accPerspective(50.0, viewport[2]/ viewport[3], 1.0, 15.0, $j8[jitter][0], $j8[jitter][1], 0.0, 0.0, 1.0)
185
- displayObjects()
186
- glAccum(GL_ACCUM, 1.0/ACSIZE)
187
- end
188
- glAccum(GL_RETURN, 1.0)
189
- glutSwapBuffers()
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()
190
192
  end
191
193
 
192
194
  reshape = proc do |w, h|
@@ -1,13 +1,13 @@
1
1
  #
2
2
  # Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
- # ALL RIGHTS RESERVED
4
- # Permission to use, copy, modify, and distribute this software for
3
+ # ALL RIGHTS RESERVED
4
+ # Permission to use, copy, modify, and distribute this software for
5
5
  # any purpose and without fee is hereby granted, provided that the above
6
6
  # copyright notice appear in all copies and that both the copyright notice
7
- # and this permission notice appear in supporting documentation, and that
7
+ # and this permission notice appear in supporting documentation, and that
8
8
  # the name of Silicon Graphics, Inc. not be used in advertising
9
9
  # or publicity pertaining to distribution of the software without specific,
10
- # written prior permission.
10
+ # written prior permission.
11
11
  #
12
12
  # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
13
  # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
@@ -21,8 +21,8 @@
21
21
  # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
22
  # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
23
  # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
- #
25
- # US Government Users Restricted Rights
24
+ #
25
+ # US Government Users Restricted Rights
26
26
  # Use, duplication, or disclosure by the Government is subject to
27
27
  # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
28
  # (c)(1)(ii) of the Rights in Technical Data and Computer Software
@@ -39,6 +39,8 @@
39
39
  # to demonstrate the effect order has on alpha blending results.
40
40
  # Use the 't' key to toggle the order of drawing polygons.
41
41
  require 'opengl'
42
+ require 'glu'
43
+ require 'glut'
42
44
  require 'mathn'
43
45
  include Gl,Glu,Glut
44
46
 
@@ -46,70 +48,70 @@ $leftFirst = GL_TRUE
46
48
 
47
49
  # Initialize alpha blending function.
48
50
  def init
49
- glEnable(GL_BLEND)
50
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
51
- glShadeModel(GL_FLAT)
52
- glClearColor(0.0, 0.0, 0.0, 0.0)
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)
53
55
  end
54
56
 
55
57
  def drawLeftTriangle
56
- # draw yellow triangle on LHS of screen
57
-
58
- glBegin(GL_TRIANGLES)
59
- glColor(1.0, 1.0, 0.0, 0.75)
60
- glVertex(0.1, 0.9, 0.0)
61
- glVertex(0.1, 0.1, 0.0)
62
- glVertex(0.7, 0.5, 0.0)
63
- glEnd()
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()
64
66
  end
65
67
 
66
68
  def drawRightTriangle
67
- # draw cyan triangle on RHS of screen
68
-
69
- glBegin(GL_TRIANGLES)
70
- glColor(0.0, 1.0, 1.0, 0.75)
71
- glVertex(0.9, 0.9, 0.0)
72
- glVertex(0.3, 0.5, 0.0)
73
- glVertex(0.9, 0.1, 0.0)
74
- glEnd()
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()
75
77
  end
76
78
 
77
79
  display = Proc.new do
78
- glClear(GL_COLOR_BUFFER_BIT)
79
-
80
- if ($leftFirst)
81
- drawLeftTriangle()
82
- drawRightTriangle()
83
- else
84
- drawRightTriangle()
85
- drawLeftTriangle()
86
- end
87
- glutSwapBuffers()
80
+ glClear(GL_COLOR_BUFFER_BIT)
81
+
82
+ if ($leftFirst)
83
+ drawLeftTriangle()
84
+ drawRightTriangle()
85
+ else
86
+ drawRightTriangle()
87
+ drawLeftTriangle()
88
+ end
89
+ glutSwapBuffers()
88
90
  end
89
91
 
90
92
  reshape = Proc.new do |w, h|
91
- glViewport(0, 0, w, h)
92
- glMatrixMode(GL_PROJECTION)
93
- glLoadIdentity()
94
- if (w <= h)
95
- gluOrtho2D(0.0, 1.0, 0.0, 1.0*h/w)
96
- else
97
- gluOrtho2D(0.0, 1.0*w/h, 0.0, 1.0)
98
- end
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
99
101
  end
100
102
 
101
103
  keyboard = Proc.new do|key, x, y|
102
- case (key)
103
- when ?t,?T
104
- $leftFirst = !$leftFirst
105
- glutPostRedisplay()
106
- when ?\e # Escape key
107
- exit(0)
108
- end
104
+ case (key)
105
+ when ?t,?T
106
+ $leftFirst = !$leftFirst
107
+ glutPostRedisplay()
108
+ when ?\e # Escape key
109
+ exit(0)
110
+ end
109
111
  end
110
112
 
111
113
  # Main Loop
112
- # Open window with initial window size, title bar,
114
+ # Open window with initial window size, title bar,
113
115
  # RGBA display mode, and handle input events.
114
116
  glutInit
115
117
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
@@ -1,13 +1,13 @@
1
1
  #
2
2
  # Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
- # ALL RIGHTS RESERVED
4
- # Permission to use, copy, modify, and distribute this software for
3
+ # ALL RIGHTS RESERVED
4
+ # Permission to use, copy, modify, and distribute this software for
5
5
  # any purpose and without fee is hereby granted, provided that the above
6
6
  # copyright notice appear in all copies and that both the copyright notice
7
- # and this permission notice appear in supporting documentation, and that
7
+ # and this permission notice appear in supporting documentation, and that
8
8
  # the name of Silicon Graphics, Inc. not be used in advertising
9
9
  # or publicity pertaining to distribution of the software without specific,
10
- # written prior permission.
10
+ # written prior permission.
11
11
  #
12
12
  # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
13
  # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
@@ -21,8 +21,8 @@
21
21
  # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
22
  # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
23
  # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
- #
25
- # US Government Users Restricted Rights
24
+ #
25
+ # US Government Users Restricted Rights
26
26
  # Use, duplication, or disclosure by the Government is subject to
27
27
  # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
28
  # (c)(1)(ii) of the Rights in Technical Data and Computer Software
@@ -36,11 +36,13 @@
36
36
  #
37
37
  # alpha3D.c
38
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
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
42
  # the 'r' key to reset the scene.
43
43
  require 'opengl'
44
+ require 'glu'
45
+ require 'glut'
44
46
  include Gl,Glu,Glut
45
47
 
46
48
  MAXZ=1.0
@@ -53,97 +55,97 @@ $sphereList=nil
53
55
  $cubeList=nil
54
56
 
55
57
  def init
56
- mat_specular = [ 1.0, 1.0, 1.0, 0.15 ]
57
- mat_shininess = [ 100.0 ]
58
- position = [ 0.5, 0.5, 1.0, 0.0 ]
59
-
60
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
61
- glMaterial(GL_FRONT, GL_SHININESS, mat_shininess)
62
- glLight(GL_LIGHT0, GL_POSITION, position)
63
-
64
- glEnable(GL_LIGHTING)
65
- glEnable(GL_LIGHT0)
66
- glEnable(GL_DEPTH_TEST)
67
-
68
- $sphereList = glGenLists(1)
69
- glNewList($sphereList, GL_COMPILE)
70
- glutSolidSphere(0.4, 16, 16)
71
- glEndList()
72
-
73
- $cubeList = glGenLists(1)
74
- glNewList($cubeList, GL_COMPILE)
75
- glutSolidCube(0.6)
76
- glEndList()
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()
77
79
  end
78
80
 
79
81
  display = proc do
80
- mat_solid = [ 0.75, 0.75, 0.0, 1.0 ]
81
- mat_zero = [ 0.0, 0.0, 0.0, 1.0 ]
82
- mat_transparent = [ 0.0, 0.8, 0.8, 0.6 ]
83
- mat_emission = [ 0.0, 0.3, 0.3, 0.6 ]
84
-
85
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
86
-
87
- glPushMatrix()
88
- glTranslate(-0.15, -0.15, $solidZ)
89
- glMaterial(GL_FRONT, GL_EMISSION, mat_zero)
90
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_solid)
91
- glCallList($sphereList)
92
- glPopMatrix()
93
-
94
- glPushMatrix()
95
- glTranslate(0.15, 0.15, $transparentZ)
96
- glRotate(15.0, 1.0, 1.0, 0.0)
97
- glRotate(30.0, 0.0, 1.0, 0.0)
98
- glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
99
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_transparent)
100
- glEnable(GL_BLEND)
101
- glDepthMask(GL_FALSE)
102
- glBlendFunc(GL_SRC_ALPHA, GL_ONE)
103
- glCallList($cubeList)
104
- glDepthMask(GL_TRUE)
105
- glDisable(GL_BLEND)
106
- glPopMatrix()
107
-
108
- glutSwapBuffers()
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()
109
111
  end
110
112
 
111
113
  reshape = proc do |w, h|
112
- glViewport(0, 0, w, h)
113
- glMatrixMode(GL_PROJECTION)
114
- glLoadIdentity()
115
- if (w <= h)
116
- glOrtho(-1.5, 1.5, -1.5*h.to_f/w, 1.5*h.to_f/w, -10.0, 10.0)
117
- else
118
- glOrtho(-1.5*w.to_f/h, 1.5*w.to_f/h, -1.5, 1.5, -10.0, 10.0)
119
- end
120
- glMatrixMode(GL_MODELVIEW)
121
- glLoadIdentity()
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()
122
124
  end
123
125
 
124
126
  animate = proc do
125
- if ($solidZ <= MINZ || $transparentZ >= MAXZ)
126
- glutIdleFunc(nil)
127
- else
128
- $solidZ -= ZINC
129
- $transparentZ += ZINC
130
- glutPostRedisplay()
131
- end
127
+ if ($solidZ <= MINZ || $transparentZ >= MAXZ)
128
+ glutIdleFunc(nil)
129
+ else
130
+ $solidZ -= ZINC
131
+ $transparentZ += ZINC
132
+ glutPostRedisplay()
133
+ end
132
134
  end
133
135
 
134
136
  keyboard = proc do |key, x, y|
135
- case (key)
136
- when ?a,?A
137
- $solidZ = MAXZ
138
- $transparentZ = MINZ
139
- glutIdleFunc(animate)
140
- when ?r, ?R
141
- $solidZ = MAXZ
142
- $transparentZ = MINZ
143
- glutPostRedisplay()
144
- when ?\e
145
- exit(0)
146
- end
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
147
149
  end
148
150
 
149
151
  glutInit()