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,179 @@
1
+ #
2
+ # Copyright (c) Mark J. Kilgard, 1994. */
3
+ #
4
+ #
5
+ # (c) Copyright 1993, Silicon Graphics, Inc.
6
+ # ALL RIGHTS RESERVED
7
+ # Permission to use, copy, modify, and distribute this software for
8
+ # any purpose and without fee is hereby granted, provided that the above
9
+ # copyright notice appear in all copies and that both the copyright notice
10
+ # and this permission notice appear in supporting documentation, and that
11
+ # the name of Silicon Graphics, Inc. not be used in advertising
12
+ # or publicity pertaining to distribution of the software without specific,
13
+ # written prior permission.
14
+ #
15
+ # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
+ # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
+ # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
+ # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
+ # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
+ # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
+ # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
+ # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
+ # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
+ # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
+ # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ #
28
+ # US Government Users Restricted Rights
29
+ # Use, duplication, or disclosure by the Government is subject to
30
+ # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
+ # (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
+ # clause at DFARS 252.227-7013 and/or in similar or successor
33
+ # clauses in the FAR or the DOD or NASA FAR Supplement.
34
+ # Unpublished-- rights reserved under the copyright laws of the
35
+ # United States. Contractor/manufacturer is Silicon Graphics,
36
+ # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
37
+ #
38
+ # OpenGL(TM) is a trademark of Silicon Graphics, Inc.
39
+ #
40
+ # pickdepth.c
41
+ # Picking is demonstrated in this program. In
42
+ # rendering mode, three overlapping rectangles are
43
+ # drawn. When the left mouse button is pressed,
44
+ # selection mode is entered with the picking matrix.
45
+ # Rectangles which are drawn under the cursor position
46
+ # are "picked." Pay special attention to the depth
47
+ # value range, which is returned.
48
+ require 'opengl'
49
+ include Gl,Glu,Glut
50
+
51
+ def myinit
52
+ glClearColor(0.0, 0.0, 0.0, 0.0)
53
+ glDepthFunc(GL_LESS)
54
+ glEnable(GL_DEPTH_TEST)
55
+ glShadeModel(GL_FLAT)
56
+ glDepthRange(0.0, 1.0) #/* The default z mapping */
57
+ end
58
+
59
+ # The three rectangles are drawn. In selection mode,
60
+ # each rectangle is given the same name. Note that
61
+ # each rectangle is drawn with a different z value.
62
+ def drawRects(mode)
63
+ if (mode == GL_SELECT)
64
+ glLoadName(1)
65
+ end
66
+ glBegin(GL_QUADS)
67
+ glColor(1.0, 1.0, 0.0)
68
+ glVertex(2, 0, 0)
69
+ glVertex(2, 6, 0)
70
+ glVertex(6, 6, 0)
71
+ glVertex(6, 0, 0)
72
+ glEnd()
73
+ if (mode == GL_SELECT)
74
+ glLoadName(2)
75
+ end
76
+ glBegin(GL_QUADS)
77
+ glColor(0.0, 1.0, 1.0)
78
+ glVertex(3, 2, -1)
79
+ glVertex(3, 8, -1)
80
+ glVertex(8, 8, -1)
81
+ glVertex(8, 2, -1)
82
+ glEnd()
83
+ if (mode == GL_SELECT)
84
+ glLoadName(3)
85
+ end
86
+ glBegin(GL_QUADS)
87
+ glColor(1.0, 0.0, 1.0)
88
+ glVertex(0, 2, -2)
89
+ glVertex(0, 7, -2)
90
+ glVertex(5, 7, -2)
91
+ glVertex(5, 2, -2)
92
+ glEnd()
93
+ end
94
+
95
+ # processHits() prints out the contents of the
96
+ # selection array.
97
+ def processHits(hits, buffer)
98
+ printf("hits = %d\n", hits)
99
+ ptr = buffer.unpack("I*")
100
+ p = 0
101
+ for i in 0...hits # for each hit
102
+ names = ptr[p]
103
+ printf(" number of names for hit = %d\n", names); p+=1
104
+ printf(" z1 is %g", ptr[p].to_f/0xffffffff); p+=1
105
+ printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1
106
+ printf(" the name is ")
107
+ for j in 0...names # for each name
108
+ printf("%d ", ptr[p]) ; p+=1
109
+ end
110
+ printf("\n")
111
+ end
112
+ end
113
+
114
+ # pickRects() sets up selection mode, name stack,
115
+ # and projection matrix for picking. Then the objects
116
+ # are drawn.
117
+ BUFSIZE=512
118
+
119
+ pickRects = proc do |button, state, x, y|
120
+ if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
121
+ viewport = glGetDoublev(GL_VIEWPORT)
122
+
123
+ selectBuf = glSelectBuffer(BUFSIZE)
124
+ glRenderMode(GL_SELECT)
125
+
126
+ glInitNames()
127
+ glPushName(~0)
128
+
129
+ glMatrixMode(GL_PROJECTION)
130
+ glPushMatrix()
131
+ glLoadIdentity()
132
+ # create 5x5 pixel picking region near cursor location
133
+ gluPickMatrix( x, viewport[3] - y, 5.0, 5.0, viewport)
134
+ glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
135
+ drawRects(GL_SELECT)
136
+ glPopMatrix()
137
+ glFlush()
138
+
139
+ hits = glRenderMode(GL_RENDER)
140
+ processHits(hits, selectBuf)
141
+ end
142
+ end
143
+
144
+ display = proc do
145
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
146
+ drawRects(GL_RENDER)
147
+ glutSwapBuffers()
148
+ end
149
+
150
+ myReshape = proc do |w, h|
151
+ glViewport(0, 0, w, h)
152
+ glMatrixMode(GL_PROJECTION)
153
+ glLoadIdentity()
154
+ glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
155
+ glMatrixMode(GL_MODELVIEW)
156
+ glLoadIdentity()
157
+ end
158
+
159
+ keyboard = Proc.new do |key, x, y|
160
+ case (key)
161
+ when 27
162
+ exit(0)
163
+ end
164
+ end
165
+
166
+ # Main Loop
167
+ # Open window with initial window size, title bar,
168
+ # RGBA display mode, depth buffer, and handle input events.
169
+ glutInitWindowSize(500, 500)
170
+ glutInitWindowPosition(100, 100)
171
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
172
+ glutInit()
173
+ glutCreateWindow()
174
+ myinit()
175
+ glutMouseFunc(pickRects)
176
+ glutReshapeFunc(myReshape)
177
+ glutDisplayFunc(display)
178
+ glutKeyboardFunc(keyboard)
179
+ glutMainLoop()
@@ -33,80 +33,76 @@
33
33
  # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
