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,6 +1,8 @@
1
1
  # This example comes from the Red Book chapter 5, example 5-1 light.c
2
2
 
3
3
  require 'opengl'
4
+ require 'glu'
5
+ require 'glut'
4
6
  require 'mathn'
5
7
 
6
8
  def init
@@ -151,4 +153,3 @@ glutDisplayFunc :display
151
153
  glutReshapeFunc :reshape
152
154
  glutKeyboardFunc :keyboard
153
155
  glutMainLoop
154
-
@@ -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
@@ -38,91 +38,93 @@
38
38
  # This program demonstrates geometric primitives and
39
39
  # their attributes.
40
40
  require 'opengl'
41
+ require 'glu'
42
+ require 'glut'
41
43
  require 'mathn'
42
44
  include Gl,Glu,Glut
43
45
 
44
46
  def drawOneLine(x1,y1,x2,y2)
45
- glBegin(GL_LINES)
46
- glVertex((x1),(y1))
47
- glVertex((x2),(y2))
48
- glEnd()
47
+ glBegin(GL_LINES)
48
+ glVertex((x1),(y1))
49
+ glVertex((x2),(y2))
50
+ glEnd()
49
51
  end
50
52
 
51
53
  def init
52
- glClearColor(0.0, 0.0, 0.0, 0.0)
53
- glShadeModel(GL_FLAT)
54
+ glClearColor(0.0, 0.0, 0.0, 0.0)
55
+ glShadeModel(GL_FLAT)
54
56
  end
55
57
 
56
58
  display = Proc.new do
57
- glClear(GL_COLOR_BUFFER_BIT)
58
-
59
- # select white for all lines
60
- glColor(1.0, 1.0, 1.0)
61
-
62
- # in 1st row, 3 lines, each with a different stipple
63
- glEnable(GL_LINE_STIPPLE)
64
-
65
- glLineStipple(1, 0x0101) # dotted
66
- drawOneLine(50.0, 125.0, 150.0, 125.0)
67
- glLineStipple(1, 0x00FF) # dashed
68
- drawOneLine(150.0, 125.0, 250.0, 125.0)
69
- glLineStipple(1, 0x1C47) # dash/dot/dash
70
- drawOneLine(250.0, 125.0, 350.0, 125.0)
71
-
72
- # in 2nd row, 3 wide lines, each with different stipple
73
- glLineWidth(5.0)
74
- glLineStipple(1, 0x0101) # dotted
75
- drawOneLine(50.0, 100.0, 150.0, 100.0)
76
- glLineStipple(1, 0x00FF) # dashed
77
- drawOneLine(150.0, 100.0, 250.0, 100.0)
78
- glLineStipple(1, 0x1C47) # dash/dot/dash
79
- drawOneLine(250.0, 100.0, 350.0, 100.0)
80
- glLineWidth(1.0)
81
-
82
- # in 3rd row, 6 lines, with dash/dot/dash stipple
83
- # as part of a single connected line strip
84
- glLineStipple(1, 0x1C47) # dash/dot/dash
85
- glBegin(GL_LINE_STRIP)
86
- for i in 0..6
87
- glVertex(50.0 + (i * 50.0), 75.0)
88
- end
89
- glEnd()
90
-
91
- # in 4th row, 6 independent lines with same stipple
92
- for i in 0..5
93
- drawOneLine(50.0 + (i * 50.0), 50.0, 50.0 + ((i+1) * 50.0), 50.0)
94
- end
95
-
96
- # in 5th row, 1 line, with dash/dot/dash stipple
97
- # and a stipple repeat factor of 5
98
- glLineStipple(5, 0x1C47) # dash/dot/dash
99
- drawOneLine(50.0, 25.0, 350.0, 25.0)
100
-
101
- glDisable(GL_LINE_STIPPLE)
102
- glutSwapBuffers()
59
+ glClear(GL_COLOR_BUFFER_BIT)
60
+
61
+ # select white for all lines
62
+ glColor(1.0, 1.0, 1.0)
63
+
64
+ # in 1st row, 3 lines, each with a different stipple
65
+ glEnable(GL_LINE_STIPPLE)
66
+
67
+ glLineStipple(1, 0x0101) # dotted
68
+ drawOneLine(50.0, 125.0, 150.0, 125.0)
69
+ glLineStipple(1, 0x00FF) # dashed
70
+ drawOneLine(150.0, 125.0, 250.0, 125.0)
71
+ glLineStipple(1, 0x1C47) # dash/dot/dash
72
+ drawOneLine(250.0, 125.0, 350.0, 125.0)
73
+
74
+ # in 2nd row, 3 wide lines, each with different stipple
75
+ glLineWidth(5.0)
76
+ glLineStipple(1, 0x0101) # dotted
77
+ drawOneLine(50.0, 100.0, 150.0, 100.0)
78
+ glLineStipple(1, 0x00FF) # dashed
79
+ drawOneLine(150.0, 100.0, 250.0, 100.0)
80
+ glLineStipple(1, 0x1C47) # dash/dot/dash
81
+ drawOneLine(250.0, 100.0, 350.0, 100.0)
82
+ glLineWidth(1.0)
83
+
84
+ # in 3rd row, 6 lines, with dash/dot/dash stipple
85
+ # as part of a single connected line strip
86
+ glLineStipple(1, 0x1C47) # dash/dot/dash
87
+ glBegin(GL_LINE_STRIP)
88
+ for i in 0..6
89
+ glVertex(50.0 + (i * 50.0), 75.0)
90
+ end
91
+ glEnd()
92
+
93
+ # in 4th row, 6 independent lines with same stipple
94
+ for i in 0..5
95
+ drawOneLine(50.0 + (i * 50.0), 50.0, 50.0 + ((i+1) * 50.0), 50.0)
96
+ end
97
+
98
+ # in 5th row, 1 line, with dash/dot/dash stipple
99
+ # and a stipple repeat factor of 5
100
+ glLineStipple(5, 0x1C47) # dash/dot/dash
101
+ drawOneLine(50.0, 25.0, 350.0, 25.0)
102
+
103
+ glDisable(GL_LINE_STIPPLE)
104
+ glutSwapBuffers()
103
105
  end
