ruby-opengl2 0.60.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/Rakefile +80 -0
  2. data/examples/NeHe/nehe_lesson02.rb +117 -0
  3. data/examples/NeHe/nehe_lesson03.rb +122 -0
  4. data/examples/NeHe/nehe_lesson04.rb +133 -0
  5. data/examples/NeHe/nehe_lesson05.rb +186 -0
  6. data/examples/NeHe/nehe_lesson36.rb +303 -0
  7. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  8. data/examples/OrangeBook/brick.frag +36 -0
  9. data/examples/OrangeBook/brick.rb +376 -0
  10. data/examples/OrangeBook/brick.vert +41 -0
  11. data/examples/OrangeBook/particle.frag +17 -0
  12. data/examples/OrangeBook/particle.rb +406 -0
  13. data/examples/OrangeBook/particle.vert +38 -0
  14. data/examples/README +16 -0
  15. data/examples/RedBook/aapoly.rb +142 -0
  16. data/examples/RedBook/aargb.rb +119 -0
  17. data/examples/RedBook/accanti.rb +162 -0
  18. data/examples/RedBook/accpersp.rb +215 -0
  19. data/examples/RedBook/alpha.rb +123 -0
  20. data/examples/RedBook/alpha3D.rb +158 -0
  21. data/examples/RedBook/bezcurve.rb +105 -0
  22. data/examples/RedBook/bezmesh.rb +137 -0
  23. data/examples/RedBook/checker.rb +124 -0
  24. data/examples/RedBook/clip.rb +95 -0
  25. data/examples/RedBook/colormat.rb +135 -0
  26. data/examples/RedBook/cube.rb +69 -0
  27. data/examples/RedBook/depthcue.rb +99 -0
  28. data/examples/RedBook/dof.rb +205 -0
  29. data/examples/RedBook/double.rb +105 -0
  30. data/examples/RedBook/drawf.rb +91 -0
  31. data/examples/RedBook/feedback.rb +145 -0
  32. data/examples/RedBook/fog.rb +167 -0
  33. data/examples/RedBook/font.rb +151 -0
  34. data/examples/RedBook/hello.rb +79 -0
  35. data/examples/RedBook/image.rb +137 -0
  36. data/examples/RedBook/jitter.rb +207 -0
  37. data/examples/RedBook/lines.rb +128 -0
  38. data/examples/RedBook/list.rb +111 -0
  39. data/examples/RedBook/material.rb +275 -0
  40. data/examples/RedBook/mipmap.rb +156 -0
  41. data/examples/RedBook/model.rb +113 -0
  42. data/examples/RedBook/movelight.rb +132 -0
  43. data/examples/RedBook/pickdepth.rb +179 -0
  44. data/examples/RedBook/planet.rb +108 -0
  45. data/examples/RedBook/quadric.rb +158 -0
  46. data/examples/RedBook/robot.rb +115 -0
  47. data/examples/RedBook/select.rb +196 -0
  48. data/examples/RedBook/smooth.rb +95 -0
  49. data/examples/RedBook/stencil.rb +163 -0
  50. data/examples/RedBook/stroke.rb +167 -0
  51. data/examples/RedBook/surface.rb +166 -0
  52. data/examples/RedBook/teaambient.rb +132 -0
  53. data/examples/RedBook/teapots.rb +182 -0
  54. data/examples/RedBook/tess.rb +183 -0
  55. data/examples/RedBook/texbind.rb +147 -0
  56. data/examples/RedBook/texgen.rb +169 -0
  57. data/examples/RedBook/texturesurf.rb +128 -0
  58. data/examples/RedBook/varray.rb +159 -0
  59. data/examples/RedBook/wrap.rb +148 -0
  60. data/examples/misc/OGLBench.rb +337 -0
  61. data/examples/misc/anisotropic.rb +194 -0
  62. data/examples/misc/fbo_test.rb +356 -0
  63. data/examples/misc/font-glut.rb +46 -0
  64. data/examples/misc/glfwtest.rb +30 -0
  65. data/examples/misc/plane.rb +161 -0
  66. data/examples/misc/readpixel.rb +65 -0
  67. data/examples/misc/sdltest.rb +34 -0
  68. data/examples/misc/trislam.rb +828 -0
  69. data/ext/common/common.h +423 -0
  70. data/ext/common/conv.h +243 -0
  71. data/ext/common/funcdef.h +280 -0
  72. data/ext/common/gl-enums.h +10031 -0
  73. data/ext/common/gl-error.h +23 -0
  74. data/ext/common/gl-types.h +63 -0
  75. data/ext/common/glu-enums.h +463 -0
  76. data/ext/gl/gl-1.0-1.1.c +2811 -0
  77. data/ext/gl/gl-1.2.c +814 -0
  78. data/ext/gl/gl-1.3.c +443 -0
  79. data/ext/gl/gl-1.4.c +348 -0
  80. data/ext/gl/gl-1.5.c +225 -0
  81. data/ext/gl/gl-2.0.c +657 -0
  82. data/ext/gl/gl-2.1.c +57 -0
  83. data/ext/gl/gl-enums.c +3354 -0
  84. data/ext/gl/gl-error.c +104 -0
  85. data/ext/gl/gl-ext-3dfx.c +27 -0
  86. data/ext/gl/gl-ext-arb.c +866 -0
  87. data/ext/gl/gl-ext-ati.c +41 -0
  88. data/ext/gl/gl-ext-ext.c +889 -0
  89. data/ext/gl/gl-ext-gremedy.c +41 -0
  90. data/ext/gl/gl-ext-nv.c +679 -0
  91. data/ext/gl/gl.c +214 -0
  92. data/ext/gl/mkrf_conf.rb +37 -0
  93. data/ext/glu/glu-enums.c +164 -0
  94. data/ext/glu/glu.c +1530 -0
  95. data/ext/glu/mkrf_conf.rb +39 -0
  96. data/ext/glut/glut.c +1627 -0
  97. data/ext/glut/mkrf_conf.rb +37 -0
  98. data/lib/opengl.rb +84 -0
  99. data/test/README +10 -0
  100. data/test/tc_common.rb +98 -0
  101. data/test/tc_ext_arb.rb +467 -0
  102. data/test/tc_ext_ati.rb +33 -0
  103. data/test/tc_ext_ext.rb +551 -0
  104. data/test/tc_ext_gremedy.rb +36 -0
  105. data/test/tc_ext_nv.rb +357 -0
  106. data/test/tc_func_10_11.rb +1281 -0
  107. data/test/tc_func_12.rb +186 -0
  108. data/test/tc_func_13.rb +229 -0
  109. data/test/tc_func_14.rb +197 -0
  110. data/test/tc_func_15.rb +270 -0
  111. data/test/tc_func_20.rb +346 -0
  112. data/test/tc_func_21.rb +541 -0
  113. data/test/tc_glu.rb +310 -0
  114. data/test/tc_include_gl.rb +35 -0
  115. data/test/tc_misc.rb +54 -0
  116. data/test/tc_require_gl.rb +34 -0
  117. metadata +164 -0