34
  #
35
35
  # OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
- #/
37
-
38
36
  #
39
- # planet.c
40
- # This program shows how to composite modeling transformations
41
- # to draw translated and rotated models.
42
- # Interaction: pressing the d and y keys (day and year)
43
- # alters the rotation of the planet around the sun.
44
- #/
45
- require "gl_prev"
46
- require "glu_prev"
47
- require "glut_prev"
48
- require "rational"
37
+ # planet.c
38
+ # This program shows how to composite modeling transformations
39
+ # to draw translated and rotated models.
40
+ # Interaction: pressing the d and y keys (day and year)
41
+ # alters the rotation of the planet around the sun.
42
+ require 'opengl'
43
+ require 'rational'
44
+ include Gl,Glu,Glut
49
45
 
50
46
  STDOUT.sync = TRUE
51
47
 
52
- $year = 0; $day = 0;
48
+ $year = 0
49
+ $day = 0
53
50
 
54
51
  def init
55
- GL.ClearColor(0.0, 0.0, 0.0, 0.0);
56
- GL.ShadeModel(GL::FLAT);
52
+ glClearColor(0.0, 0.0, 0.0, 0.0)
53
+ glShadeModel(GL_FLAT)
57
54
  end
58
55
 
59
- display = Proc.new {
60
- GL.Clear(GL::COLOR_BUFFER_BIT);
61
- GL.Color(1.0, 1.0, 1.0);
62
-
63
- GL.PushMatrix();
64
- GLUT.WireSphere(1.0, 20, 16); # draw sun */
65
- GL.Rotate($year, 0.0, 1.0, 0.0);
66
- GL.Translate(2.0, 0.0, 0.0);
67
- GL.Rotate($day, 0.0, 1.0, 0.0);
68
- GLUT.WireSphere(0.2, 10, 8); # draw smaller planet */
69
- GL.PopMatrix();
70
- GLUT.SwapBuffers();
71
- }
56
+ display = Proc.new do
57
+ glClear(GL_COLOR_BUFFER_BIT)
58
+ glColor(1.0, 1.0, 1.0)
59
+
60
+ glPushMatrix()
61
+ glutWireSphere(1.0, 20, 16) # draw sun
62
+ glRotate($year, 0.0, 1.0, 0.0)
63
+ glTranslate(2.0, 0.0, 0.0)
64
+ glRotate($day, 0.0, 1.0, 0.0)
65
+ glutWireSphere(0.2, 10, 8) # draw smaller planet
66
+ glPopMatrix()
67
+ glutSwapBuffers()
68
+ end
72
69
 