104
106
 
105
107
  reshape = Proc.new do |w, h|
106
- glViewport(0, 0, w, h)
107
- glMatrixMode(GL_PROJECTION)
108
- glLoadIdentity()
109
- GLU.Ortho2D(0.0, w, 0.0, h)
108
+ glViewport(0, 0, w, h)
109
+ glMatrixMode(GL_PROJECTION)
110
+ glLoadIdentity()
111
+ GLU.Ortho2D(0.0, w, 0.0, h)
110
112
  end
111
113
 
112
114
  keyboard = Proc.new do |key, x, y|
113
- case (key)
114
- when ?\e
115
- exit(0)
116
- end
115
+ case (key)
116
+ when ?\e
117
+ exit(0)
118
+ end
117
119
  end
118
120
 
119
121
  glutInit
120
122
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
121
- glutInitWindowSize(400, 150)
123
+ glutInitWindowSize(400, 150)
122
124
  glutInitWindowPosition(100, 100)
123
125
  glutCreateWindow($0)
124
126
  init()
125
- glutDisplayFunc(display)
127
+ glutDisplayFunc(display)
126
128
  glutReshapeFunc(reshape)
127
129
  glutKeyboardFunc(keyboard)
128
130
  glutMainLoop()
@@ -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
@@ -35,69 +35,71 @@
35
35
  # OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
36
  #
37
37
  # list.c
38
- # This program demonstrates how to make and execute a
39
- # display list. Note that attributes, such as current
38
+ # This program demonstrates how to make and execute a
39
+ # display list. Note that attributes, such as current
40
40
  # color and matrix, are changed.
41
41
  require 'opengl'
42
+ require 'glu'
43
+ require 'glut'
42
44
  require 'mathn'
43
45
  include Gl,Glu,Glut
44
46
 
45
47
  $listName = 0
46
48
 
47
49
  def init
