danabr75-opengl 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +29 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +6 -0
  5. data/.travis.yml +19 -0
  6. data/Gemfile +8 -0
  7. data/History.md +101 -0
  8. data/MIT-LICENSE +18 -0
  9. data/Manifest.txt +142 -0
  10. data/README.rdoc +105 -0
  11. data/Rakefile +170 -0
  12. data/danabr75-opengl.gemspec +32 -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 +157 -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/GL/gl.h +2115 -0
  96. data/ext/opengl/GL/glext.h +11770 -0
  97. data/ext/opengl/common.h +372 -0
  98. data/ext/opengl/conv.h +247 -0
  99. data/ext/opengl/extconf.rb +19 -0
  100. data/ext/opengl/fptr_struct.h +912 -0
  101. data/ext/opengl/funcdef.h +279 -0
  102. data/ext/opengl/gl-1.0-1.1.c +3345 -0
  103. data/ext/opengl/gl-1.2.c +155 -0
  104. data/ext/opengl/gl-1.3.c +447 -0
  105. data/ext/opengl/gl-1.4.c +346 -0
  106. data/ext/opengl/gl-1.5.c +225 -0
  107. data/ext/opengl/gl-2.0.c +665 -0
  108. data/ext/opengl/gl-2.1.c +57 -0
  109. data/ext/opengl/gl-3.0.c +502 -0
  110. data/ext/opengl/gl-enums.c +4853 -0
  111. data/ext/opengl/gl-enums.h +14528 -0
  112. data/ext/opengl/gl-error.c +110 -0
  113. data/ext/opengl/gl-error.h +25 -0
  114. data/ext/opengl/gl-ext-3dfx.c +27 -0
  115. data/ext/opengl/gl-ext-arb.c +880 -0
  116. data/ext/opengl/gl-ext-ati.c +41 -0
  117. data/ext/opengl/gl-ext-ext.c +885 -0
  118. data/ext/opengl/gl-ext-gremedy.c +41 -0
  119. data/ext/opengl/gl-ext-nv.c +679 -0
  120. data/ext/opengl/gl.c +265 -0
  121. data/ext/opengl/gl_buffer.c +202 -0
  122. data/ext/opengl/glimpl.c +187 -0
  123. data/ext/opengl/glimpl.h +47 -0
  124. data/ext/opengl/opengl.c +9 -0
  125. data/lib/gl.rb +1 -0
  126. data/lib/opengl.rb +79 -0
  127. data/lib/opengl/bindings_version.rb +4 -0
  128. data/lib/opengl/implementation.rb +38 -0
  129. data/lib/opengl/test_case.rb +86 -0
  130. data/test/dummy.xorg.conf +140 -0
  131. data/test/test_gl.rb +45 -0
  132. data/test/test_gl_10_11.rb +1363 -0
  133. data/test/test_gl_12.rb +71 -0
  134. data/test/test_gl_13.rb +221 -0
  135. data/test/test_gl_14.rb +218 -0
  136. data/test/test_gl_15.rb +258 -0
  137. data/test/test_gl_20.rb +417 -0
  138. data/test/test_gl_21.rb +436 -0
  139. data/test/test_gl_ext_arb.rb +508 -0
  140. data/test/test_gl_ext_ati.rb +28 -0
  141. data/test/test_gl_ext_ext.rb +608 -0
  142. data/test/test_gl_ext_gremedy.rb +29 -0
  143. data/test/test_gl_ext_nv.rb +349 -0
  144. data/test/test_glimpl.rb +23 -0
  145. data/test/test_opengl_buffer.rb +122 -0
  146. data/utils/README +6 -0
  147. data/utils/enumgen.rb +108 -0
  148. data/utils/extlistgen.rb +90 -0
  149. metadata +326 -0