@@ -0,0 +1,124 @@
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
+ # checker.c
40
+ # This program texture maps a checkerboard image onto
41
+ # two rectangles. This program clamps the texture, if
42
+ # the texture coordinates fall outside 0.0 and 1.0.
43
+ require 'opengl'
44
+ require 'mathn'
45
+ include Gl,Glu,Glut
46
+
47
+ # Create checkerboard texture
48
+ CheckImageWidth=64
49
+ CheckImageHeight=64
50
+ $checkImage = []
51
+
52
+ def makeCheckImage
53
+ for i in 0..CheckImageWidth-1
54
+ for j in 0..CheckImageHeight-1
55
+ c = if ((i&0x8==0) != (j&0x8==0)) then 255 else 0 end
56
+ $checkImage[(i+CheckImageWidth*j)*3+0] = c
57
+ $checkImage[(i+CheckImageWidth*j)*3+1] = c
58
+ $checkImage[(i+CheckImageWidth*j)*3+2] = c
59
+ end
60
+ end
61
+ end
62
+
63
+ def myinit
64
+ glClearColor(0.0, 0.0, 0.0, 0.0)
65
+ glEnable(GL_DEPTH_TEST)
66
+ glDepthFunc(GL_LESS)
67
+
68
+ makeCheckImage()
69
+ glPixelStore(GL_UNPACK_ALIGNMENT, 1)
70
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, CheckImageWidth,
71
+ CheckImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
72
+ $checkImage.pack("C*"))
73
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
74
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
75
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
76
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
77
+ glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
78
+ glEnable(GL_TEXTURE_2D)
79
+ glShadeModel(GL_FLAT)
80
+ end
81
+
82
+ display = Proc.new do
83
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
84
+ glBegin(GL_QUADS)
85
+ glTexCoord(0.0, 0.0); glVertex(-2.0, -1.0, 0.0)
86
+ glTexCoord(0.0, 1.0); glVertex(-2.0, 1.0, 0.0)
87
+ glTexCoord(1.0, 1.0); glVertex(0.0, 1.0, 0.0)
88
+ glTexCoord(1.0, 0.0); glVertex(0.0, -1.0, 0.0)
89
+
90
+ glTexCoord(0.0, 0.0); glVertex(1.0, -1.0, 0.0)
91
+ glTexCoord(0.0, 1.0); glVertex(1.0, 1.0, 0.0)
92
+ glTexCoord(1.0, 1.0); glVertex(2.41421, 1.0, -1.41421)
93
+ glTexCoord(1.0, 0.0); glVertex(2.41421, -1.0, -1.41421)
94
+ glEnd()
95
+ glutSwapBuffers()
96
+ end
97
+
98
+ myReshape = Proc.new do |w, h|
99
+ glViewport(0, 0, w, h)
100
+ glMatrixMode(GL_PROJECTION)
101
+ glLoadIdentity()
102
+ gluPerspective(60.0, 1.0*w/h, 1.0, 30.0)
103
+ glMatrixMode(GL_MODELVIEW)
104
+ glLoadIdentity()
105
+ glTranslate(0.0, 0.0, -3.6)
106
+ end
107
+
108
+ keyboard = Proc.new do |key, x, y|
109
+ case (key)
110
+ when ?\e
111
+ exit(0)
112
+ end
113
+ end
114
+
115
+ glutInit
116
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
117
+ glutInitWindowSize(500, 500)
118
+ glutInitWindowPosition(100, 100)
119
+ glutCreateWindow("checker")
120
+ myinit()
121
+ glutReshapeFunc(myReshape)
122
+ glutDisplayFunc(display)
123
+ glutKeyboardFunc(keyboard)
124
+ glutMainLoop()
@@ -0,0 +1,95 @@
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
+ # clip.c
38
+ # This program demonstrates arbitrary clipping planes.
39
+ require 'opengl'
40
+ require 'mathn'
41
+ include Gl,Glu,Glut
42
+
43
+ def init
44
+ glClearColor(0.0, 0.0, 0.0, 0.0)
45
+ glShadeModel(GL_FLAT)
46
+ end
47
+
48
+ display = Proc.new do
49
+ eqn = [0.0, 1.0, 0.0, 0.0]
50
+ eqn2 = [1.0, 0.0, 0.0, 0.0]
51
+
52
+ glClear(GL_COLOR_BUFFER_BIT)
53
+
54
+ glColor(1.0, 1.0, 1.0)
55
+ glPushMatrix()
56
+ glTranslate(0.0, 0.0, -5.0)
57
+
58
+ # clip lower half -- y < 0
59
+ glClipPlane(GL_CLIP_PLANE0, eqn)
60
+ glEnable(GL_CLIP_PLANE0)
61
+ # clip left half -- x < 0
62
+ glClipPlane(GL_CLIP_PLANE1, eqn2)
63
+ glEnable(GL_CLIP_PLANE1)
64
+
65
+ glRotate(90.0, 1.0, 0.0, 0.0)
66
+ glutWireSphere(1.0, 20, 16)
67
+ glPopMatrix()
68
+ glutSwapBuffers()
69
+ end
70
+
71
+ reshape = Proc.new do |w, h|
72
+ glViewport(0, 0, w, h)
73
+ glMatrixMode(GL_PROJECTION)
74
+ glLoadIdentity()
75
+ gluPerspective(60.0, w/ h, 1.0, 20.0)
76
+ glMatrixMode(GL_MODELVIEW)
77
+ end
78
+
79
+ keyboard = Proc.new do |key, x, y|
80
+ case (key)
81
+ when ?\e
82
+ exit(0)
83
+ end
84
+ end
85
+
86
+ glutInit
87
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
88
+ glutInitWindowSize(500, 500)
89
+ glutInitWindowPosition(100, 100)
90
+ glutCreateWindow($0)
91
+ init()
92
+ glutDisplayFunc(display)
93
+ glutReshapeFunc(reshape)
94
+ glutKeyboardFunc(keyboard)
95
+ glutMainLoop()
@@ -0,0 +1,135 @@
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
+ # colormat.c
38
+ # After initialization, the program will be in
39
+ # ColorMaterial mode. Interaction: pressing the
40
+ # mouse buttons will change the diffuse reflection values.
41
+ require 'opengl'
42
+ require 'mathn'
43
+ include Gl,Glu,Glut
44
+
45
+ $diffuseMaterial = [0.5,0.5,0.5,1.0]
46
+
47
+ # Initialize material property, light source, lighting model,
48
+ # and depth buffer.
49
+ def init
50
+ mat_specular = [ 1.0, 1.0, 1.0, 1.0 ]
51
+ light_position = [ 1.0, 1.0, 1.0, 0.0 ]
52
+
53
+ glClearColor(0.0, 0.0, 0.0, 0.0)
54
+ glShadeModel(GL_SMOOTH)
55
+ glEnable(GL_DEPTH_TEST)
56
+ glMaterial(GL_FRONT, GL_DIFFUSE, $diffuseMaterial)
57
+ glMaterial(GL_FRONT, GL_SPECULAR, mat_specular)
58
+ glMaterial(GL_FRONT, GL_SHININESS, 25.0)
59
+ glLight(GL_LIGHT0, GL_POSITION, light_position)
60
+ glEnable(GL_LIGHTING)
61
+ glEnable(GL_LIGHT0)
62
+
63
+ glColorMaterial(GL_FRONT, GL_DIFFUSE)
64
+ glEnable(GL_COLOR_MATERIAL)
65
+ end
66
+
67
+ display = Proc.new do
68
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
69
+ glutSolidSphere(1.0, 20, 16)
70
+ glutSwapBuffers()
71
+ end
72
+
73
+ reshape = Proc.new do |w, h|
74
+ glViewport(0, 0, w, h)
75
+ glMatrixMode(GL_PROJECTION)
76
+ glLoadIdentity()
77
+ if (w <= h)
78
+ glOrtho(-1.5, 1.5, -1.5*h/w, 1.5*h/w, -10.0, 10.0)
79
+ else
80
+ glOrtho(-1.5*w/h, 1.5*w/h, -1.5, 1.5, -10.0, 10.0)
81
+ end
82
+ glMatrixMode(GL_MODELVIEW)
83
+ glLoadIdentity()
84
+ end
85
+
86
+ mouse = Proc.new do |button, state, x, y|
87
+ case (button)
88
+ when GLUT_LEFT_BUTTON
89
+ if (state == GLUT_DOWN)
90
+ $diffuseMaterial[0] = $diffuseMaterial[0] + 0.1
91
+ if ($diffuseMaterial[0] > 1.0)
92
+ $diffuseMaterial[0] = 0.0
93
+ end
94
+ glColor($diffuseMaterial)
95
+ glutPostRedisplay()
96
+ end
97
+ when GLUT_MIDDLE_BUTTON
98
+ if (state == GLUT_DOWN)
99
+ $diffuseMaterial[1] = $diffuseMaterial[1] + 0.1
100
+ if ($diffuseMaterial[1] > 1.0)
101
+ $diffuseMaterial[1] = 0.0
102
+ end
103
+ glColor($diffuseMaterial)
104
+ glutPostRedisplay()
105
+ end
106
+ when GLUT_RIGHT_BUTTON
107
+ if (state == GLUT_DOWN)
108
+ $diffuseMaterial[2] = $diffuseMaterial[2] + 0.1
109
+ if ($diffuseMaterial[2] > 1.0)
110
+ $diffuseMaterial[2] = 0.0
111
+ end
112
+ glColor($diffuseMaterial)
113
+ glutPostRedisplay()
114
+ end
115
+ end
116
+ end
117
+
118
+ keyboard = Proc.new do |key, x, y|
119
+ case (key)
120
+ when ?\e
121
+ exit(0)
122
+ end
123
+ end
124
+
125
+ glutInit
126
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
127
+ glutInitWindowSize(500, 500)
128
+ glutInitWindowPosition(100, 100)
129
+ glutCreateWindow($0)
130
+ init()
131
+ glutDisplayFunc(display)
132
+ glutReshapeFunc(reshape)
133
+ glutMouseFunc(mouse)
134
+ glutKeyboardFunc(keyboard)
135
+ glutMainLoop()
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby -rubygems
2
+ require 'opengl'
3
+ include Gl,Glu,Glut
4
+
5
+ $light_diffuse = [1.0, 0.0, 0.0, 1.0]
6
+ $light_position = [1.0, 1.0, 1.0, 0.0]
7
+ $n = [
8
+ [-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0],
9
+ [0.0, -1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0] ]
10
+ $faces = [
11
+ [0, 1, 2, 3], [3, 2, 6, 7], [7, 6, 5, 4],
12
+ [4, 5, 1, 0], [5, 6, 2, 1], [7, 4, 0, 3] ]
13
+ $v = 0
14
+
15
+ def drawBox
16
+ for i in (0..5)
17
+ glBegin(GL_QUADS)
18
+ glNormal(*($n[i]))
19
+ glVertex($v[$faces[i][0]])
20
+ glVertex($v[$faces[i][1]])
21
+ glVertex($v[$faces[i][2]])
22
+ glVertex($v[$faces[i][3]])
23
+ glEnd()
24
+ end
25
+ end
26
+
27
+ display = Proc.new do
28
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
29
+ drawBox
30
+ glutSwapBuffers
31
+ end
32
+
33
+ def myinit
34
+ $v = [[-1, -1,1],[-1, -1,-1], [-1,1,-1], [-1,1,1], [1, -1,1],
35
+ [1, -1,-1], [1, 1,-1], [1,1,1]]
36
+
37
+ glLight(GL_LIGHT0, GL_DIFFUSE, $light_diffuse)
38
+ glLight(GL_LIGHT0, GL_POSITION, $light_position)
39
+ glEnable(GL_LIGHT0)
40
+ glEnable(GL_LIGHTING)
41
+
42
+ glEnable(GL_DEPTH_TEST)
43
+
44
+ glMatrixMode(GL_PROJECTION)
45
+ gluPerspective(40.0, 1.0, 1.0, 10.0)
46
+ glMatrixMode(GL_MODELVIEW)
47
+ gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
48
+
49
+ glTranslate(0.0, 0.0, -1.0)
50
+ glRotate(60, 1.0, 0.0, 0.0)
51
+ glRotate(-20, 0.0, 0.0, 1.0)
52
+ end
53
+
54
+ keyboard = Proc.new do |key, x, y|
55
+ case (key)
56
+ when ?\e
57
+ exit(0);
58
+ end
59
+ end
60
+
61
+ glutInit
62
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
63
+ glutInitWindowSize(500, 500)
64
+ glutInitWindowPosition(100, 100)
65
+ glutCreateWindow("red 3D lighted cube")
66
+ glutDisplayFunc(display)
67
+ glutKeyboardFunc(keyboard)
68
+ myinit
69
+ glutMainLoop()
@@ -0,0 +1,99 @@
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
+ # depthcue.c
40
+ # This program draws a wireframe model, which uses
41
+ # intensity (brightness) to give clues to distance.
42
+ # Fog is used to achieve this effect.
43
+ require 'opengl'
44
+ require 'mathn'
45
+ include Gl,Glu,Glut
46
+
47
+ # Initialize linear fog for depth cueing.
48
+ def myinit
49
+ fogColor = [0.0, 0.0, 0.0, 1.0]
50
+
51
+ glEnable(GL_FOG)
52
+ glFog(GL_FOG_MODE, GL_LINEAR)
53
+ glHint(GL_FOG_HINT, GL_NICEST) # per pixel
54
+ glFog(GL_FOG_START, 3.0)
55
+ glFog(GL_FOG_END, 5.0)
56
+ glFog(GL_FOG_COLOR, fogColor)
57
+ glClearColor(0.0, 0.0, 0.0, 1.0)
58
+
59
+ glDepthFunc(GL_LESS)
60
+ glEnable(GL_DEPTH_TEST)
61
+ glShadeModel(GL_FLAT)
62
+ end
63
+
64
+ # display() draws an icosahedron.
65
+ display = Proc.new do
66
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
67
+ glColor(1.0, 1.0, 1.0)
68
+ glutWireIcosahedron()
69
+ glFlush()
70
+ end
71
+
72
+ myReshape = Proc.new do |w, h|
73
+ glViewport(0, 0, w, h)
74
+ glMatrixMode(GL_PROJECTION)
75
+ glLoadIdentity()
76
+ gluPerspective(45.0, w/h, 3.0, 5.0)
77
+ glMatrixMode(GL_MODELVIEW)
78
+ glLoadIdentity()
79
+ glTranslate(0.0, 0.0, -4.0) # move object into view
80
+ end
81
+
82
+ keyboard = Proc.new do |key, x, y|
83
+ case (key)
84
+ when ?\e
85
+ exit(0)
86
+ end
87
+ end
88
+
89
+ # Main Loop
90
+ glutInit
91
+ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
92
+ glutInitWindowSize(500, 500)
93
+ glutInitWindowPosition(100, 100)
94
+ glutCreateWindow($0)
95
+ myinit()
96
+ glutReshapeFunc(myReshape)
97
+ glutDisplayFunc(display)
98
+ glutKeyboardFunc(keyboard)
99
+ glutMainLoop()