48
- $listName = glGenLists(1)
49
- glNewList($listName, GL_COMPILE)
50
- glColor(1.0, 0.0, 0.0) # /* current color red */
51
- glBegin(GL_TRIANGLES)
52
- glVertex(0.0, 0.0)
53
- glVertex(1.0, 0.0)
54
- glVertex(0.0, 1.0)
55
- glEnd()
56
- glTranslate(1.5, 0.0, 0.0) # /* move position */
57
- glEndList()
58
- glShadeModel(GL_FLAT)
50
+ $listName = glGenLists(1)
51
+ glNewList($listName, GL_COMPILE)
52
+ glColor(1.0, 0.0, 0.0) # /* current color red */
53
+ glBegin(GL_TRIANGLES)
54
+ glVertex(0.0, 0.0)
55
+ glVertex(1.0, 0.0)
56
+ glVertex(0.0, 1.0)
57
+ glEnd()
58
+ glTranslate(1.5, 0.0, 0.0) # /* move position */
59
+ glEndList()
60
+ glShadeModel(GL_FLAT)
59
61
  end
60
62
 
61
63
  def drawLine
62
- glBegin(GL_LINES)
63
- glVertex(0.0, 0.5)
64
- glVertex(15.0, 0.5)
65
- glEnd()
64
+ glBegin(GL_LINES)
65
+ glVertex(0.0, 0.5)
66
+ glVertex(15.0, 0.5)
67
+ glEnd()
66
68
  end
67
69
 
68
70
  display = Proc.new do
69
- glClear(GL_COLOR_BUFFER_BIT)
70
- glColor(0.0, 1.0, 0.0) # current color green
71
- for i in (0..9 ) # draw 10 triangles
72
- glCallList($listName)
73
- end
74
- drawLine() # is this line green? NO!
75
- # where is the line drawn?
76
- glutSwapBuffers()
71
+ glClear(GL_COLOR_BUFFER_BIT)
72
+ glColor(0.0, 1.0, 0.0) # current color green
73
+ for i in (0..9 ) # draw 10 triangles
74
+ glCallList($listName)
75
+ end
76
+ drawLine() # is this line green? NO!
77
+ # where is the line drawn?
78
+ glutSwapBuffers()
77
79
  end
78
80
 
79
81
  reshape = Proc.new do |w, h|
80
- glViewport(0, 0, w, h)
81
- glMatrixMode(GL_PROJECTION)
82
- glLoadIdentity()
83
- if (w <= h)
84
- GLU.Ortho2D(0.0, 2.0, -0.5 * h/w, 1.5 * h/w)
85
- else
86
- GLU.Ortho2D(0.0, 2.0 * w/h, -0.5, 1.5)
87
- end
88
- glMatrixMode(GL_MODELVIEW)
89
- glLoadIdentity()
82
+ glViewport(0, 0, w, h)
83
+ glMatrixMode(GL_PROJECTION)
84
+ glLoadIdentity()
85
+ if (w <= h)
86
+ GLU.Ortho2D(0.0, 2.0, -0.5 * h/w, 1.5 * h/w)
87
+ else
88
+ GLU.Ortho2D(0.0, 2.0 * w/h, -0.5, 1.5)
89
+ end
90
+ glMatrixMode(GL_MODELVIEW)
91
+ glLoadIdentity()
90
92
  end
91
93
 
92
94
  keyboard = Proc.new do |key, x, y|
93
- case (key)
94
- when ?\e
95
- exit(0)
96
- end
95
+ case (key)
96
+ when ?\e
97
+ exit(0)
98
+ end
97
99
  end
98
100
 
99
101
  # Main Loop
100
- # Open window with initial window size, title bar,
102
+ # Open window with initial window size, title bar,
101
103
  # RGBA display mode, and handle input events.
102
104
  glutInit
103
105
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
@@ -2,14 +2,14 @@
2
2
  # Copyright (c) Mark J. Kilgard, 1994.
3
3
  #
4
4
  # (c) Copyright 1993, Silicon Graphics, Inc.
5
- # ALL RIGHTS RESERVED
6
- # Permission to use, copy, modify, and distribute this software for
5
+ # ALL RIGHTS RESERVED
6
+ # Permission to use, copy, modify, and distribute this software for
7
7
  # any purpose and without fee is hereby granted, provided that the above
8
8
  # copyright notice appear in all copies and that both the copyright notice
9
- # and this permission notice appear in supporting documentation, and that
9
+ # and this permission notice appear in supporting documentation, and that
10
10
  # the name of Silicon Graphics, Inc. not be used in advertising
