opengl 0.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +29 -0
  5. data/.gemtest +0 -0
  6. data/.gitignore +6 -0
  7. data/.travis.yml +19 -0
  8. data/History.rdoc +77 -0
  9. data/MIT-LICENSE +18 -0
  10. data/Manifest.txt +138 -0
  11. data/README.rdoc +102 -0
  12. data/Rakefile +60 -0
  13. data/examples/NeHe/NeHe.png +0 -0
  14. data/examples/NeHe/crate.png +0 -0
  15. data/examples/NeHe/glass.png +0 -0
  16. data/examples/NeHe/nehe_lesson02.rb +117 -0
  17. data/examples/NeHe/nehe_lesson03.rb +123 -0
  18. data/examples/NeHe/nehe_lesson04.rb +132 -0
  19. data/examples/NeHe/nehe_lesson05.rb +182 -0
  20. data/examples/NeHe/nehe_lesson06.rb +186 -0
  21. data/examples/NeHe/nehe_lesson07.rb +240 -0
  22. data/examples/NeHe/nehe_lesson08.rb +255 -0
  23. data/examples/NeHe/nehe_lesson09.rb +203 -0
  24. data/examples/NeHe/nehe_lesson11.rb +176 -0
  25. data/examples/NeHe/nehe_lesson12.rb +203 -0
  26. data/examples/NeHe/nehe_lesson16.rb +211 -0
  27. data/examples/NeHe/nehe_lesson19.rb +209 -0
  28. data/examples/NeHe/nehe_lesson36.rb +308 -0
  29. data/examples/NeHe/particle.png +0 -0
  30. data/examples/NeHe/star.png +0 -0
  31. data/examples/NeHe/tim.png +0 -0
  32. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  33. data/examples/OrangeBook/brick.frag +36 -0
  34. data/examples/OrangeBook/brick.rb +378 -0
  35. data/examples/OrangeBook/brick.vert +41 -0
  36. data/examples/OrangeBook/particle.frag +17 -0
  37. data/examples/OrangeBook/particle.rb +408 -0
  38. data/examples/OrangeBook/particle.vert +38 -0
  39. data/examples/README +16 -0
  40. data/examples/RedBook/aapoly.rb +143 -0
  41. data/examples/RedBook/aargb.rb +121 -0
  42. data/examples/RedBook/accanti.rb +164 -0
  43. data/examples/RedBook/accpersp.rb +217 -0
  44. data/examples/RedBook/alpha.rb +125 -0
  45. data/examples/RedBook/alpha3D.rb +160 -0
  46. data/examples/RedBook/bezcurve.rb +107 -0
  47. data/examples/RedBook/bezmesh.rb +139 -0
  48. data/examples/RedBook/checker.rb +126 -0
  49. data/examples/RedBook/clip.rb +97 -0
  50. data/examples/RedBook/colormat.rb +137 -0
  51. data/examples/RedBook/cube.rb +71 -0
  52. data/examples/RedBook/depthcue.rb +101 -0
  53. data/examples/RedBook/dof.rb +206 -0
  54. data/examples/RedBook/double.rb +107 -0
  55. data/examples/RedBook/drawf.rb +93 -0
  56. data/examples/RedBook/feedback.rb +147 -0
  57. data/examples/RedBook/fog.rb +168 -0
  58. data/examples/RedBook/font.rb +153 -0
  59. data/examples/RedBook/hello.rb +81 -0
  60. data/examples/RedBook/image.rb +139 -0
  61. data/examples/RedBook/jitter.rb +207 -0
  62. data/examples/RedBook/light.rb +155 -0
  63. data/examples/RedBook/lines.rb +130 -0
  64. data/examples/RedBook/list.rb +113 -0
  65. data/examples/RedBook/material.rb +276 -0
  66. data/examples/RedBook/mipmap.rb +158 -0
  67. data/examples/RedBook/model.rb +115 -0
  68. data/examples/RedBook/movelight.rb +134 -0
  69. data/examples/RedBook/pickdepth.rb +181 -0
  70. data/examples/RedBook/planet.rb +110 -0
  71. data/examples/RedBook/quadric.rb +160 -0
  72. data/examples/RedBook/robot.rb +117 -0
  73. data/examples/RedBook/select.rb +198 -0
  74. data/examples/RedBook/smooth.rb +97 -0
  75. data/examples/RedBook/stencil.rb +165 -0
  76. data/examples/RedBook/stroke.rb +169 -0
  77. data/examples/RedBook/surface.rb +168 -0
  78. data/examples/RedBook/teaambient.rb +134 -0
  79. data/examples/RedBook/teapots.rb +184 -0
  80. data/examples/RedBook/tess.rb +185 -0
  81. data/examples/RedBook/texbind.rb +149 -0
  82. data/examples/RedBook/texgen.rb +171 -0
  83. data/examples/RedBook/texturesurf.rb +130 -0
  84. data/examples/RedBook/varray.rb +161 -0
  85. data/examples/RedBook/wrap.rb +150 -0
  86. data/examples/misc/OGLBench.rb +338 -0
  87. data/examples/misc/anisotropic.rb +196 -0
  88. data/examples/misc/fbo_test.rb +357 -0
  89. data/examples/misc/font-glut.rb +47 -0
  90. data/examples/misc/glfwtest.rb +30 -0
  91. data/examples/misc/plane.rb +161 -0
  92. data/examples/misc/readpixel.rb +66 -0
  93. data/examples/misc/sdltest.rb +36 -0
  94. data/examples/misc/trislam.rb +829 -0
  95. data/ext/opengl/common.h +428 -0
  96. data/ext/opengl/conv.h +244 -0
  97. data/ext/opengl/extconf.rb +47 -0
  98. data/ext/opengl/funcdef.h +313 -0
  99. data/ext/opengl/gl-1.0-1.1.c +3075 -0
  100. data/ext/opengl/gl-1.2.c +155 -0
  101. data/ext/opengl/gl-1.3.c +443 -0
  102. data/ext/opengl/gl-1.4.c +348 -0
  103. data/ext/opengl/gl-1.5.c +224 -0
  104. data/ext/opengl/gl-2.0.c +667 -0
  105. data/ext/opengl/gl-2.1.c +57 -0
  106. data/ext/opengl/gl-3.0.c +493 -0
  107. data/ext/opengl/gl-enums.c +4873 -0
  108. data/ext/opengl/gl-enums.h +14588 -0
  109. data/ext/opengl/gl-error.c +112 -0
  110. data/ext/opengl/gl-error.h +28 -0
  111. data/ext/opengl/gl-ext-3dfx.c +27 -0
  112. data/ext/opengl/gl-ext-arb.c +875 -0
  113. data/ext/opengl/gl-ext-ati.c +41 -0
  114. data/ext/opengl/gl-ext-ext.c +889 -0
  115. data/ext/opengl/gl-ext-gremedy.c +41 -0
  116. data/ext/opengl/gl-ext-nv.c +680 -0
  117. data/ext/opengl/gl-types.h +67 -0
  118. data/ext/opengl/gl.c +220 -0
  119. data/ext/opengl/gl_buffer.c +177 -0
  120. data/ext/opengl/opengl.c +7 -0
  121. data/lib/gl.rb +1 -0
  122. data/lib/opengl.rb +53 -0
  123. data/lib/opengl/2.0/opengl.so +0 -0
  124. data/lib/opengl/2.1/opengl.so +0 -0
  125. data/lib/opengl/test_case.rb +86 -0
  126. data/test/dummy.xorg.conf +140 -0
  127. data/test/test_gl.rb +38 -0
  128. data/test/test_gl_10_11.rb +1363 -0
  129. data/test/test_gl_12.rb +71 -0
  130. data/test/test_gl_13.rb +221 -0
  131. data/test/test_gl_14.rb +218 -0
  132. data/test/test_gl_15.rb +258 -0
  133. data/test/test_gl_20.rb +417 -0
  134. data/test/test_gl_21.rb +436 -0
  135. data/test/test_gl_ext_arb.rb +508 -0
  136. data/test/test_gl_ext_ati.rb +28 -0
  137. data/test/test_gl_ext_ext.rb +608 -0
  138. data/test/test_gl_ext_gremedy.rb +29 -0
  139. data/test/test_gl_ext_nv.rb +349 -0
  140. data/test/test_opengl_buffer.rb +120 -0
  141. data/utils/README +6 -0
  142. data/utils/enumgen.rb +108 -0
  143. data/utils/extlistgen.rb +90 -0
  144. metadata +319 -0
  145. metadata.gz.sig +1 -0
