ruby-opengl 0.40.1 → 0.50.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 (154) hide show
  1. data/Rakefile +2 -2
  2. data/doc/build_install.txt +48 -28
  3. data/doc/extensions.txt +361 -0
  4. data/doc/history.txt +8 -2
  5. data/doc/requirements_and_design.txt +0 -13
  6. data/doc/roadmap.txt +11 -13
  7. data/doc/supplies/page_template.html +11 -5
  8. data/doc/thanks.txt +2 -4
  9. data/doc/tutorial.txt +1 -4
  10. data/examples/{nehe_lesson02.rb → NeHe/nehe_lesson02.rb} +0 -0
  11. data/examples/{nehe_lesson03.rb → NeHe/nehe_lesson03.rb} +0 -0
  12. data/examples/{nehe_lesson04.rb → NeHe/nehe_lesson04.rb} +0 -0
  13. data/examples/{nehe_lesson05.rb → NeHe/nehe_lesson05.rb} +0 -0
  14. data/examples/NeHe/nehe_lesson36.rb +303 -0
  15. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  16. data/examples/OrangeBook/brick.frag +36 -0
  17. data/examples/OrangeBook/brick.rb +388 -0
  18. data/examples/OrangeBook/brick.vert +41 -0
  19. data/examples/OrangeBook/particle.frag +17 -0
  20. data/examples/OrangeBook/particle.rb +424 -0
  21. data/examples/OrangeBook/particle.vert +38 -0
  22. data/examples/README +13 -83
  23. data/examples/RedBook/aaindex.rb +97 -0
  24. data/examples/RedBook/aapoly.rb +142 -0
  25. data/examples/RedBook/aargb.rb +119 -0
  26. data/examples/RedBook/accanti.rb +162 -0
  27. data/examples/RedBook/accpersp.rb +215 -0
  28. data/examples/RedBook/alpha.rb +123 -0
  29. data/examples/RedBook/alpha3D.rb +158 -0
  30. data/examples/RedBook/bezcurve.rb +105 -0
  31. data/examples/RedBook/bezmesh.rb +137 -0
  32. data/examples/RedBook/checker.rb +124 -0
  33. data/examples/RedBook/clip.rb +95 -0
  34. data/examples/RedBook/colormat.rb +135 -0
  35. data/examples/RedBook/cube.rb +69 -0
  36. data/examples/RedBook/depthcue.rb +99 -0
  37. data/examples/RedBook/dof.rb +205 -0
  38. data/examples/{legacy → RedBook}/double.rb +59 -58
  39. data/examples/{legacy → RedBook}/drawf.rb +47 -54
  40. data/examples/RedBook/feedback.rb +145 -0
  41. data/examples/RedBook/fog.rb +167 -0
  42. data/examples/RedBook/font.rb +151 -0
  43. data/examples/RedBook/hello.rb +79 -0
  44. data/examples/RedBook/image.rb +137 -0
  45. data/examples/{legacy → RedBook}/jitter.rb +60 -62
  46. data/examples/RedBook/lines.rb +128 -0
  47. data/examples/RedBook/list.rb +111 -0
  48. data/examples/RedBook/material.rb +275 -0
  49. data/examples/RedBook/mipmap.rb +156 -0
  50. data/examples/{legacy → RedBook}/model.rb +66 -72
  51. data/examples/{legacy → RedBook}/movelight.rb +67 -75
  52. data/examples/RedBook/pickdepth.rb +179 -0
  53. data/examples/{legacy → RedBook}/planet.rb +62 -66
  54. data/examples/RedBook/quadric.rb +158 -0
  55. data/examples/RedBook/robot.rb +115 -0
  56. data/examples/RedBook/select.rb +196 -0
  57. data/examples/RedBook/smooth.rb +95 -0
  58. data/examples/RedBook/stencil.rb +163 -0
  59. data/examples/RedBook/stroke.rb +167 -0
  60. data/examples/RedBook/surface.rb +166 -0
  61. data/examples/RedBook/teaambient.rb +132 -0
  62. data/examples/RedBook/teapots.rb +182 -0
  63. data/examples/RedBook/tess.rb +183 -0
  64. data/examples/RedBook/texbind.rb +147 -0
  65. data/examples/RedBook/texgen.rb +169 -0
  66. data/examples/RedBook/texturesurf.rb +128 -0
  67. data/examples/RedBook/varray.rb +159 -0
  68. data/examples/RedBook/wrap.rb +148 -0
  69. data/examples/misc/anisotropic.rb +194 -0
  70. data/examples/misc/font-glut.rb +46 -0
  71. data/examples/{plane.rb → misc/plane.rb} +0 -0
  72. data/examples/misc/readpixel.rb +65 -0
  73. data/examples/{smooth.rb → misc/smooth.rb} +0 -0
  74. data/examples/{test.rb → misc/test.rb} +0 -0
  75. data/ext/common/common.h +252 -70
  76. data/ext/common/gl-enums.h +6102 -7334
  77. data/ext/common/gl-types.h +47 -0
  78. data/ext/common/glu-enums.h +469 -0
  79. data/ext/gl/gl-1.0-1.1.c +842 -2464
  80. data/ext/gl/gl-1.2.c +217 -281
  81. data/ext/gl/gl-1.3.c +113 -133
  82. data/ext/gl/gl-1.4.c +98 -334
  83. data/ext/gl/gl-1.5.c +28 -34
  84. data/ext/gl/gl-2.0.c +26 -235
  85. data/ext/gl/gl-2.1.c +31 -124
  86. data/ext/gl/gl-enums.c +786 -631
  87. data/ext/gl/gl-ext-arb.c +66 -0
  88. data/ext/gl/gl-ext-ext.c +218 -0
  89. data/ext/gl/gl.c +138 -31
  90. data/ext/gl/mkrf_conf.rb +1 -0
  91. data/ext/glu/glu-enums.c +163 -0
  92. data/ext/glu/glu.c +1003 -1205
  93. data/ext/glu/mkrf_conf.rb +1 -0
  94. data/ext/glut/glut.c +1056 -1175
  95. data/lib/opengl.rb +90 -3
  96. data/test/tc_common.rb +26 -13
  97. data/test/tc_ext_arb.rb +73 -0
  98. data/test/tc_ext_ext.rb +74 -0
  99. data/test/tc_func_12.rb +8 -8
  100. data/test/tc_func_13.rb +17 -11
  101. data/test/tc_func_14.rb +8 -8
  102. data/test/tc_func_15.rb +190 -2
  103. data/test/tc_func_20.rb +36 -10
  104. data/test/tc_func_21.rb +445 -2
  105. data/test/tc_glu.rb +305 -0
  106. data/test/tc_misc.rb +1 -0
  107. metadata +84 -68
  108. data/doc/screenshots.txt +0 -23
  109. data/examples/legacy/COPYRIGHT +0 -8
  110. data/examples/legacy/aaindex.rb +0 -98
  111. data/examples/legacy/aapoly.rb +0 -153
  112. data/examples/legacy/aargb.rb +0 -139
  113. data/examples/legacy/accanti.rb +0 -159
  114. data/examples/legacy/accpersp.rb +0 -216
  115. data/examples/legacy/alpha.rb +0 -133
  116. data/examples/legacy/alpha3D.rb +0 -165
  117. data/examples/legacy/bezcurve.rb +0 -107
  118. data/examples/legacy/bezmesh.rb +0 -131
  119. data/examples/legacy/checker.rb +0 -121
  120. data/examples/legacy/clip.rb +0 -104
  121. data/examples/legacy/colormat.rb +0 -145
  122. data/examples/legacy/cube.rb +0 -73
  123. data/examples/legacy/depthcue.rb +0 -101
  124. data/examples/legacy/dof.rb +0 -212
  125. data/examples/legacy/feedback.rb +0 -152
  126. data/examples/legacy/fog.rb +0 -172
  127. data/examples/legacy/font-glut.rb +0 -41
  128. data/examples/legacy/font.rb +0 -158
  129. data/examples/legacy/hello.rb +0 -75
  130. data/examples/legacy/image.rb +0 -145
  131. data/examples/legacy/lines.rb +0 -135
  132. data/examples/legacy/list.rb +0 -120
  133. data/examples/legacy/material.rb +0 -290
  134. data/examples/legacy/mipmap.rb +0 -159
  135. data/examples/legacy/pickdepth.rb +0 -180
  136. data/examples/legacy/quadric.rb +0 -180
  137. data/examples/legacy/readpixel.rb +0 -59
  138. data/examples/legacy/robot.rb +0 -120
  139. data/examples/legacy/select.rb +0 -207
  140. data/examples/legacy/smooth.rb +0 -41
  141. data/examples/legacy/stencil.rb +0 -154
  142. data/examples/legacy/stroke.rb +0 -170
  143. data/examples/legacy/surface.rb +0 -170
  144. data/examples/legacy/teaambient.rb +0 -132
  145. data/examples/legacy/teapots.rb +0 -188
  146. data/examples/legacy/tess.rb +0 -222
  147. data/examples/legacy/texbind.rb +0 -157
  148. data/examples/legacy/texgen.rb +0 -171
  149. data/examples/legacy/texturesurf.rb +0 -128
  150. data/examples/legacy/varray.rb +0 -167
  151. data/examples/legacy/wrap.rb +0 -158
  152. data/lib/gl_prev.rb +0 -46
  153. data/lib/glu_prev.rb +0 -46
  154. data/lib/glut_prev.rb +0 -45