11
11
  # or publicity pertaining to distribution of the software without specific,
12
- # written prior permission.
12
+ # written prior permission.
13
13
  #
14
14
  # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
15
15
  # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
@@ -23,8 +23,8 @@
23
23
  # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
24
24
  # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
25
25
  # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
26
- #
27
- # US Government Users Restricted Rights
26
+ #
27
+ # US Government Users Restricted Rights
28
28
  # Use, duplication, or disclosure by the Government is subject to
29
29
  # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
30
30
  # (c)(1)(ii) of the Rights in Technical Data and Computer Software
@@ -41,33 +41,35 @@
41
41
  # Several objects are drawn using different material characteristics.
42
42
  # A single light source illuminates the objects.
43
43
  require 'opengl'
44
+ require 'glu'
45
+ require 'glut'
44
46
  include Gl,Glu,Glut
45
47
 
46
- # Initialize z-buffer, projection matrix, light source,
48
+ # Initialize z-buffer, projection matrix, light source,
47
49
  # and lighting model. Do not specify a material property here.
48
50
  def myinit
49
- ambient = [ 0.0, 0.0, 0.0, 1.0 ]
50
- diffuse = [ 1.0, 1.0, 1.0, 1.0 ]
51
- position = [ 0.0, 3.0, 2.0, 0.0 ]
52
- lmodel_ambient = [ 0.4, 0.4, 0.4, 1.0 ]
53
- local_view = [ 0.0 ]
54
-
55
- glEnable(GL_DEPTH_TEST)
56
- glDepthFunc(GL_LESS)
57
-
58
- glLight(GL_LIGHT0, GL_AMBIENT, ambient)
59
- glLight(GL_LIGHT0, GL_DIFFUSE, diffuse)
60
- glLight(GL_LIGHT0, GL_POSITION, position)
61
- glLightModel(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient)
62
- glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
63
-
64
- glEnable(GL_LIGHTING)
65
- glEnable(GL_LIGHT0)
66
-
67
- glClearColor(0.0, 0.1, 0.1, 0.0)
51
+ ambient = [ 0.0, 0.0, 0.0, 1.0 ]
52
+ diffuse = [ 1.0, 1.0, 1.0, 1.0 ]
53
+ position = [ 0.0, 3.0, 2.0, 0.0 ]
54
+ lmodel_ambient = [ 0.4, 0.4, 0.4, 1.0 ]
55
+ local_view = [ 0.0 ]
56
+
57
+ glEnable(GL_DEPTH_TEST)
58
+ glDepthFunc(GL_LESS)
59
+
60
+ glLight(GL_LIGHT0, GL_AMBIENT, ambient)
61
+ glLight(GL_LIGHT0, GL_DIFFUSE, diffuse)
62
+ glLight(GL_LIGHT0, GL_POSITION, position)
63
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient)
64
+ glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
65
+
66
+ glEnable(GL_LIGHTING)
67
+ glEnable(GL_LIGHT0)
68
+
69
+ glClearColor(0.0, 0.1, 0.1, 0.0)
68
70
  end
69
71
 
70
- # Draw twelve spheres in 3 rows with 4 columns.
72
+ # Draw twelve spheres in 3 rows with 4 columns.
71
73
  # The spheres in the first row have materials with no ambient reflection.
72
74
  # The second row has materials with significant ambient reflection.
73
75
  # The third row has materials with colored ambient reflection.
@@ -81,186 +83,186 @@ end
81
83
  #
82
84
  # glTranslatef() is used to move spheres to their appropriate locations.
83
85
  display = proc do