73
- reshape = Proc.new { |w, h|
74
- GL.Viewport(0, 0, w, h);
75
- GL.MatrixMode(GL::PROJECTION);
76
- GL.LoadIdentity();
77
- GLU.Perspective(60.0, w.to_f/h.to_f, 1.0, 20.0);
78
- GL.MatrixMode(GL::MODELVIEW);
79
- GL.LoadIdentity();
80
- GLU.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
81
- }
70
+ reshape = Proc.new do |w, h|
71
+ glViewport(0, 0, w, h)
72
+ glMatrixMode(GL_PROJECTION)
73
+ glLoadIdentity()
74
+ gluPerspective(60.0, w.to_f/h.to_f, 1.0, 20.0)
75
+ glMatrixMode(GL_MODELVIEW)
76
+ glLoadIdentity()
77
+ gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
78
+ end
82
79
 
83
- # ARGSUSED1 */
84
- keyboard = Proc.new {|key, x, y|
85
- case (key)
86
- when 'd'[0]
87
- $day = ($day + 10) % 360;
88
- GLUT.PostRedisplay();
89
- when 'D'[0]
90
- $day = ($day - 10) % 360;
91
- GLUT.PostRedisplay();
92
- when 'y'[0]
93
- $year = ($year + 5) % 360;
94
- GLUT.PostRedisplay();
95
- when 'Y'[0]
96
- $year = ($year - 5) % 360;
97
- GLUT.PostRedisplay();
98
- when 27
99
- exit(0);
100
- end
101
- }
80
+ keyboard = Proc.new do |key, x, y|
81
+ case (key)
82
+ when 'd'[0]
83
+ $day = ($day + 10) % 360
84
+ glutPostRedisplay()
85
+ when 'D'[0]
86
+ $day = ($day - 10) % 360
87
+ glutPostRedisplay()
88
+ when 'y'[0]
89
+ $year = ($year + 5) % 360
90
+ glutPostRedisplay()
91
+ when 'Y'[0]
92
+ $year = ($year - 5) % 360
93
+ glutPostRedisplay()
94
+ when 27
95
+ exit(0)
96
+ end
97
+ end
102
98
 