@@ -0,0 +1,110 @@
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
+ # 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 'glu'
44
+ require 'glut'
45
+ require 'rational'
46
+ include Gl,Glu,Glut
47
+
48
+ STDOUT.sync = TRUE
49
+
50
+ $year = 0
51
+ $day = 0
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
+ glColor(1.0, 1.0, 1.0)
61
+
62
+ glPushMatrix()
63
+ glutWireSphere(1.0, 20, 16) # draw sun
64
+ glRotate($year, 0.0, 1.0, 0.0)
65
+ glTranslate(2.0, 0.0, 0.0)
66
+ glRotate($day, 0.0, 1.0, 0.0)
67
+ glutWireSphere(0.2, 10, 8) # draw smaller planet
68
+ glPopMatrix()
69
+ glutSwapBuffers()
70
+ end
71
+
72
+ reshape = Proc.new do |w, h|
73
+ glViewport(0, 0, w, h)
74
+ glMatrixMode(GL_PROJECTION)
75
+ glLoadIdentity()
76
+ gluPerspective(60.0, w.to_f/h.to_f, 1.0, 20.0)
77
+ glMatrixMode(GL_MODELVIEW)
78
+ glLoadIdentity()
79
+ gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
80
+ end
81
+
82
+ keyboard = Proc.new do |key, x, y|
83
+ case (key)
84
+ when ?d
85
+ $day = ($day + 10) % 360
86
+ glutPostRedisplay()
87
+ when ?D
88
+ $day = ($day - 10) % 360
89
+ glutPostRedisplay()
90
+ when ?y
91
+ $year = ($year + 5) % 360
92
+ glutPostRedisplay()
93
+ when ?Y
94
+ $year = ($year - 5) % 360
95
+ glutPostRedisplay()
96
+ when ?\e
97
+ exit(0)
98
+ end
99
+ end
100
+
101
+ glutInit
102
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
103
+ glutInitWindowSize(500, 500)
104
+ glutInitWindowPosition(100, 100)
105
+ glutCreateWindow($0)
106
+ init()
107
+ glutDisplayFunc(display)
108
+ glutReshapeFunc(reshape)
109
+ glutKeyboardFunc(keyboard)
110
+ glutMainLoop()
@@ -0,0 +1,160 @@
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 'glu'
45
+ require 'glut'
46
+ require 'mathn'
47
+ include Gl,Glu,Glut
48
+
49
+ $startList = nil
50
+
51
+ def init
52
+ mat_ambient = [ 0.5, 0.5, 0.5, 1.0 ]
53
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
54
+ mat_shininess = [ 50.0 ]
55
+ light_position = [ 1.0, 1.0, 1.0, 0.0 ]
56
+ model_ambient = [ 0.5, 0.5, 0.5, 1.0 ]
57
+
58
+ glClearColor(0.0, 0.0, 0.0, 0.0)
59
+
60
+ glMaterial(GL_FRONT, GL_AMBIENT, mat_ambient)
61
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
62
+ glMaterial(GL_FRONT, GL_SHININESS, mat_shininess)
63
+ glLight(GL_LIGHT0, GL_POSITION, light_position)
64
+ glLightModel(GL_LIGHT_MODEL_AMBIENT, model_ambient)
65
+
66
+ glEnable(GL_LIGHTING)
67
+ glEnable(GL_LIGHT0)
68
+ glEnable(GL_DEPTH_TEST)
69
+
70
+ # Create 4 display lists, each with a different quadric object.
71
+ # Different drawing styles and surface normal specifications
72
+ # are demonstrated.
73
+ $startList = glGenLists(4)
74
+ qobj = gluNewQuadric()
75
+
76
+ gluQuadricDrawStyle(qobj, GLU_FILL) # smooth shaded
77
+ gluQuadricNormals(qobj, GLU_SMOOTH)
78
+ glNewList($startList, GL_COMPILE)
79
+ gluSphere(qobj, 0.75, 15, 10)
80
+ glEndList()
81
+
82
+ gluQuadricDrawStyle(qobj, GLU_FILL) # flat shaded
83
+ gluQuadricNormals(qobj, GLU_FLAT)
84
+ glNewList($startList+1, GL_COMPILE)
85
+ gluCylinder(qobj, 0.5, 0.3, 1.0, 15, 5)
86
+ glEndList()
87
+
88
+ gluQuadricDrawStyle(qobj, GLU_LINE) # all polygons wireframe
89
+ gluQuadricNormals(qobj, GLU_NONE)
90
+ glNewList($startList+2, GL_COMPILE)
91
+ gluDisk(qobj, 0.25, 1.0, 20, 4)
92
+ glEndList()
93
+
94
+ gluQuadricDrawStyle(qobj, GLU_SILHOUETTE) # boundary only
95
+ gluQuadricNormals(qobj, GLU_NONE)
96
+ glNewList($startList+3, GL_COMPILE)
97
+ gluPartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0)
98
+ glEndList()
99
+ end
100
+
101
+ display = Proc.new do
102
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
103
+ glPushMatrix()
104
+
105
+ glEnable(GL_LIGHTING)
106
+ glShadeModel(GL_SMOOTH)
107
+ glTranslate(-1.0, -1.0, 0.0)
108
+ glCallList($startList)
109
+
110
+ glShadeModel(GL_FLAT)
111
+ glTranslate(0.0, 2.0, 0.0)
112
+ glPushMatrix()
113
+ glRotate(300.0, 1.0, 0.0, 0.0)
114
+ glCallList($startList+1)
115
+ glPopMatrix()
116
+
117
+ glDisable(GL_LIGHTING)
118
+ glColor(0.0, 1.0, 1.0)
119
+ glTranslate(2.0, -2.0, 0.0)
120
+ glCallList($startList+2)
121
+
122
+ glColor(1.0, 1.0, 0.0)
123
+ glTranslate(0.0, 2.0, 0.0)
124
+ glCallList($startList+3)
125
+
126
+ glPopMatrix()
127
+ glutSwapBuffers()
128
+ end
129
+
130
+ reshape = Proc.new do |w, h|
131
+ glViewport(0, 0, w, h)
132
+ glMatrixMode(GL_PROJECTION)
133
+ glLoadIdentity()
134
+ if (w <= h)
135
+ glOrtho(-2.5, 2.5, -2.5*h/w, 2.5*h/w, -10.0, 10.0)
136
+ else
137
+ glOrtho(-2.5*w/h, 2.5*w/h, -2.5, 2.5, -10.0, 10.0)
138
+ end
139
+ glMatrixMode(GL_MODELVIEW)
140
+ glLoadIdentity()
141
+ end
142
+
143
+ keyboard = Proc.new do |key, x, y|
144
+ case (key)
145
+ when ?\e
146
+ exit(0)
147
+ end
148
+ end
149
+
150
+ # main
151
+ glutInit
152
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
153
+ glutInitWindowSize(500, 500)
154
+ glutInitWindowPosition(100, 100)
155
+ glutCreateWindow($0)
156
+ init()
157
+ glutDisplayFunc(display)
158
+ glutReshapeFunc(reshape)
159
+ glutKeyboardFunc(keyboard)
160
+ glutMainLoop()
@@ -0,0 +1,117 @@
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 'glu'
44
+ require 'glut'
45
+ require 'mathn'
46
+ include Gl,Glu,Glut
47
+
48
+ $shoulder = 0
49
+ $elbow = 0
50
+
51
+ def init
52
+ glClearColor(0.0, 0.0, 0.0, 0.0)
53
+ glShadeModel(GL_FLAT)
54
+ end
55
+
56
+ display = Proc.new do
57
+ glClear(GL_COLOR_BUFFER_BIT)
58
+ glPushMatrix()
59
+ glTranslate(-1.0, 0.0, 0.0)
60
+ glRotate($shoulder, 0.0, 0.0, 1.0)
61
+ glTranslate(1.0, 0.0, 0.0)
62
+ glPushMatrix()
63
+ glScale(2.0, 0.4, 1.0)
64
+ glutWireCube(1.0)
65
+ glPopMatrix()
66
+
67
+ glTranslate(1.0, 0.0, 0.0)
68
+ glRotate($elbow, 0.0, 0.0, 1.0)
69
+ glTranslate(1.0, 0.0, 0.0)
70
+ glPushMatrix()
71
+ glScale(2.0, 0.4, 1.0)
72
+ glutWireCube(1.0)
73
+ glPopMatrix()
74
+
75
+ glPopMatrix()
76
+ glutSwapBuffers()
77
+ end
78
+
79
+ reshape = Proc.new do |w, h|
80
+ glViewport(0, 0, w, h)
81
+ glMatrixMode(GL_PROJECTION)
82
+ glLoadIdentity()
83
+ gluPerspective(65.0, w/ h, 1.0, 20.0)
84
+ glMatrixMode(GL_MODELVIEW)
85
+ glLoadIdentity()
86
+ glTranslate(0.0, 0.0, -5.0)
87
+ end
88
+
89
+ keyboard = Proc.new do|key, x, y|
90
+ case (key)
91
+ when ?s
92
+ $shoulder = ($shoulder + 5) % 360
93
+ glutPostRedisplay()
94
+ when ?S
95
+ $shoulder = ($shoulder - 5) % 360
96
+ glutPostRedisplay()
97
+ when ?e
98
+ $elbow = ($elbow + 5) % 360
99
+ glutPostRedisplay()
100
+ when ?E
101
+ $elbow = ($elbow - 5) % 360
102
+ glutPostRedisplay()
103
+ when ?\e
104
+ exit(0)
105
+ end
106
+ end
107
+
108
+ glutInit
109
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
110
+ glutInitWindowSize(500, 500)
111
+ glutInitWindowPosition(100, 100)
112
+ glutCreateWindow($0)
113
+ init()
114
+ glutDisplayFunc(display)
115
+ glutReshapeFunc(reshape)
116
+ glutKeyboardFunc(keyboard)
117
+ glutMainLoop()
@@ -0,0 +1,198 @@
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
+ require 'glu'
53
+ require 'glut'
54
+ include Gl,Glu,Glut
55
+
56
+ # draw a triangle with vertices at (x1, y1), (x2, y2)
57
+ # and (x3, y3) at z units away from the origin.
58
+ def drawTriangle(x1, y1, x2, y2, x3, y3, z)
59
+ glBegin(GL_TRIANGLES)
60
+ glVertex(x1, y1, z)
61
+ glVertex(x2, y2, z)
62
+ glVertex(x3, y3, z)
63
+ glEnd()
64
+ end
65
+
66
+ # draw a rectangular box with these outer x, y, and z values
67
+ def drawViewVolume(x1, x2, y1, y2, z1, z2)
68
+ glColor(1.0, 1.0, 1.0)
69
+ glBegin(GL_LINE_LOOP)
70
+ glVertex(x1, y1, -z1)
71
+ glVertex(x2, y1, -z1)
72
+ glVertex(x2, y2, -z1)
73
+ glVertex(x1, y2, -z1)
74
+ glEnd()
75
+
76
+ glBegin(GL_LINE_LOOP)
77
+ glVertex(x1, y1, -z2)
78
+ glVertex(x2, y1, -z2)
79
+ glVertex(x2, y2, -z2)
80
+ glVertex(x1, y2, -z2)
81
+ glEnd()
82
+
83
+ glBegin(GL_LINES)# 4 lines
84
+ glVertex(x1, y1, -z1)
85
+ glVertex(x1, y1, -z2)
86
+ glVertex(x1, y2, -z1)
87
+ glVertex(x1, y2, -z2)
88
+ glVertex(x2, y1, -z1)
89
+ glVertex(x2, y1, -z2)
90
+ glVertex(x2, y2, -z1)
91
+ glVertex(x2, y2, -z2)
92
+ glEnd()
93
+ end
94
+
95
+ # drawScene draws 4 triangles and a wire frame
96
+ # which represents the viewing volume.
97
+ def drawScene()
98
+ glMatrixMode(GL_PROJECTION)
99
+ glLoadIdentity()
100
+ gluPerspective(40.0, 4.0/3.0, 1.0, 100.0)
101
+
102
+ glMatrixMode(GL_MODELVIEW)
103
+ glLoadIdentity()
104
+ gluLookAt(7.5, 7.5, 12.5, 2.5, 2.5, -5.0, 0.0, 1.0, 0.0)
105
+ glColor(0.0, 1.0, 0.0)# green triangle
106
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0)
107
+ glColor(1.0, 0.0, 0.0)# red triangle
108
+ drawTriangle(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0)
109
+ glColor(1.0, 1.0, 0.0)# yellow triangles
110
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0)
111
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0)
112
+ drawViewVolume(0.0, 5.0, 0.0, 5.0, 0.0, 10.0)
113
+ end
114
+
115
+ # processHits prints out the contents of the selection array
116
+ def processHits(hits, buffer)
117
+ printf("hits = %d\n", hits)
118
+ ptr = buffer.unpack("I*")
119
+ p = 0
120
+ for i in 0...hits # for each hit
121
+ names = ptr[p]
122
+ printf(" number of names for hit = %d\n", names); p+=1
123
+ printf(" z1 is %g", ptr[p].to_f/0xffffffff); p+=1
124
+ printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1
125
+ printf(" the name is ")
126
+ for j in 0...names # for each name
127
+ printf("%d ", ptr[p]); p+=1
128
+ end
129
+ printf("\n")
130
+ end
131
+ end
132
+
133
+ # selectObjects "draws" the triangles in selection mode,
134
+ # assigning names for the triangles. Note that the third
135
+ # and fourth triangles share one name, so that if either
136
+ # or both triangles intersects the viewing/clipping volume,
137
+ # only one hit will be registered.
138
+
139
+ BUFSIZE=512
140
+
141
+ def selectObjects
142
+ selectBuf = glSelectBuffer(BUFSIZE)
143
+ glRenderMode(GL_SELECT)
144
+
145
+ glInitNames()
146
+ glPushName(0)
147
+
148
+ glPushMatrix()
149
+ glMatrixMode(GL_PROJECTION)
150
+ glLoadIdentity()
151
+ glOrtho(0.0, 5.0, 0.0, 5.0, 0.0, 10.0)
152
+ glMatrixMode(GL_MODELVIEW)
153
+ glLoadIdentity()
154
+ glLoadName(1)
155
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0)
156
+ glLoadName(2)
157
+ drawTriangle(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0)
158
+ glLoadName(3)
159
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0)
160
+ drawTriangle(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0)
161
+ glPopMatrix()
162
+ glFlush()
163
+
164
+ hits = glRenderMode(GL_RENDER)
165
+ processHits(hits, selectBuf)
166
+ end
167
+
168
+ def init
169
+ glEnable(GL_DEPTH_TEST)
170
+ glShadeModel(GL_FLAT)
171
+ end
172
+
173
+ display = proc do
174
+ glClearColor(0.0, 0.0, 0.0, 0.0)
175
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
176
+ drawScene()
177
+ selectObjects()
178
+ glFlush()
179
+ end
180
+
181
+ keyboard = proc do |key, x, y|
182
+ case (key)
183
+ when ?\e
184
+ exit(0)
185
+ end
186
+ end
187
+
188
+ # Main Loop
189
+
190
+ GLUT.Init
191
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
192
+ glutInitWindowSize(500, 500)
193
+ glutInitWindowPosition(100, 100)
194
+ glutCreateWindow $0
195
+ init()
196
+ glutDisplayFunc(display)
197
+ glutKeyboardFunc(keyboard)
198
+ glutMainLoop()