84
- no_mat = [ 0.0, 0.0, 0.0, 1.0 ]
85
- mat_ambient = [ 0.7, 0.7, 0.7, 1.0 ]
86
- mat_ambient_color = [ 0.8, 0.8, 0.2, 1.0 ]
87
- mat_diffuse = [ 0.1, 0.5, 0.8, 1.0 ]
88
- mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
89
- no_shininess = [ 0.0 ]
90
- low_shininess = [ 5.0 ]
91
- high_shininess = [ 100.0 ]
92
- mat_emission = [0.3, 0.2, 0.2, 0.0]
93
-
94
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
95
-
96
- # draw sphere in first row, first column
97
- # diffuse reflection only no ambient or specular
98
- glPushMatrix()
99
- glTranslate(-3.75, 3.0, 0.0)
100
- glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
101
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
102
- glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
103
- glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
104
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
105
- glutSolidSphere(1.0, 16, 16)
106
- glPopMatrix()
107
-
108
- # draw sphere in first row, second column
109
- # diffuse and specular reflection low shininess no ambient
110
- glPushMatrix()
111
- glTranslate(-1.25, 3.0, 0.0)
112
- glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
113
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
114
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
115
- glMaterial(GL_FRONT, GL_SHININESS, low_shininess)
116
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
117
- glutSolidSphere(1.0, 16, 16)
118
- glPopMatrix()
119
-
120
- # draw sphere in first row, third column
121
- # diffuse and specular reflection high shininess no ambient
122
- glPushMatrix()
123
- glTranslate(1.25, 3.0, 0.0)
124
- glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
125
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
126
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
127
- glMaterial(GL_FRONT, GL_SHININESS, high_shininess)
128
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
129
- glutSolidSphere(1.0, 16, 16)
130
- glPopMatrix()
131
-
132
- # draw sphere in first row, fourth column
133
- # diffuse reflection emission no ambient or specular reflection
134
- glPushMatrix()
135
- glTranslate(3.75, 3.0, 0.0)
136
- glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
137
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
138
- glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
139
- glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
140
- glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
141
- glutSolidSphere(1.0, 16, 16)
142
- glPopMatrix()
143
-
144
- # draw sphere in second row, first column
145
- # ambient and diffuse reflection no specular
146
- glPushMatrix()
147
- glTranslate(-3.75, 0.0, 0.0)
148
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
149
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
150
- glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
151
- glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
152
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
153
- glutSolidSphere(1.0, 16, 16)
154
- glPopMatrix()
155
-
156
- # draw sphere in second row, second column
157
- # ambient, diffuse and specular reflection low shininess
158
- glPushMatrix()
159
- glTranslate(-1.25, 0.0, 0.0)
160
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
161
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
162
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
163
- glMaterial(GL_FRONT, GL_SHININESS, low_shininess)
164
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
165
- glutSolidSphere(1.0, 16, 16)
166
- glPopMatrix()
167
-
168
- # draw sphere in second row, third column
169
- # ambient, diffuse and specular reflection high shininess
170
- glPushMatrix()
171
- glTranslate(1.25, 0.0, 0.0)
172
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
173
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
174
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
175
- glMaterial(GL_FRONT, GL_SHININESS, high_shininess)
176
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
177
- glutSolidSphere(1.0, 16, 16)
178
- glPopMatrix()
179
-
180
- # draw sphere in second row, fourth column
181
- # ambient and diffuse reflection emission no specular
182
- glPushMatrix()
183
- glTranslate(3.75, 0.0, 0.0)
184
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
185
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
186
- glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
187
- glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
188
- glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
189
- glutSolidSphere(1.0, 16, 16)
190
- glPopMatrix()
191
-
192
- # draw sphere in third row, first column
193
- # colored ambient and diffuse reflection no specular
194
- glPushMatrix()
195
- glTranslate(-3.75, -3.0, 0.0)
196
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
197
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
198
- glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
199
- glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
200
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
201
- glutSolidSphere(1.0, 16, 16)
202
- glPopMatrix()
203
-
204
- # draw sphere in third row, second column
205
- # colored ambient, diffuse and specular reflection low shininess
206
- glPushMatrix()
207
- glTranslate(-1.25, -3.0, 0.0)
208
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
209
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
210
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
211
- glMaterial(GL_FRONT, GL_SHININESS, low_shininess)
212
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
213
- glutSolidSphere(1.0, 16, 16)
214
- glPopMatrix()
215
-
216
- # draw sphere in third row, third column
217
- # colored ambient, diffuse and specular reflection high shininess
218
- glPushMatrix()
219
- glTranslate(1.25, -3.0, 0.0)
220
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
221
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
222
- glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
223
- glMaterial(GL_FRONT, GL_SHININESS, high_shininess)
224
- glMaterial(GL_FRONT, GL_EMISSION, no_mat)
225
- glutSolidSphere(1.0, 16, 16)
226
- glPopMatrix()
227
-
228
- # draw sphere in third row, fourth column
229
- # colored ambient and diffuse reflection emission no specular
230
- glPushMatrix()
231
- glTranslate(3.75, -3.0, 0.0)
232
- glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
233
- glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
234
- glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
235
- glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
236
- glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
237
- glutSolidSphere(1.0, 16, 16)
238
- glPopMatrix()
239
-
240
- glutSwapBuffers()
86
+ no_mat = [ 0.0, 0.0, 0.0, 1.0 ]
87
+ mat_ambient = [ 0.7, 0.7, 0.7, 1.0 ]
88
+ mat_ambient_color = [ 0.8, 0.8, 0.2, 1.0 ]
89
+ mat_diffuse = [ 0.1, 0.5, 0.8, 1.0 ]
90
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
91
+ no_shininess = [ 0.0 ]
92
+ low_shininess = [ 5.0 ]
93
+ high_shininess = [ 100.0 ]
94
+ mat_emission = [0.3, 0.2, 0.2, 0.0]
95
+
96
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
97
+
98
+ # draw sphere in first row, first column
99
+ # diffuse reflection only no ambient or specular
100
+ glPushMatrix()
101
+ glTranslate(-3.75, 3.0, 0.0)
102
+ glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
103
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
104
+ glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
105
+ glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
106
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
107
+ glutSolidSphere(1.0, 16, 16)
108
+ glPopMatrix()
109
+
110
+ # draw sphere in first row, second column
111
+ # diffuse and specular reflection low shininess no ambient
112
+ glPushMatrix()
113
+ glTranslate(-1.25, 3.0, 0.0)
114
+ glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
115
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
116
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
117
+ glMaterial(GL_FRONT, GL_SHININESS, low_shininess)
118
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
119
+ glutSolidSphere(1.0, 16, 16)
120
+ glPopMatrix()
121
+
122
+ # draw sphere in first row, third column
123
+ # diffuse and specular reflection high shininess no ambient
124
+ glPushMatrix()
125
+ glTranslate(1.25, 3.0, 0.0)
126
+ glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
127
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
128
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
129
+ glMaterial(GL_FRONT, GL_SHININESS, high_shininess)
130
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
131
+ glutSolidSphere(1.0, 16, 16)
132
+ glPopMatrix()
133
+
134
+ # draw sphere in first row, fourth column
135
+ # diffuse reflection emission no ambient or specular reflection
136
+ glPushMatrix()
137
+ glTranslate(3.75, 3.0, 0.0)
138
+ glMaterial(GL_FRONT, GL_AMBIENT, no_mat)
139
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
140
+ glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
141
+ glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
142
+ glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
143
+ glutSolidSphere(1.0, 16, 16)
144
+ glPopMatrix()
145
+
146
+ # draw sphere in second row, first column
147
+ # ambient and diffuse reflection no specular
148
+ glPushMatrix()
149
+ glTranslate(-3.75, 0.0, 0.0)
150
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
151
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
152
+ glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
153
+ glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
154
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
155
+ glutSolidSphere(1.0, 16, 16)
156
+ glPopMatrix()
157
+
158
+ # draw sphere in second row, second column
159
+ # ambient, diffuse and specular reflection low shininess
160
+ glPushMatrix()
161
+ glTranslate(-1.25, 0.0, 0.0)
162
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
163
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
164
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
165
+ glMaterial(GL_FRONT, GL_SHININESS, low_shininess)
166
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
167
+ glutSolidSphere(1.0, 16, 16)
168
+ glPopMatrix()
169
+
170
+ # draw sphere in second row, third column
171
+ # ambient, diffuse and specular reflection high shininess
172
+ glPushMatrix()
173
+ glTranslate(1.25, 0.0, 0.0)
174
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
175
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
176
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
177
+ glMaterial(GL_FRONT, GL_SHININESS, high_shininess)
178
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
179
+ glutSolidSphere(1.0, 16, 16)
180
+ glPopMatrix()
181
+
182
+ # draw sphere in second row, fourth column
183
+ # ambient and diffuse reflection emission no specular
184
+ glPushMatrix()
185
+ glTranslate(3.75, 0.0, 0.0)
186
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
187
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
188
+ glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
189
+ glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
190
+ glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
191
+ glutSolidSphere(1.0, 16, 16)
192
+ glPopMatrix()
193
+
194
+ # draw sphere in third row, first column
195
+ # colored ambient and diffuse reflection no specular
196
+ glPushMatrix()
197
+ glTranslate(-3.75, -3.0, 0.0)
198
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
199
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
200
+ glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
201
+ glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
202
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
203
+ glutSolidSphere(1.0, 16, 16)
204
+ glPopMatrix()
205
+
206
+ # draw sphere in third row, second column
207
+ # colored ambient, diffuse and specular reflection low shininess
208
+ glPushMatrix()
209
+ glTranslate(-1.25, -3.0, 0.0)
210
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
211
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
212
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
213
+ glMaterial(GL_FRONT, GL_SHININESS, low_shininess)
214
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
215
+ glutSolidSphere(1.0, 16, 16)
216
+ glPopMatrix()
217
+
218
+ # draw sphere in third row, third column
219
+ # colored ambient, diffuse and specular reflection high shininess
220
+ glPushMatrix()
221
+ glTranslate(1.25, -3.0, 0.0)
222
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
223
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
224
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
225
+ glMaterial(GL_FRONT, GL_SHININESS, high_shininess)
226
+ glMaterial(GL_FRONT, GL_EMISSION, no_mat)
227
+ glutSolidSphere(1.0, 16, 16)
228
+ glPopMatrix()
229
+
230
+ # draw sphere in third row, fourth column
231
+ # colored ambient and diffuse reflection emission no specular
232
+ glPushMatrix()
233
+ glTranslate(3.75, -3.0, 0.0)
234
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient_color)
235
+ glMaterial(GL_FRONT, GL_DIFFUSE, mat_diffuse)
236
+ glMaterial(GL_FRONT, GL_SPECULAR, no_mat)
237
+ glMaterial(GL_FRONT, GL_SHININESS, no_shininess)
238
+ glMaterial(GL_FRONT, GL_EMISSION, mat_emission)
239
+ glutSolidSphere(1.0, 16, 16)
240
+ glPopMatrix()
241
+
242
+ glutSwapBuffers()
241
243
  end
