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,158 @@
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
+ # mipmap.c
40
+ # This program demonstrates using mipmaps for texture maps.
41
+ # To overtly show the effect of mipmaps, each mipmap reduction
42
+ # level has a solidly colored, contrasting texture image.
43
+ # Thus, the quadrilateral which is drawn is drawn with several
44
+ # different colors.
45
+ require 'opengl'
46
+ require 'glu'
47
+ require 'glut'
48
+ require 'mathn'
49
+ include Gl,Glu,Glut
50
+
51
+ $mipmapImage32 = []
52
+ $mipmapImage16 = []
53
+ $mipmapImage8 = []
54
+ $mipmapImage4 = []
55
+ $mipmapImage2 = []
56
+ $mipmapImage1 = []
57
+
58
+ def makeImages
59
+ for i in 0..31
60
+ for j in 0..31
61
+ $mipmapImage32[(j*32+i)*3+0] = 255
62
+ $mipmapImage32[(j*32+i)*3+1] = 255
63
+ $mipmapImage32[(j*32+i)*3+2] = 0
64
+ end
65
+ end
66
+ for i in 0..15
67
+ for j in 0..15
68
+ $mipmapImage16[(j*16+i)*3+0] = 255
69
+ $mipmapImage16[(j*16+i)*3+1] = 0
70
+ $mipmapImage16[(j*16+i)*3+2] = 255
71
+ end
72
+ end
73
+ for i in 0..7
74
+ for j in 0..7
75
+ $mipmapImage8[(j*8+i)*3+0] = 255
76
+ $mipmapImage8[(j*8+i)*3+1] = 0
77
+ $mipmapImage8[(j*8+i)*3+2] = 0
78
+ end
79
+ end
80
+ for i in 0..3
81
+ for j in 0..3
82
+ $mipmapImage4[(j*4+i)*3+0] = 0
83
+ $mipmapImage4[(j*4+i)*3+1] = 255
84
+ $mipmapImage4[(j*4+i)*3+2] = 0
85
+ end
86
+ end
87
+ for i in 0..1
88
+ for j in 0..1
89
+ $mipmapImage2[(j*2+i)*3+0] = 0
90
+ $mipmapImage2[(j*2+i)*3+1] = 0
91
+ $mipmapImage2[(j*2+i)*3+2] = 255
92
+ end
93
+ end
94
+ $mipmapImage1[0] = 255
95
+ $mipmapImage1[1] = 255
96
+ $mipmapImage1[2] = 255
97
+ end
98
+
99
+ def myinit
100
+ glEnable(GL_DEPTH_TEST)
101
+ glDepthFunc(GL_LESS)
102
+ glShadeModel(GL_FLAT)
103
+
104
+ glTranslate(0.0, 0.0, -3.6)
105
+ makeImages()
106
+ glPixelStore(GL_UNPACK_ALIGNMENT, 1)
107
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage32.pack("C*"))
108
+ glTexImage2D(GL_TEXTURE_2D, 1, 3, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage16.pack("C*"))
109
+ glTexImage2D(GL_TEXTURE_2D, 2, 3, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage8.pack("C*"))
110
+ glTexImage2D(GL_TEXTURE_2D, 3, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage4.pack("C*"))
111
+ glTexImage2D(GL_TEXTURE_2D, 4, 3, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage2.pack("C*"))
112
+ glTexImage2D(GL_TEXTURE_2D, 5, 3, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage1.pack("C*"))
113
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
114
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
115
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
116
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
117
+ GL_NEAREST_MIPMAP_NEAREST)
118
+ glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
119
+ glEnable(GL_TEXTURE_2D)
120
+ end
121
+
122
+ display = Proc.new do
123
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
124
+ glBegin(GL_QUADS)
125
+ glTexCoord(0.0, 0.0); glVertex(-2.0, -1.0, 0.0)
126
+ glTexCoord(0.0, 8.0); glVertex(-2.0, 1.0, 0.0)
127
+ glTexCoord(8.0, 8.0); glVertex(2000.0, 1.0, -6000.0)
128
+ glTexCoord(8.0, 0.0); glVertex(2000.0, -1.0, -6000.0)
129
+ glEnd()
130
+ glutSwapBuffers()
131
+ end
132
+
133
+ myReshape = Proc.new do |w, h|
134
+ glViewport(0, 0, w, h)
135
+ glMatrixMode(GL_PROJECTION)
136
+ glLoadIdentity()
137
+ gluPerspective(60.0, 1.0*w/h, 1.0, 30000.0)
138
+ glMatrixMode(GL_MODELVIEW)
139
+ glLoadIdentity()
140
+ end
141
+
142
+ keyboard = Proc.new do |key, x, y|
143
+ case (key)
144
+ when ?\e
145
+ exit(0);
146
+ end
147
+ end
148
+
149
+ glutInit
150
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
151
+ glutInitWindowSize(500, 500)
152
+ glutInitWindowPosition(100, 100)
153
+ glutCreateWindow($0)
154
+ myinit()
155
+ glutReshapeFunc(myReshape)
156
+ glutDisplayFunc(display)
157
+ glutKeyboardFunc(keyboard)
158
+ glutMainLoop()
@@ -0,0 +1,115 @@
1
+ #
2
+ # Copyright (c) 1993-1997, Silicon Graphics, Inc.
3
+ # ALL RIGHTS RESERVED
4
+ # Permission to use, copy, modify, and distribute this software for
5
+ # any purpose and without fee is hereby granted, provided that the above
6
+ # copyright notice appear in all copies and that both the copyright notice
7
+ # and this permission notice appear in supporting documentation, and that
8
+ # the name of Silicon Graphics, Inc. not be used in advertising
9
+ # or publicity pertaining to distribution of the software without specific,
10
+ # written prior permission.
11
+ #
12
+ # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14
+ # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15
+ # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16
+ # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17
+ # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18
+ # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19
+ # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20
+ # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21
+ # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22
+ # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23
+ # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
24
+ #
25
+ # US Government Users Restricted Rights
26
+ # Use, duplication, or disclosure by the Government is subject to
27
+ # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28
+ # (c)(1)(ii) of the Rights in Technical Data and Computer Software
29
+ # clause at DFARS 252.227-7013 and/or in similar or successor
30
+ # clauses in the FAR or the DOD or NASA FAR Supplement.
31
+ # Unpublished-- rights reserved under the copyright laws of the
32
+ # United States. Contractor/manufacturer is Silicon Graphics,
33
+ # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
34
+ #
35
+ # OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
36
+ #
37
+ # model.c
38
+ # This program demonstrates modeling transformations
39
+ require 'opengl'
40
+ require 'glu'
41
+ require 'glut'
42
+ require 'mathn'
43
+ include Gl,Glu,Glut
44
+
45
+ def init
46
+ glClearColor(0.0, 0.0, 0.0, 0.0)
47
+ glShadeModel(GL_FLAT)
48
+ end
49
+
50
+ def draw_triangle
51
+ glBegin(GL_LINE_LOOP)
52
+ glVertex(0.0, 25.0)
53
+ glVertex(25.0, -25.0)
54
+ glVertex(-25.0, -25.0)
55
+ glEnd()
56
+ end
57
+
58
+ display = Proc.new do
59
+ glClear(GL_COLOR_BUFFER_BIT)
60
+ glColor(1.0, 1.0, 1.0)
61
+
62
+ glLoadIdentity()
63
+ glColor(1.0, 1.0, 1.0)
64
+ draw_triangle()
65
+
66
+ glEnable(GL_LINE_STIPPLE)
67
+ glLineStipple(1, 0xF0F0)
68
+ glLoadIdentity()
69
+ glTranslate(-20.0, 0.0, 0.0)
70
+ draw_triangle()
71
+
72
+ glLineStipple(1, 0xF00F)
73
+ glLoadIdentity()
74
+ glScale(1.5, 0.5, 1.0)
75
+ draw_triangle()
76
+
77
+ glLineStipple(1, 0x8888)
78
+ glLoadIdentity()
79
+ glRotate(90.0, 0.0, 0.0, 1.0)
80
+ draw_triangle()
81
+ glDisable(GL_LINE_STIPPLE)
82
+
83
+ glutSwapBuffers()
84
+ end
85
+
86
+ reshape = Proc.new do |w, h|
87
+ glViewport(0, 0, w, h)
88
+ glMatrixMode(GL_PROJECTION)
89
+ glLoadIdentity()
90
+ if (w <= h)
91
+ glOrtho(-50.0, 50.0, -50.0*h/w, 50.0*h/w, -1.0, 1.0)
92
+ else
93
+ glOrtho(-50.0*w/h,50.0*w/h, -50.0, 50.0, -1.0, 1.0)
94
+ end
95
+ glMatrixMode(GL_MODELVIEW)
96
+ end
97
+
98
+ keyboard = Proc.new do |key, x, y|
99
+ case key
100
+ when ?\e
101
+ exit(0)
102
+ end
103
+ end
104
+
105
+ # main
106
+ glutInit()
107
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
108
+ glutInitWindowSize(500, 500)
109
+ glutInitWindowPosition(100, 100)
110
+ glutCreateWindow($0)
111
+ init()
112
+ glutDisplayFunc(display)
113
+ glutReshapeFunc(reshape)
114
+ glutKeyboardFunc(keyboard)
115
+ glutMainLoop()
@@ -0,0 +1,134 @@
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
+ # movelight.c
38
+ # This program demonstrates when to issue lighting and
39
+ # transformation commands to render a model with a light
40
+ # which is moved by a modeling transformation (rotate or
41
+ # translate). The light position is reset after the modeling
42
+ # transformation is called. The eye position does not change.
43
+ #
44
+ # A sphere is drawn using a grey material characteristic.
45
+ # A single light source illuminates the object.
46
+ #
47
+ # Interaction: pressing the left mouse button alters
48
+ # the modeling transformation (x rotation) by 30 degrees.
49
+ # The scene is then redrawn with the light in a new position.
50
+
51
+ require 'opengl'
52
+ require 'glu'
53
+ require 'glut'
54
+ require 'rational'
55
+ require 'mathn'
56
+ include Gl,Glu,Glut
57
+
58
+ $spin = 0
59
+
60
+ # Initialize material property, light source, lighting model,
61
+ # and depth buffer.
62
+ def init
63
+ glClearColor(0.0, 0.0, 0.0, 0.0)
64
+ glShadeModel(GL_SMOOTH)
65
+ glEnable(GL_LIGHTING)
66
+ glEnable(GL_LIGHT0)
67
+ glEnable(GL_DEPTH_TEST)
68
+ end
69
+
70
+ # Here is where the light position is reset after the modeling
71
+ # transformation (glRotated) is called. This places the
72
+ # light at a new position in world coordinates. The cube
73
+ # represents the position of the light.
74
+ display = Proc.new do
75
+ position = [ 0.0, 0.0, 1.5, 1.0 ]
76
+
77
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
78
+ glPushMatrix()
79
+ GLU.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
80
+
81
+ glPushMatrix()
82
+ glRotate($spin, 1.0, 0.0, 0.0)
83
+ glLight(GL_LIGHT0, GL_POSITION, position)
84
+
85
+ glTranslate(0.0, 0.0, 1.5)
86
+ glDisable(GL_LIGHTING)
87
+ glColor(0.0, 1.0, 1.0)
88
+ glutWireCube(0.1)
89
+ glEnable(GL_LIGHTING)
90
+ glPopMatrix()
91
+
92
+ glutSolidTorus(0.275, 0.85, 8, 15)
93
+ glPopMatrix()
94
+ glutSwapBuffers()
95
+ end
96
+
97
+ reshape = Proc.new do |w, h|
98
+ glViewport(0, 0, w, h)
99
+ glMatrixMode(GL_PROJECTION)
100
+ glLoadIdentity()
101
+ gluPerspective(40.0, w/h, 1.0, 20.0)
102
+ glMatrixMode(GL_MODELVIEW)
103
+ glLoadIdentity()
104
+ end
105
+
106
+ mouse = Proc.new do |button, state, x, y|
107
+ case button
108
+ when GLUT_LEFT_BUTTON
109
+ if (state == GLUT_DOWN)
110
+ $spin = ($spin + 30) % 360
111
+ glutPostRedisplay()
112
+ end
113
+ end
114
+ end
115
+
116
+ keyboard = Proc.new do |key, x, y|
117
+ case key
118
+ when ?\e
119
+ exit(0)
120
+ end
121
+ end
122
+
123
+ # main
124
+ glutInit
125
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
126
+ glutInitWindowSize(500, 500)
127
+ glutInitWindowPosition(100, 100)
128
+ glutCreateWindow($0)
129
+ init()
130
+ glutDisplayFunc(display)
131
+ glutReshapeFunc(reshape)
132
+ glutMouseFunc(mouse)
133
+ glutKeyboardFunc(keyboard)
134
+ glutMainLoop()
@@ -0,0 +1,181 @@
1
+ #
2
+ # Copyright (c) Mark J. Kilgard, 1994. */
3
+ #
4
+ #
5
+ # (c) Copyright 1993, Silicon Graphics, Inc.
6
+ # ALL RIGHTS RESERVED
7
+ # Permission to use, copy, modify, and distribute this software for
8
+ # any purpose and without fee is hereby granted, provided that the above
9
+ # copyright notice appear in all copies and that both the copyright notice
10
+ # and this permission notice appear in supporting documentation, and that
11
+ # the name of Silicon Graphics, Inc. not be used in advertising
12
+ # or publicity pertaining to distribution of the software without specific,
13
+ # written prior permission.
14
+ #
15
+ # THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
+ # AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
+ # INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
+ # FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
+ # GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
+ # SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
+ # KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
+ # LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
+ # THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
+ # ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
+ # ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
+ # POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ #
28
+ # US Government Users Restricted Rights
29
+ # Use, duplication, or disclosure by the Government is subject to
30
+ # restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
+ # (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
+ # clause at DFARS 252.227-7013 and/or in similar or successor
33
+ # clauses in the FAR or the DOD or NASA FAR Supplement.
34
+ # Unpublished-- rights reserved under the copyright laws of the
35
+ # United States. Contractor/manufacturer is Silicon Graphics,
36
+ # Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
37
+ #
38
+ # OpenGL(TM) is a trademark of Silicon Graphics, Inc.
39
+ #
40
+ # pickdepth.c
41
+ # Picking is demonstrated in this program. In
42
+ # rendering mode, three overlapping rectangles are
43
+ # drawn. When the left mouse button is pressed,
44
+ # selection mode is entered with the picking matrix.
45
+ # Rectangles which are drawn under the cursor position
46
+ # are "picked." Pay special attention to the depth
47
+ # value range, which is returned.
48
+ require 'opengl'
49
+ require 'glu'
50
+ require 'glut'
51
+ include Gl,Glu,Glut
52
+
53
+ def myinit
54
+ glClearColor(0.0, 0.0, 0.0, 0.0)
55
+ glDepthFunc(GL_LESS)
56
+ glEnable(GL_DEPTH_TEST)
57
+ glShadeModel(GL_FLAT)
58
+ glDepthRange(0.0, 1.0) #/* The default z mapping */
59
+ end
60
+
61
+ # The three rectangles are drawn. In selection mode,
62
+ # each rectangle is given the same name. Note that
63
+ # each rectangle is drawn with a different z value.
64
+ def drawRects(mode)
65
+ if (mode == GL_SELECT)
66
+ glLoadName(1)
67
+ end
68
+ glBegin(GL_QUADS)
69
+ glColor(1.0, 1.0, 0.0)
70
+ glVertex(2, 0, 0)
71
+ glVertex(2, 6, 0)
72
+ glVertex(6, 6, 0)
73
+ glVertex(6, 0, 0)
74
+ glEnd()
75
+ if (mode == GL_SELECT)
76
+ glLoadName(2)
77
+ end
78
+ glBegin(GL_QUADS)
79
+ glColor(0.0, 1.0, 1.0)
80
+ glVertex(3, 2, -1)
81
+ glVertex(3, 8, -1)
82
+ glVertex(8, 8, -1)
83
+ glVertex(8, 2, -1)
84
+ glEnd()
85
+ if (mode == GL_SELECT)
86
+ glLoadName(3)
87
+ end
88
+ glBegin(GL_QUADS)
89
+ glColor(1.0, 0.0, 1.0)
90
+ glVertex(0, 2, -2)
91
+ glVertex(0, 7, -2)
92
+ glVertex(5, 7, -2)
93
+ glVertex(5, 2, -2)
94
+ glEnd()
95
+ end
96
+
97
+ # processHits() prints out the contents of the
98
+ # selection array.
99
+ def processHits(hits, buffer)
100
+ printf("hits = %d\n", hits)
101
+ ptr = buffer.unpack("I*")
102
+ p = 0
103
+ for i in 0...hits # for each hit
104
+ names = ptr[p]
105
+ printf(" number of names for hit = %d\n", names); p+=1
106
+ printf(" z1 is %g", ptr[p].to_f/0xffffffff); p+=1
107
+ printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1
108
+ printf(" the name is ")
109
+ for j in 0...names # for each name
110
+ printf("%d ", ptr[p]) ; p+=1
111
+ end
112
+ printf("\n")
113
+ end
114
+ end
115
+
116
+ # pickRects() sets up selection mode, name stack,
117
+ # and projection matrix for picking. Then the objects
118
+ # are drawn.
119
+ BUFSIZE=512
120
+
121
+ pickRects = proc do |button, state, x, y|
122
+ if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
123
+ viewport = glGetDoublev(GL_VIEWPORT)
124
+
125
+ selectBuf = glSelectBuffer(BUFSIZE)
126
+ glRenderMode(GL_SELECT)
127
+
128
+ glInitNames()
129
+ glPushName(~0)
130
+
131
+ glMatrixMode(GL_PROJECTION)
132
+ glPushMatrix()
133
+ glLoadIdentity()
134
+ # create 5x5 pixel picking region near cursor location
135
+ gluPickMatrix( x, viewport[3] - y, 5.0, 5.0, viewport)
136
+ glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
137
+ drawRects(GL_SELECT)
138
+ glPopMatrix()
139
+ glFlush()
140
+
141
+ hits = glRenderMode(GL_RENDER)
142
+ processHits(hits, selectBuf)
143
+ end
144
+ end
145
+
146
+ display = proc do
147
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
148
+ drawRects(GL_RENDER)
149
+ glutSwapBuffers()
150
+ end
151
+
152
+ myReshape = proc do |w, h|
153
+ glViewport(0, 0, w, h)
154
+ glMatrixMode(GL_PROJECTION)
155
+ glLoadIdentity()
156
+ glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
157
+ glMatrixMode(GL_MODELVIEW)
158
+ glLoadIdentity()
159
+ end
160
+
161
+ keyboard = Proc.new do |key, x, y|
162
+ case (key)
163
+ when ?\e
164
+ exit(0)
165
+ end
166
+ end
167
+
168
+ # Main Loop
169
+ # Open window with initial window size, title bar,
170
+ # RGBA display mode, depth buffer, and handle input events.
171
+ glutInitWindowSize(500, 500)
172
+ glutInitWindowPosition(100, 100)
173
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
174
+ glutInit()
175
+ glutCreateWindow()
176
+ myinit()
177
+ glutMouseFunc(pickRects)
178
+ glutReshapeFunc(myReshape)
179
+ glutDisplayFunc(display)
180
+ glutKeyboardFunc(keyboard)
181
+ glutMainLoop()