@@ -0,0 +1,115 @@
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
+ # robot.c
38
+ # This program shows how to composite modeling transformations
39
+ # to draw translated and rotated hierarchical models.
40
+ # Interaction: pressing the s and e keys (shoulder and elbow)
41
+ # alters the rotation of the robot arm.
42
+ require 'opengl'
43
+ require 'mathn'
44
+ include Gl,Glu,Glut
45
+
46
+ $shoulder = 0
47
+ $elbow = 0
48
+
49
+ def init
50
+ glClearColor(0.0, 0.0, 0.0, 0.0)
51
+ glShadeModel(GL_FLAT)
52
+ end
53
+
54
+ display = Proc.new do
55
+ glClear(GL_COLOR_BUFFER_BIT)
56
+ glPushMatrix()
57
+ glTranslate(-1.0, 0.0, 0.0)
58
+ glRotate($shoulder, 0.0, 0.0, 1.0)
59
+ glTranslate(1.0, 0.0, 0.0)
60
+ glPushMatrix()
61
+ glScale(2.0, 0.4, 1.0)
62
+ glutWireCube(1.0)
63
+ glPopMatrix()
64
+
65
+ glTranslate(1.0, 0.0, 0.0)
66
+ glRotate($elbow, 0.0, 0.0, 1.0)
67
+ glTranslate(1.0, 0.0, 0.0)
68
+ glPushMatrix()
69
+ glScale(2.0, 0.4, 1.0)
70
+ glutWireCube(1.0)
71
+ glPopMatrix()
72
+
73
+ glPopMatrix()
74
+ glutSwapBuffers()
75
+ end
76
+
77
+ reshape = Proc.new do |w, h|
78
+ glViewport(0, 0, w, h)
79
+ glMatrixMode(GL_PROJECTION)
80
+ glLoadIdentity()
81
+ gluPerspective(65.0, w/ h, 1.0, 20.0)
82
+ glMatrixMode(GL_MODELVIEW)
83
+ glLoadIdentity()
84
+ glTranslate(0.0, 0.0, -5.0)
85
+ end
86
+
87
+ keyboard = Proc.new do|key, x, y|
88
+ case (key)
89
+ when 's'[0]
90
+ $shoulder = ($shoulder + 5) % 360
91
+ glutPostRedisplay()
92
+ when 'S'[0]
93
+ $shoulder = ($shoulder - 5) % 360
94
+ glutPostRedisplay()
95
+ when 'e'[0]
96
+ $elbow = ($elbow + 5) % 360
97
+ glutPostRedisplay()
98
+ when 'E'[0]
99
+ $elbow = ($elbow - 5) % 360
100
+ glutPostRedisplay()
101
+ when 27
102
+ exit(0)
103
+ end
104
+ end
105
+
106
+ glutInit
107
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
108
+ glutInitWindowSize(500, 500)
109
+ glutInitWindowPosition(100, 100)
110
+ glutCreateWindow($0)
111
+ init()
112
+ glutDisplayFunc(display)
113
+ glutReshapeFunc(reshape)
114
+ glutKeyboardFunc(keyboard)
115
+ glutMainLoop()
@@ -0,0 +1,196 @@
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
+ # select.c
39
+ # This is an illustration of the selection mode and
40
+ # name stack, which detects whether objects which collide
41
+ # with a viewing volume. First, four triangles and a
42
+ # rectangular box representing a viewing volume are drawn
43
+ # (drawScene routine). The green triangle and yellow
44
+ # triangles appear to lie within the viewing volume, but
45
+ # the red triangle appears to lie outside it. Then the
46
+ # selection mode is entered (selectObjects routine).
47
+ # Drawing to the screen ceases. To see if any collisions
48
+ # occur, the four triangles are called. In this example,
49
+ # the green triangle causes one hit with the name 1, and
50
+ # the yellow triangles cause one hit with the name 3.
51
+ require 'opengl'
52
+ include Gl,Glu,Glut
53
+
54
+ # draw a triangle with vertices at (x1, y1), (x2, y2)
55
+ # and (x3, y3) at z units away from the origin.
56
+ def drawTriangle(x1, y1, x2, y2, x3, y3, z)
57
+ glBegin(GL_TRIANGLES)
58
+ glVertex(x1, y1, z)
59
+ glVertex(x2, y2, z)
60
+ glVertex(x3, y3, z)
61
+ glEnd()
62
+ end
63
+
64
+ # draw a rectangular box with these outer x, y, and z values
65
+ def drawViewVolume(x1, x2, y1, y2, z1, z2)
66
+ glColor(1.0, 1.0, 1.0)
67
+ glBegin(GL_LINE_LOOP)
68
+ glVertex(x1, y1, -z1)
69
+ glVertex(x2, y1, -z1)
70
+ glVertex(x2, y2, -z1)
71
+ glVertex(x1, y2, -z1)
72
+ glEnd()
73
+
74
+ glBegin(GL_LINE_LOOP)
75
+ glVertex(x1, y1, -z2)
76
+ glVertex(x2, y1, -z2)
77
+ glVertex(x2, y2, -z2)
78
+ glVertex(x1, y2, -z2)
79
+ glEnd()
80
+
81
+ glBegin(GL_LINES)# 4 lines
82
+ glVertex(x1, y1, -z1)
83
+ glVertex(x1, y1, -z2)
84
+ glVertex(x1, y2, -z1)
85
+ glVertex(x1, y2, -z2)
86
+ glVertex(x2, y1, -z1)
87
+ glVertex(x2, y1, -z2)
88
+ glVertex(x2, y2, -z1)
89
+ glVertex(x2, y2, -z2)
90
+ glEnd()
91
+ end
92
+
93
+ # drawScene draws 4 triangles and a wire frame
94
+ # which represents the viewing volume.
95
+ def drawScene()
96
+ glMatrixMode(GL_PROJECTION)
97
+ glLoadIdentity()
98
+ gluPerspective(40.0, 4.0/3.0, 1.0, 100.0)
99
+
100
+ glMatrixMode(GL_MODELVIEW)
101
+ glLoadIdentity()
102
+ gluLookAt(7.5, 7.5, 12.5, 2.5, 2.5, -5.0, 0.0, 1.0, 0.0)
103
+ glColor(0.0, 1.0, 0.0)# green triangle
104
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0)
105
+ glColor(1.0, 0.0, 0.0)# red triangle
106
+ drawTriangle(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0)
107
+ glColor(1.0, 1.0, 0.0)# yellow triangles
108
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0)
109
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0)
110
+ drawViewVolume(0.0, 5.0, 0.0, 5.0, 0.0, 10.0)
111
+ end
112
+
113
+ # processHits prints out the contents of the selection array
114
+ def processHits(hits, buffer)
115
+ printf("hits = %d\n", hits)
116
+ ptr = buffer.unpack("I*")
117
+ p = 0
118
+ for i in 0...hits # for each hit
119
+ names = ptr[p]
120
+ printf(" number of names for hit = %d\n", names); p+=1
121
+ printf(" z1 is %g", ptr[p].to_f/0xffffffff); p+=1
122
+ printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1
123
+ printf(" the name is ")
124
+ for j in 0...names # for each name
125
+ printf("%d ", ptr[p]); p+=1
126
+ end
127
+ printf("\n")
128
+ end
129
+ end
130
+
131
+ # selectObjects "draws" the triangles in selection mode,
132
+ # assigning names for the triangles. Note that the third
133
+ # and fourth triangles share one name, so that if either
134
+ # or both triangles intersects the viewing/clipping volume,
135
+ # only one hit will be registered.
136
+
137
+ BUFSIZE=512
138
+
139
+ def selectObjects
140
+ selectBuf = glSelectBuffer(BUFSIZE)
141
+ glRenderMode(GL_SELECT)
142
+
143
+ glInitNames()
144
+ glPushName(0)
145
+
146
+ glPushMatrix()
147
+ glMatrixMode(GL_PROJECTION)
148
+ glLoadIdentity()
149
+ glOrtho(0.0, 5.0, 0.0, 5.0, 0.0, 10.0)
150
+ glMatrixMode(GL_MODELVIEW)
151
+ glLoadIdentity()
152
+ glLoadName(1)
153
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0)
154
+ glLoadName(2)
155
+ drawTriangle(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0)
156
+ glLoadName(3)
157
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0)
158
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0)
159
+ glPopMatrix()
160
+ glFlush()
161
+
162
+ hits = glRenderMode(GL_RENDER)
163
+ processHits(hits, selectBuf)
164
+ end
165
+
166
+ def init
167
+ glEnable(GL_DEPTH_TEST)
168
+ glShadeModel(GL_FLAT)
169
+ end
170
+
171
+ display = proc do
172
+ glClearColor(0.0, 0.0, 0.0, 0.0)
173
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
174
+ drawScene()
175
+ selectObjects()
176
+ glFlush()
177
+ end
178
+
179
+ keyboard = proc do |key, x, y|
180
+ case (key)
181
+ when 27
182
+ exit(0)
183
+ end
184
+ end
185
+
186
+ # Main Loop
187
+
188
+ GLUT.Init
189
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
190
+ glutInitWindowSize(500, 500)
191
+ glutInitWindowPosition(100, 100)
192
+ glutCreateWindow $0
193
+ init()
194
+ glutDisplayFunc(display)
195
+ glutKeyboardFunc(keyboard)
196
+ glutMainLoop()
@@ -0,0 +1,95 @@
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
+ # smooth.c
38
+ # This program demonstrates smooth shading.
39
+ # A smooth shaded polygon is drawn in a 2-D projection.
40
+
41
+ require 'opengl'
42
+ include Gl,Glu,Glut
43
+
44
+ def init
45
+ glClearColor(0,0,0,0)
46
+ glShadeModel(GL_SMOOTH)
47
+ end
48
+
49
+ def triangle
50
+ glBegin(GL_TRIANGLES)
51
+ glColor3f(1.0, 0.0, 0.0)
52
+ glVertex2f(5, 5)
53
+ glColor3f(0.0, 1.0, 0.0)
54
+ glVertex2f(25, 5)
55
+ glColor3f(0.0, 0.0, 1.0)
56
+ glVertex2f(5, 25)
57
+ glEnd()
58
+ end
59
+
60
+
61
+ display = Proc.new do
62
+ glClear(GL_COLOR_BUFFER_BIT)
63
+ triangle
64
+ glutSwapBuffers()
65
+ end
66
+
67
+ reshape = Proc.new do |w, h|
68
+ glViewport(0, 0, w, h)
69
+ glMatrixMode(GL_PROJECTION)
70
+ glLoadIdentity
71
+ if w<=h
72
+ gluOrtho2D(0,30,0, 30 * h/w)
73
+ else
74
+ gluOrtho2D(0,30 * w/h, 0,30)
75
+ end
76
+ glMatrixMode(GL_MODELVIEW)
77
+ end
78
+
79
+ keyboard = lambda do |key, x, y|
80
+ case(key)
81
+ when 27
82
+ exit(0)
83
+ end
84
+ end
85
+
86
+ glutInit()
87
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
88
+ glutInitWindowSize(500, 500)
89
+ glutInitWindowPosition(100, 100)
90
+ glutCreateWindow($0)
91
+ init()
92
+ glutDisplayFunc(display)
93
+ glutReshapeFunc(reshape)
94
+ glutKeyboardFunc(keyboard)
95
+ glutMainLoop()
@@ -0,0 +1,163 @@
1
+ #
2
+ # Copyright (c) Mark J. Kilgard, 1994.
3
+ #
4
+ # (c) Copyright 1993, Silicon Graphics, Inc.
5
+ # ALL RIGHTS RESERVED
6
+ # Permission to use, copy, modify, and distribute this software for
7
+ # any purpose and without fee is hereby granted, provided that the above
8
+ # copyright notice appear in all copies and that both the copyright notice
9
+ # and this permission notice appear in supporting documentation, and that
10
+ # the name of Silicon Graphics, Inc. not be used in advertising
11
+ # or publicity pertaining to distribution of the software without specific,
12
+ # written prior permission.
13
+ #
14
+ # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
15
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
16
+ # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
17
+ # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
18
+ # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
19
+ # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
20
+ # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
21
+ # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
22
+ # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
23
+ # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
24
+ # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
25
+ # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
26
+ #
27
+ # US Government Users Restricted Rights
28
+ # Use, duplication, or disclosure by the Government is subject to
29
+ # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
30
+ # (c)(1)(ii) of the Rights in Technical Data and Computer Software
31
+ # clause at DFARS 252.227-7013 and/or in similar or successor
32
+ # clauses in the FAR or the DOD or NASA FAR Supplement.
33
+ # Unpublished-- rights reserved under the copyright laws of the
34
+ # United States. Contractor/manufacturer is Silicon Graphics,
35
+ # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
36
+ #
37
+ # OpenGL(TM) is a trademark of Silicon Graphics, Inc.
38
+ #
39
+ # stencil.c
40
+ # This program draws two rotated tori in a window.
41
+ # A diamond in the center of the window masks out part
42
+ # of the scene. Within this mask, a different model
43
+ # (a sphere) is drawn in a different color.
44
+ #
45
+ require 'opengl'
46
+ require 'rational'
47
+ include Gl,Glu,Glut
48
+
49
+ YELLOWMAT=1
50
+ BLUEMAT=2
51
+
52
+ def myinit
53
+ yellow_diffuse = [ 0.7, 0.7, 0.0, 1.0 ]
54
+ yellow_specular = [ 1.0, 1.0, 1.0, 1.0 ]
55
+
56
+ blue_diffuse = [ 0.1, 0.1, 0.7, 1.0 ]
57
+ blue_specular = [ 0.1, 1.0, 1.0, 1.0 ]
58
+
59
+ position_one = [ 1.0, 1.0, 1.0, 0.0 ]
60
+
61
+ glNewList(YELLOWMAT, GL_COMPILE)
62
+ glMaterial(GL_FRONT, GL_DIFFUSE, yellow_diffuse)
63
+ glMaterial(GL_FRONT, GL_SPECULAR, yellow_specular)
64
+ glMaterial(GL_FRONT, GL_SHININESS, 64.0)
65
+ glEndList()
66
+
67
+ glNewList(BLUEMAT, GL_COMPILE)
68
+ glMaterial(GL_FRONT, GL_DIFFUSE, blue_diffuse)
69
+ glMaterial(GL_FRONT, GL_SPECULAR, blue_specular)
70
+ glMaterial(GL_FRONT, GL_SHININESS, 45.0)
71
+ glEndList()
72
+
73
+ glLight(GL_LIGHT0, GL_POSITION, position_one)
74
+
75
+ glEnable(GL_LIGHT0)
76
+ glEnable(GL_LIGHTING)
77
+ glEnable(GL_DEPTH_TEST)
78
+
79
+ glClearStencil(0x0)
80
+ glEnable(GL_STENCIL_TEST)
81
+ end
82
+
83
+ # Draw a sphere in a diamond-shaped section in the
84
+ # middle of a window with 2 tori.
85
+ display = Proc.new do
86
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
87
+
88
+ # draw blue sphere where the stencil is 1
89
+ glStencilFunc(GL_EQUAL, 0x1, 0x1)
90
+ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)
91
+ glCallList(BLUEMAT)
92
+ glutSolidSphere(0.5, 15, 15)
93
+
94
+ # draw the tori where the stencil is not 1
95
+ glStencilFunc(GL_NOTEQUAL, 0x1, 0x1)
96
+ glPushMatrix()
97
+ glRotate(45.0, 0.0, 0.0, 1.0)
98
+ glRotate(45.0, 0.0, 1.0, 0.0)
99
+ glCallList(YELLOWMAT)
100
+ glutSolidTorus(0.275, 0.85, 15, 15)
101
+ glPushMatrix()
102
+ glRotate(90.0, 1.0, 0.0, 0.0)
103
+ glutSolidTorus(0.275, 0.85, 15, 15)
104
+ glPopMatrix()
105
+ glPopMatrix()
106
+
107
+ glutSwapBuffers()
108
+ end
109
+
110
+ # Whenever the window is reshaped, redefine the
111
+ # coordinate system and redraw the stencil area.
112
+ myReshape = Proc.new do |w, h|
113
+ glViewport(0, 0, w, h)
114
+
115
+ # create a diamond shaped stencil area
116
+ glMatrixMode(GL_PROJECTION)
117
+ glLoadIdentity()
118
+ if w<=h
119
+ gluOrtho2D(-3.0, 3.0, -3.0*h/w, 3*h/w)
120
+ else
121
+ gluOrtho2D(-3.0*w/h, 3.0*w/h, -3.0, 3)
122
+ end
123
+ glMatrixMode(GL_MODELVIEW)
124
+ glLoadIdentity()
125
+
126
+ glClear(GL_STENCIL_BUFFER_BIT)
127
+ glStencilFunc(GL_ALWAYS, 0x1, 0x1)
128
+ glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE)
129
+ glBegin(GL_QUADS)
130
+ glVertex2f(-1.0, 0.0)
131
+ glVertex2f(0.0, 1.0)
132
+ glVertex2f(1.0, 0.0)
133
+ glVertex2f(0.0, -1.0)
134
+ glEnd()
135
+
136
+ glMatrixMode(GL_PROJECTION)
137
+ glLoadIdentity()
138
+ GLU.Perspective(45.0, w.to_f/h.to_f, 3.0, 7.0)
139
+ glMatrixMode(GL_MODELVIEW)
140
+ glLoadIdentity()
141
+ glTranslate(0.0, 0.0, -5.0)
142
+ end
143
+
144
+ keyboard = Proc.new do |key, x, y|
145
+ case (key)
146
+ when 27
147
+ exit(0);
148
+ end
149
+ end
150
+
151
+ # Main Loop
152
+ # Open window with initial window size, title bar,
153
+ # RGB display mode, and handle input events.
154
+ glutInit()
155
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL)
156
+ glutInitWindowSize(500, 500)
157
+ glutInitWindowPosition(100, 100)
158
+ glutCreateWindow($0)
159
+ myinit
160
+ glutReshapeFunc(myReshape)
161
+ glutDisplayFunc(display)
162
+ glutKeyboardFunc(keyboard)
163
+ glutMainLoop()