242
244
 
243
245
  myReshape = proc do |w, h|
244
- glViewport(0, 0, w, h)
245
- glMatrixMode(GL_PROJECTION)
246
- glLoadIdentity()
247
- if (w <= (h * 2))
248
- glOrtho(-6.0, 6.0, -3.0*(h.to_f*2)/w, 3.0*(h.to_f*2)/w, -10.0, 10.0)
249
- else
250
- glOrtho(-6.0*w.to_f/(h*2), 6.0*w.to_f/(h*2), -3.0, 3.0, -10.0, 10.0)
251
- end
252
- glMatrixMode(GL_MODELVIEW)
246
+ glViewport(0, 0, w, h)
247
+ glMatrixMode(GL_PROJECTION)
248
+ glLoadIdentity()
249
+ if (w <= (h * 2))
250
+ glOrtho(-6.0, 6.0, -3.0*(h.to_f*2)/w, 3.0*(h.to_f*2)/w, -10.0, 10.0)
251
+ else
252
+ glOrtho(-6.0*w.to_f/(h*2), 6.0*w.to_f/(h*2), -3.0, 3.0, -10.0, 10.0)
253
+ end
254
+ glMatrixMode(GL_MODELVIEW)
253
255
  end
254
256
 
255
257
  keyboard = Proc.new do |key, x, y|
256
- case (key)
257
- when ?\e
258
- exit(0);
259
- end
258
+ case (key)
259
+ when ?\e
260
+ exit(0);
261
+ end
260
262
  end
261
263
 
262
264
  # Main Loop
263
- # Open window with initial window size, title bar,
265
+ # Open window with initial window size, title bar,
264
266
  # RGBA display mode, and handle input events.
265
267
  glutInit()
266
268
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
@@ -272,4 +274,3 @@ glutReshapeFunc(myReshape)
272
274
  glutDisplayFunc(display)
273
275
  glutKeyboardFunc(keyboard)
274
276
  glutMainLoop()
275
-