103
- GLUT.Init
104
- GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB);
105
- GLUT.InitWindowSize(500, 500);
106
- GLUT.InitWindowPosition(100, 100);
107
- GLUT.CreateWindow($0);
108
- init();
109
- GLUT.DisplayFunc(display);
110
- GLUT.ReshapeFunc(reshape);
111
- GLUT.KeyboardFunc(keyboard);
112
- GLUT.MainLoop();
99
+ glutInit
100
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
101
+ glutInitWindowSize(500, 500)
102
+ glutInitWindowPosition(100, 100)
103
+ glutCreateWindow($0)
104
+ init()
105
+ glutDisplayFunc(display)
106
+ glutReshapeFunc(reshape)
107
+ glutKeyboardFunc(keyboard)
108
+ glutMainLoop()
@@ -0,0 +1,158 @@
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
+ # quadric.c
38
+ # This program demonstrates the use of some of the gluQuadric*
39
+ # routines. Quadric objects are created with some quadric
40
+ # properties and the callback routine to handle errors.
41
+ # Note that the cylinder has no top or bottom and the circle
42
+ # has a hole in it.
43
+ require 'opengl'
44
+ require 'mathn'
45
+ include Gl,Glu,Glut
46
+
47
+ $startList = nil
48
+
49
+ def init
50
+ mat_ambient = [ 0.5, 0.5, 0.5, 1.0 ]
51
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
52
+ mat_shininess = [ 50.0 ]
53
+ light_position = [ 1.0, 1.0, 1.0, 0.0 ]
54
+ model_ambient = [ 0.5, 0.5, 0.5, 1.0 ]
55
+
56
+ glClearColor(0.0, 0.0, 0.0, 0.0)
57
+
58
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
59
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
60
+ glMaterial(GL_FRONT, GL_SHININESS, mat_shininess)
61
+ glLight(GL_LIGHT0, GL_POSITION, light_position)
62
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, model_ambient)
63
+
64
+ glEnable(GL_LIGHTING)
65
+ glEnable(GL_LIGHT0)
66
+ glEnable(GL_DEPTH_TEST)
67
+
68
+ # Create 4 display lists, each with a different quadric object.
69
+ # Different drawing styles and surface normal specifications
70
+ # are demonstrated.
71
+ $startList = glGenLists(4)
72
+ qobj = gluNewQuadric()
73
+
74
+ gluQuadricDrawStyle(qobj, GLU_FILL) # smooth shaded
75
+ gluQuadricNormals(qobj, GLU_SMOOTH)
76
+ glNewList($startList, GL_COMPILE)
77
+ gluSphere(qobj, 0.75, 15, 10)
78
+ glEndList()
79
+
80
+ gluQuadricDrawStyle(qobj, GLU_FILL) # flat shaded
81
+ gluQuadricNormals(qobj, GLU_FLAT)
82
+ glNewList($startList+1, GL_COMPILE)
83
+ gluCylinder(qobj, 0.5, 0.3, 1.0, 15, 5)
84
+ glEndList()
85
+
86
+ gluQuadricDrawStyle(qobj, GLU_LINE) # all polygons wireframe
87
+ gluQuadricNormals(qobj, GLU_NONE)
88
+ glNewList($startList+2, GL_COMPILE)
89
+ gluDisk(qobj, 0.25, 1.0, 20, 4)
90
+ glEndList()
91
+
92
+ gluQuadricDrawStyle(qobj, GLU_SILHOUETTE) # boundary only
93
+ gluQuadricNormals(qobj, GLU_NONE)
94
+ glNewList($startList+3, GL_COMPILE)
95
+ gluPartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0)
96
+ glEndList()
97
+ end
98
+
99
+ display = Proc.new do
100
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
101
+ glPushMatrix()
102
+
103
+ glEnable(GL_LIGHTING)
104
+ glShadeModel(GL_SMOOTH)
105
+ glTranslate(-1.0, -1.0, 0.0)
106
+ glCallList($startList)
107
+
108
+ glShadeModel(GL_FLAT)
109
+ glTranslate(0.0, 2.0, 0.0)
110
+ glPushMatrix()
111
+ glRotate(300.0, 1.0, 0.0, 0.0)
112
+ glCallList($startList+1)
113
+ glPopMatrix()
114
+
115
+ glDisable(GL_LIGHTING)
116
+ glColor(0.0, 1.0, 1.0)
117
+ glTranslate(2.0, -2.0, 0.0)
118
+ glCallList($startList+2)
119
+
120
+ glColor(1.0, 1.0, 0.0)
121
+ glTranslate(0.0, 2.0, 0.0)
122
+ glCallList($startList+3)
123
+
124
+ glPopMatrix()
125
+ glutSwapBuffers()
126
+ end
127
+
128
+ reshape = Proc.new do |w, h|
129
+ glViewport(0, 0, w, h)
130
+ glMatrixMode(GL_PROJECTION)
131
+ glLoadIdentity()
132
+ if (w <= h)
133
+ glOrtho(-2.5, 2.5, -2.5*h/w, 2.5*h/w, -10.0, 10.0)
134
+ else
135
+ glOrtho(-2.5*w/h, 2.5*w/h, -2.5, 2.5, -10.0, 10.0)
136
+ end
137
+ glMatrixMode(GL_MODELVIEW)
138
+ glLoadIdentity()
139
+ end
140
+
141
+ keyboard = Proc.new do |key, x, y|
142
+ case (key)
143
+ when 27
144
+ exit(0)
145
+ end
146
+ end
147
+
148
+ # main
149
+ glutInit
150
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
151
+ glutInitWindowSize(500, 500)
152
+ glutInitWindowPosition(100, 100)
153
+ glutCreateWindow($0)
154
+ init()
155
+ glutDisplayFunc(display)
156
+ glutReshapeFunc(reshape)
157
+ glutKeyboardFunc(keyboard)
158
+ glutMainLoop()