@@ -0,0 +1,155 @@
1
+ # This example comes from the Red Book chapter 5, example 5-1 light.c
2
+
3
+ require 'opengl'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'mathn'
7
+
8
+ def init
9
+ @fullscreen = false
10
+ @xrot = 0
11
+ @yrot = 0
12
+ @zrot = 0
13
+
14
+ glClearColor 0, 0, 0, 0
15
+ glShadeModel GL_SMOOTH
16
+
17
+ glMaterialfv GL_FRONT, GL_DIFFUSE, [1, 0, 0, 1]
18
+ glMaterialfv GL_FRONT, GL_SPECULAR, [0, 1, 0, 1]
19
+ glMaterialfv GL_FRONT, GL_AMBIENT, [0, 0, 0.75, 1]
20
+ glMaterialfv GL_FRONT, GL_SHININESS, [40]
21
+ glLightfv GL_LIGHT0, GL_POSITION, [0, 1, -0.25]
22
+
23
+ glEnable GL_LIGHTING
24
+ glEnable GL_LIGHT0
25
+ glEnable GL_DEPTH_TEST
26
+ glEnable GL_NORMALIZE
27
+ end
28
+
29
+ def cross_product a, b
30
+ Vector[a[1] * b[2] - a[2] * b[1],
31
+ a[2] * b[0] - a[0] * b[2],
32
+ a[0] * b[1] - a[1] * b[0]]
33
+ end
34
+
35
+ def normal v1, v2, v3
36
+ cross_product v1 - v2, v2 - v3
37
+ end
38
+
39
+ def normals_for_triangle_fan vertexes
40
+ center = vertexes.first
41
+
42
+ vertex_normals = vertexes[1..-1].each_cons(2).map do |a, b|
43
+ normal center, a, b
44
+ end
45
+
46
+ normals = vertex_normals.each_cons(2).map do |a, b|
47
+ a + b
48
+ end
49
+
50
+ normals.unshift vertex_normals.first(3).inject :+
51
+ normals.push vertex_normals.first + vertex_normals.last
52
+ normals.push normals[1]
53
+
54
+ normals
55
+ end
56
+
57
+ def display
58
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
59
+ glLoadIdentity
60
+ #glutSolidSphere 1.0, 50, 50
61
+ glRotate @xrot, 1, 0, 0
62
+ glRotate @yrot, 0, 1, 0
63
+ glRotate @zrot, 0, 0, 1
64
+
65
+ #glBegin GL_POLYGON do
66
+ # glVertex2f -1, 1
67
+ # glVertex2f 1, 1
68
+ # glVertex2f 1, -1
69
+ # glVertex2f -1, -1
70
+ #end
71
+
72
+ glMaterialfv GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 1, 1, 1]
73
+ glMaterialfv GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 1]
74
+ glMaterialfv GL_FRONT_AND_BACK, GL_AMBIENT, [1, 1, 1, 1]
75
+ glMaterialfv GL_FRONT, GL_SHININESS, [40]
76
+ glBegin GL_LINES do
77
+ glVertex3f 0, 0, 0
78
+ glVertex3f 0, 0, 1
79
+ end
80
+
81
+ glMaterialfv GL_FRONT, GL_DIFFUSE, [1, 0, 0, 1]
82
+ glMaterialfv GL_FRONT, GL_SPECULAR, [0, 1, 0, 1]
83
+ glMaterialfv GL_FRONT, GL_AMBIENT, [0, 0, 0.75, 1]
84
+ glMaterialfv GL_FRONT, GL_SHININESS, [40]
85
+
86
+ vertices = [
87
+ Vector[ 0.00, -0.4, 0.1],
88
+ Vector[ 0.00, 0.5, 0.0],
89
+ Vector[ 0.24, -0.5, 0.0],
90
+ Vector[-0.24, -0.5, 0.0],
91
+ Vector[ 0.00, 0.5, 0.0],
92
+ ]
93
+
94
+ normals = normals_for_triangle_fan vertices
95
+
96
+ glBegin GL_TRIANGLE_FAN do
97
+ normals.zip(vertices).each do |normal, vertex|
98
+ glNormal3fv normal
99
+ glVertex3fv vertex
100
+ end
101
+ end
102
+ glFlush
103
+ end
104
+
105
+ def reshape w, h
106
+ glViewport 0, 0, w, h
107
+ glMatrixMode GL_PROJECTION
108
+ glLoadIdentity
109
+
110
+ if w <= h then
111
+ glOrtho -1.5, 1.5, -1.5 * h / w, 1.5 * h / w, -10.0, 10.0
112
+ else
113
+ glOrtho -1.5 * w / h, 1.5 * w / h, -1.5, 1.5, -10.0, 10.0
114
+ end
115
+
116
+ glMatrixMode GL_MODELVIEW
117
+ glLoadIdentity
118
+ end
119
+
120
+ def keyboard key, x, y
121
+ case key
122
+ when ?\e
123
+ glutDestroyWindow $window
124
+ exit 0
125
+ when 'X' then @xrot += 1
126
+ when 'x' then @xrot -= 1
127
+ when 'Y' then @yrot += 1
128
+ when 'y' then @yrot -= 1
129
+ when 'Z' then @zrot += 1
130
+ when 'z' then @zrot -= 1
131
+ when 'F' then
132
+ @fullscreen = !@fullscreen
133
+
134
+ if @fullscreen then
135
+ glutFullScreen
136
+ else
137
+ glutPositionWindow 0, 0
138
+ end
139
+ end
140
+
141
+ p key => [@xrot, @yrot, @zrot]
142
+
143
+ glutPostRedisplay
144
+ end
145
+
146
+ glutInit
147
+ glutInitDisplayMode GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH
148
+ glutInitWindowSize 500, 500
149
+ glutInitWindowPosition 100, 100
150
+ $window = glutCreateWindow 'example 5-1: light'
151
+ init
152
+ glutDisplayFunc :display
153
+ glutReshapeFunc :reshape
154
+ glutKeyboardFunc :keyboard
155
+ glutMainLoop
@@ -0,0 +1,130 @@
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
+ # lines.c
38
+ # This program demonstrates geometric primitives and
39
+ # their attributes.
40
+ require 'opengl'
41
+ require 'glu'
42
+ require 'glut'
43
+ require 'mathn'
44
+ include Gl,Glu,Glut
45
+
46
+ def drawOneLine(x1,y1,x2,y2)
47
+ glBegin(GL_LINES)
48
+ glVertex((x1),(y1))
49
+ glVertex((x2),(y2))
50
+ glEnd()
51
+ end
52
+
53
+ def init
54
+ glClearColor(0.0, 0.0, 0.0, 0.0)
55
+ glShadeModel(GL_FLAT)
56
+ end
57
+
58
+ display = Proc.new do
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()
105
+ end
106
+
107
+ reshape = Proc.new do |w, h|
108
+ glViewport(0, 0, w, h)
109
+ glMatrixMode(GL_PROJECTION)
110
+ glLoadIdentity()
111
+ GLU.Ortho2D(0.0, w, 0.0, h)
112
+ end
113
+
114
+ keyboard = Proc.new do |key, x, y|
115
+ case (key)
116
+ when ?\e
117
+ exit(0)
118
+ end
119
+ end
120
+
121
+ glutInit
122
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
123
+ glutInitWindowSize(400, 150)
124
+ glutInitWindowPosition(100, 100)
125
+ glutCreateWindow($0)
126
+ init()
127
+ glutDisplayFunc(display)
128
+ glutReshapeFunc(reshape)
129
+ glutKeyboardFunc(keyboard)
130
+ glutMainLoop()
@@ -0,0 +1,113 @@
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
+ # list.c
38
+ # This program demonstrates how to make and execute a
39
+ # display list. Note that attributes, such as current
40
+ # color and matrix, are changed.
41
+ require 'opengl'
42
+ require 'glu'
43
+ require 'glut'
44
+ require 'mathn'
45
+ include Gl,Glu,Glut
46
+
47
+ $listName = 0
48
+
49
+ def init
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)
61
+ end
62
+
63
+ def drawLine
64
+ glBegin(GL_LINES)
65
+ glVertex(0.0, 0.5)
66
+ glVertex(15.0, 0.5)
67
+ glEnd()
68
+ end
69
+
70
+ display = Proc.new do
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()
79
+ end
80
+
81
+ reshape = Proc.new do |w, h|
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()
92
+ end
93
+
94
+ keyboard = Proc.new do |key, x, y|
95
+ case (key)
96
+ when ?\e
97
+ exit(0)
98
+ end
99
+ end
100
+
101
+ # Main Loop
102
+ # Open window with initial window size, title bar,
103
+ # RGBA display mode, and handle input events.
104
+ glutInit
105
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
106
+ glutInitWindowSize(650, 100)
107
+ glutInitWindowPosition(100, 100)
108
+ glutCreateWindow($0)
109
+ init()
110
+ glutReshapeFunc(reshape)
111
+ glutDisplayFunc(display)
112
+ glutKeyboardFunc(keyboard)
113
+ glutMainLoop()
@@ -0,0 +1,276 @@
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
+ # material.c
40
+ # This program demonstrates the use of the GL lighting model.
41
+ # Several objects are drawn using different material characteristics.
42
+ # A single light source illuminates the objects.
43
+ require 'opengl'
44
+ require 'glu'
45
+ require 'glut'
46
+ include Gl,Glu,Glut
47
+
48
+ # Initialize z-buffer, projection matrix, light source,
49
+ # and lighting model. Do not specify a material property here.
50
+ def myinit
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)
70
+ end
71
+
72
+ # Draw twelve spheres in 3 rows with 4 columns.
73
+ # The spheres in the first row have materials with no ambient reflection.
74
+ # The second row has materials with significant ambient reflection.
75
+ # The third row has materials with colored ambient reflection.
76
+ #
77
+ # The first column has materials with blue, diffuse reflection only.
78
+ # The second column has blue diffuse reflection, as well as specular
79
+ # reflection with a low shininess exponent.
80
+ # The third column has blue diffuse reflection, as well as specular
81
+ # reflection with a high shininess exponent (a more concentrated highlight).
82
+ # The fourth column has materials which also include an emissive component.
83
+ #
84
+ # glTranslatef() is used to move spheres to their appropriate locations.
85
+ display = proc do
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()
243
+ end
244
+
245
+ myReshape = proc do |w, h|
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)
255
+ end
256
+
257
+ keyboard = Proc.new do |key, x, y|
258
+ case (key)
259
+ when ?\e
260
+ exit(0);
261
+ end
262
+ end
263
+
264
+ # Main Loop
265
+ # Open window with initial window size, title bar,
266
+ # RGBA display mode, and handle input events.
267
+ glutInit()
268
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
269
+ glutInitWindowSize(600, 600)
270
+ glutInitWindowPosition(100, 100)
271
+ glutCreateWindow()
272
+ myinit()
273
+ glutReshapeFunc(myReshape)
274
+ glutDisplayFunc(display)
275
+ glutKeyboardFunc(keyboard)
276
+ glutMainLoop()