ruby-opengl 0.40.1 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -2
- data/doc/build_install.txt +48 -28
- data/doc/extensions.txt +361 -0
- data/doc/history.txt +8 -2
- data/doc/requirements_and_design.txt +0 -13
- data/doc/roadmap.txt +11 -13
- data/doc/supplies/page_template.html +11 -5
- data/doc/thanks.txt +2 -4
- data/doc/tutorial.txt +1 -4
- data/examples/{nehe_lesson02.rb → NeHe/nehe_lesson02.rb} +0 -0
- data/examples/{nehe_lesson03.rb → NeHe/nehe_lesson03.rb} +0 -0
- data/examples/{nehe_lesson04.rb → NeHe/nehe_lesson04.rb} +0 -0
- data/examples/{nehe_lesson05.rb → NeHe/nehe_lesson05.rb} +0 -0
- data/examples/NeHe/nehe_lesson36.rb +303 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +388 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +424 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +13 -83
- data/examples/RedBook/aaindex.rb +97 -0
- data/examples/RedBook/aapoly.rb +142 -0
- data/examples/RedBook/aargb.rb +119 -0
- data/examples/RedBook/accanti.rb +162 -0
- data/examples/RedBook/accpersp.rb +215 -0
- data/examples/RedBook/alpha.rb +123 -0
- data/examples/RedBook/alpha3D.rb +158 -0
- data/examples/RedBook/bezcurve.rb +105 -0
- data/examples/RedBook/bezmesh.rb +137 -0
- data/examples/RedBook/checker.rb +124 -0
- data/examples/RedBook/clip.rb +95 -0
- data/examples/RedBook/colormat.rb +135 -0
- data/examples/RedBook/cube.rb +69 -0
- data/examples/RedBook/depthcue.rb +99 -0
- data/examples/RedBook/dof.rb +205 -0
- data/examples/{legacy → RedBook}/double.rb +59 -58
- data/examples/{legacy → RedBook}/drawf.rb +47 -54
- data/examples/RedBook/feedback.rb +145 -0
- data/examples/RedBook/fog.rb +167 -0
- data/examples/RedBook/font.rb +151 -0
- data/examples/RedBook/hello.rb +79 -0
- data/examples/RedBook/image.rb +137 -0
- data/examples/{legacy → RedBook}/jitter.rb +60 -62
- data/examples/RedBook/lines.rb +128 -0
- data/examples/RedBook/list.rb +111 -0
- data/examples/RedBook/material.rb +275 -0
- data/examples/RedBook/mipmap.rb +156 -0
- data/examples/{legacy → RedBook}/model.rb +66 -72
- data/examples/{legacy → RedBook}/movelight.rb +67 -75
- data/examples/RedBook/pickdepth.rb +179 -0
- data/examples/{legacy → RedBook}/planet.rb +62 -66
- data/examples/RedBook/quadric.rb +158 -0
- data/examples/RedBook/robot.rb +115 -0
- data/examples/RedBook/select.rb +196 -0
- data/examples/RedBook/smooth.rb +95 -0
- data/examples/RedBook/stencil.rb +163 -0
- data/examples/RedBook/stroke.rb +167 -0
- data/examples/RedBook/surface.rb +166 -0
- data/examples/RedBook/teaambient.rb +132 -0
- data/examples/RedBook/teapots.rb +182 -0
- data/examples/RedBook/tess.rb +183 -0
- data/examples/RedBook/texbind.rb +147 -0
- data/examples/RedBook/texgen.rb +169 -0
- data/examples/RedBook/texturesurf.rb +128 -0
- data/examples/RedBook/varray.rb +159 -0
- data/examples/RedBook/wrap.rb +148 -0
- data/examples/misc/anisotropic.rb +194 -0
- data/examples/misc/font-glut.rb +46 -0
- data/examples/{plane.rb → misc/plane.rb} +0 -0
- data/examples/misc/readpixel.rb +65 -0
- data/examples/{smooth.rb → misc/smooth.rb} +0 -0
- data/examples/{test.rb → misc/test.rb} +0 -0
- data/ext/common/common.h +252 -70
- data/ext/common/gl-enums.h +6102 -7334
- data/ext/common/gl-types.h +47 -0
- data/ext/common/glu-enums.h +469 -0
- data/ext/gl/gl-1.0-1.1.c +842 -2464
- data/ext/gl/gl-1.2.c +217 -281
- data/ext/gl/gl-1.3.c +113 -133
- data/ext/gl/gl-1.4.c +98 -334
- data/ext/gl/gl-1.5.c +28 -34
- data/ext/gl/gl-2.0.c +26 -235
- data/ext/gl/gl-2.1.c +31 -124
- data/ext/gl/gl-enums.c +786 -631
- data/ext/gl/gl-ext-arb.c +66 -0
- data/ext/gl/gl-ext-ext.c +218 -0
- data/ext/gl/gl.c +138 -31
- data/ext/gl/mkrf_conf.rb +1 -0
- data/ext/glu/glu-enums.c +163 -0
- data/ext/glu/glu.c +1003 -1205
- data/ext/glu/mkrf_conf.rb +1 -0
- data/ext/glut/glut.c +1056 -1175
- data/lib/opengl.rb +90 -3
- data/test/tc_common.rb +26 -13
- data/test/tc_ext_arb.rb +73 -0
- data/test/tc_ext_ext.rb +74 -0
- data/test/tc_func_12.rb +8 -8
- data/test/tc_func_13.rb +17 -11
- data/test/tc_func_14.rb +8 -8
- data/test/tc_func_15.rb +190 -2
- data/test/tc_func_20.rb +36 -10
- data/test/tc_func_21.rb +445 -2
- data/test/tc_glu.rb +305 -0
- data/test/tc_misc.rb +1 -0
- metadata +84 -68
- data/doc/screenshots.txt +0 -23
- data/examples/legacy/COPYRIGHT +0 -8
- data/examples/legacy/aaindex.rb +0 -98
- data/examples/legacy/aapoly.rb +0 -153
- data/examples/legacy/aargb.rb +0 -139
- data/examples/legacy/accanti.rb +0 -159
- data/examples/legacy/accpersp.rb +0 -216
- data/examples/legacy/alpha.rb +0 -133
- data/examples/legacy/alpha3D.rb +0 -165
- data/examples/legacy/bezcurve.rb +0 -107
- data/examples/legacy/bezmesh.rb +0 -131
- data/examples/legacy/checker.rb +0 -121
- data/examples/legacy/clip.rb +0 -104
- data/examples/legacy/colormat.rb +0 -145
- data/examples/legacy/cube.rb +0 -73
- data/examples/legacy/depthcue.rb +0 -101
- data/examples/legacy/dof.rb +0 -212
- data/examples/legacy/feedback.rb +0 -152
- data/examples/legacy/fog.rb +0 -172
- data/examples/legacy/font-glut.rb +0 -41
- data/examples/legacy/font.rb +0 -158
- data/examples/legacy/hello.rb +0 -75
- data/examples/legacy/image.rb +0 -145
- data/examples/legacy/lines.rb +0 -135
- data/examples/legacy/list.rb +0 -120
- data/examples/legacy/material.rb +0 -290
- data/examples/legacy/mipmap.rb +0 -159
- data/examples/legacy/pickdepth.rb +0 -180
- data/examples/legacy/quadric.rb +0 -180
- data/examples/legacy/readpixel.rb +0 -59
- data/examples/legacy/robot.rb +0 -120
- data/examples/legacy/select.rb +0 -207
- data/examples/legacy/smooth.rb +0 -41
- data/examples/legacy/stencil.rb +0 -154
- data/examples/legacy/stroke.rb +0 -170
- data/examples/legacy/surface.rb +0 -170
- data/examples/legacy/teaambient.rb +0 -132
- data/examples/legacy/teapots.rb +0 -188
- data/examples/legacy/tess.rb +0 -222
- data/examples/legacy/texbind.rb +0 -157
- data/examples/legacy/texgen.rb +0 -171
- data/examples/legacy/texturesurf.rb +0 -128
- data/examples/legacy/varray.rb +0 -167
- data/examples/legacy/wrap.rb +0 -158
- data/lib/gl_prev.rb +0 -46
- data/lib/glu_prev.rb +0 -46
- data/lib/glut_prev.rb +0 -45
@@ -0,0 +1,156 @@
|
|
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 'mathn'
|
47
|
+
include Gl,Glu,Glut
|
48
|
+
|
49
|
+
$mipmapImage32 = []
|
50
|
+
$mipmapImage16 = []
|
51
|
+
$mipmapImage8 = []
|
52
|
+
$mipmapImage4 = []
|
53
|
+
$mipmapImage2 = []
|
54
|
+
$mipmapImage1 = []
|
55
|
+
|
56
|
+
def makeImages
|
57
|
+
for i in 0..31
|
58
|
+
for j in 0..31
|
59
|
+
$mipmapImage32[(j*32+i)*3+0] = 255
|
60
|
+
$mipmapImage32[(j*32+i)*3+1] = 255
|
61
|
+
$mipmapImage32[(j*32+i)*3+2] = 0
|
62
|
+
end
|
63
|
+
end
|
64
|
+
for i in 0..15
|
65
|
+
for j in 0..15
|
66
|
+
$mipmapImage16[(j*16+i)*3+0] = 255
|
67
|
+
$mipmapImage16[(j*16+i)*3+1] = 0
|
68
|
+
$mipmapImage16[(j*16+i)*3+2] = 255
|
69
|
+
end
|
70
|
+
end
|
71
|
+
for i in 0..7
|
72
|
+
for j in 0..7
|
73
|
+
$mipmapImage8[(j*8+i)*3+0] = 255
|
74
|
+
$mipmapImage8[(j*8+i)*3+1] = 0
|
75
|
+
$mipmapImage8[(j*8+i)*3+2] = 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
for i in 0..3
|
79
|
+
for j in 0..3
|
80
|
+
$mipmapImage4[(j*4+i)*3+0] = 0
|
81
|
+
$mipmapImage4[(j*4+i)*3+1] = 255
|
82
|
+
$mipmapImage4[(j*4+i)*3+2] = 0
|
83
|
+
end
|
84
|
+
end
|
85
|
+
for i in 0..1
|
86
|
+
for j in 0..1
|
87
|
+
$mipmapImage2[(j*2+i)*3+0] = 0
|
88
|
+
$mipmapImage2[(j*2+i)*3+1] = 0
|
89
|
+
$mipmapImage2[(j*2+i)*3+2] = 255
|
90
|
+
end
|
91
|
+
end
|
92
|
+
$mipmapImage1[0] = 255
|
93
|
+
$mipmapImage1[1] = 255
|
94
|
+
$mipmapImage1[2] = 255
|
95
|
+
end
|
96
|
+
|
97
|
+
def myinit
|
98
|
+
glEnable(GL_DEPTH_TEST)
|
99
|
+
glDepthFunc(GL_LESS)
|
100
|
+
glShadeModel(GL_FLAT)
|
101
|
+
|
102
|
+
glTranslate(0.0, 0.0, -3.6)
|
103
|
+
makeImages()
|
104
|
+
glPixelStore(GL_UNPACK_ALIGNMENT, 1)
|
105
|
+
glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage32.pack("C*"))
|
106
|
+
glTexImage2D(GL_TEXTURE_2D, 1, 3, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage16.pack("C*"))
|
107
|
+
glTexImage2D(GL_TEXTURE_2D, 2, 3, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage8.pack("C*"))
|
108
|
+
glTexImage2D(GL_TEXTURE_2D, 3, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage4.pack("C*"))
|
109
|
+
glTexImage2D(GL_TEXTURE_2D, 4, 3, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage2.pack("C*"))
|
110
|
+
glTexImage2D(GL_TEXTURE_2D, 5, 3, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, $mipmapImage1.pack("C*"))
|
111
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
112
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
113
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
114
|
+
glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
115
|
+
GL_NEAREST_MIPMAP_NEAREST)
|
116
|
+
glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
|
117
|
+
glEnable(GL_TEXTURE_2D)
|
118
|
+
end
|
119
|
+
|
120
|
+
display = Proc.new do
|
121
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
122
|
+
glBegin(GL_QUADS)
|
123
|
+
glTexCoord(0.0, 0.0); glVertex(-2.0, -1.0, 0.0)
|
124
|
+
glTexCoord(0.0, 8.0); glVertex(-2.0, 1.0, 0.0)
|
125
|
+
glTexCoord(8.0, 8.0); glVertex(2000.0, 1.0, -6000.0)
|
126
|
+
glTexCoord(8.0, 0.0); glVertex(2000.0, -1.0, -6000.0)
|
127
|
+
glEnd()
|
128
|
+
glutSwapBuffers()
|
129
|
+
end
|
130
|
+
|
131
|
+
myReshape = Proc.new do |w, h|
|
132
|
+
glViewport(0, 0, w, h)
|
133
|
+
glMatrixMode(GL_PROJECTION)
|
134
|
+
glLoadIdentity()
|
135
|
+
gluPerspective(60.0, 1.0*w/h, 1.0, 30000.0)
|
136
|
+
glMatrixMode(GL_MODELVIEW)
|
137
|
+
glLoadIdentity()
|
138
|
+
end
|
139
|
+
|
140
|
+
keyboard = Proc.new do |key, x, y|
|
141
|
+
case (key)
|
142
|
+
when 27
|
143
|
+
exit(0);
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
glutInit
|
148
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
149
|
+
glutInitWindowSize(500, 500)
|
150
|
+
glutInitWindowPosition(100, 100)
|
151
|
+
glutCreateWindow($0)
|
152
|
+
myinit()
|
153
|
+
glutReshapeFunc(myReshape)
|
154
|
+
glutDisplayFunc(display)
|
155
|
+
glutKeyboardFunc(keyboard)
|
156
|
+
glutMainLoop()
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# or publicity pertaining to distribution of the software without specific,
|
10
10
|
# written prior permission.
|
11
11
|
#
|
12
|
-
#THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
12
|
+
# THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
13
13
|
# AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
14
14
|
# INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
15
15
|
# FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
@@ -33,87 +33,81 @@
|
|
33
33
|
# Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
34
|
#
|
35
35
|
# OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
-
#/
|
37
|
-
|
38
36
|
#
|
39
37
|
# model.c
|
40
38
|
# This program demonstrates modeling transformations
|
41
|
-
|
42
|
-
require
|
43
|
-
|
44
|
-
require "glut_prev"
|
45
|
-
require "mathn"
|
39
|
+
require 'opengl'
|
40
|
+
require 'mathn'
|
41
|
+
include Gl,Glu,Glut
|
46
42
|
|
47
43
|
def init
|
48
|
-
|
49
|
-
|
44
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
45
|
+
glShadeModel(GL_FLAT)
|
50
46
|
end
|
51
47
|
|
52
48
|
def draw_triangle
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
glBegin(GL_LINE_LOOP)
|
50
|
+
glVertex(0.0, 25.0)
|
51
|
+
glVertex(25.0, -25.0)
|
52
|
+
glVertex(-25.0, -25.0)
|
53
|
+
glEnd()
|
58
54
|
end
|
59
55
|
|
60
|
-
display = Proc.new
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
56
|
+
display = Proc.new do
|
57
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
58
|
+
glColor(1.0, 1.0, 1.0)
|
59
|
+
|
60
|
+
glLoadIdentity()
|
61
|
+
glColor(1.0, 1.0, 1.0)
|
62
|
+
draw_triangle()
|
63
|
+
|
64
|
+
glEnable(GL_LINE_STIPPLE)
|
65
|
+
glLineStipple(1, 0xF0F0)
|
66
|
+
glLoadIdentity()
|
67
|
+
glTranslate(-20.0, 0.0, 0.0)
|
68
|
+
draw_triangle()
|
69
|
+
|
70
|
+
glLineStipple(1, 0xF00F)
|
71
|
+
glLoadIdentity()
|
72
|
+
glScale(1.5, 0.5, 1.0)
|
73
|
+
draw_triangle()
|
74
|
+
|
75
|
+
glLineStipple(1, 0x8888)
|
76
|
+
glLoadIdentity()
|
77
|
+
glRotate(90.0, 0.0, 0.0, 1.0)
|
78
|
+
draw_triangle()
|
79
|
+
glDisable(GL_LINE_STIPPLE)
|
80
|
+
|
81
|
+
glutSwapBuffers()
|
82
|
+
end
|
87
83
|
|
88
|
-
reshape = Proc.new
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
GL.MatrixMode(GL::MODELVIEW);
|
100
|
-
}
|
84
|
+
reshape = Proc.new do |w, h|
|
85
|
+
glViewport(0, 0, w, h)
|
86
|
+
glMatrixMode(GL_PROJECTION)
|
87
|
+
glLoadIdentity()
|
88
|
+
if (w <= h)
|
89
|
+
glOrtho(-50.0, 50.0, -50.0*h/w, 50.0*h/w, -1.0, 1.0)
|
90
|
+
else
|
91
|
+
glOrtho(-50.0*w/h,50.0*w/h, -50.0, 50.0, -1.0, 1.0)
|
92
|
+
end
|
93
|
+
glMatrixMode(GL_MODELVIEW)
|
94
|
+
end
|
101
95
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
}
|
96
|
+
keyboard = Proc.new do |key, x, y|
|
97
|
+
case key
|
98
|
+
when 27
|
99
|
+
exit(0)
|
100
|
+
end
|
101
|
+
end
|
109
102
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
103
|
+
# main
|
104
|
+
glutInit()
|
105
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
106
|
+
glutInitWindowSize(500, 500)
|
107
|
+
glutInitWindowPosition(100, 100)
|
108
|
+
glutCreateWindow($0)
|
109
|
+
init()
|
110
|
+
glutDisplayFunc(display)
|
111
|
+
glutReshapeFunc(reshape)
|
112
|
+
glutKeyboardFunc(keyboard)
|
113
|
+
glutMainLoop()
|
@@ -33,8 +33,6 @@
|
|
33
33
|
# Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
34
|
#
|
35
35
|
# OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
-
#/
|
37
|
-
|
38
36
|
#
|
39
37
|
# movelight.c
|
40
38
|
# This program demonstrates when to issue lighting and
|
@@ -49,92 +47,86 @@
|
|
49
47
|
# Interaction: pressing the left mouse button alters
|
50
48
|
# the modeling transformation (x rotation) by 30 degrees.
|
51
49
|
# The scene is then redrawn with the light in a new position.
|
52
|
-
#/
|
53
50
|
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
|
58
|
-
require "mathn"
|
51
|
+
require 'opengl'
|
52
|
+
require 'rational'
|
53
|
+
require 'mathn'
|
54
|
+
include Gl,Glu,Glut
|
59
55
|
|
60
|
-
$spin = 0
|
56
|
+
$spin = 0
|
61
57
|
|
62
58
|
# Initialize material property, light source, lighting model,
|
63
59
|
# and depth buffer.
|
64
|
-
#/
|
65
60
|
def init
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
62
|
+
glShadeModel(GL_SMOOTH)
|
63
|
+
glEnable(GL_LIGHTING)
|
64
|
+
glEnable(GL_LIGHT0)
|
65
|
+
glEnable(GL_DEPTH_TEST)
|
71
66
|
end
|
72
67
|
|
73
68
|
# Here is where the light position is reset after the modeling
|
74
69
|
# transformation (glRotated) is called. This places the
|
75
70
|
# light at a new position in world coordinates. The cube
|
76
71
|
# represents the position of the light.
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}
|
72
|
+
display = Proc.new do
|
73
|
+
position = [ 0.0, 0.0, 1.5, 1.0 ]
|
74
|
+
|
75
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
76
|
+
glPushMatrix()
|
77
|
+
GLU.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
|
78
|
+
|
79
|
+
glPushMatrix()
|
80
|
+
glRotate($spin, 1.0, 0.0, 0.0)
|
81
|
+
glLight(GL_LIGHT0, GL_POSITION, position)
|
82
|
+
|
83
|
+
glTranslate(0.0, 0.0, 1.5)
|
84
|
+
glDisable(GL_LIGHTING)
|
85
|
+
glColor(0.0, 1.0, 1.0)
|
86
|
+
glutWireCube(0.1)
|
87
|
+
glEnable(GL_LIGHTING)
|
88
|
+
glPopMatrix()
|
89
|
+
|
90
|
+
glutSolidTorus(0.275, 0.85, 8, 15)
|
91
|
+
glPopMatrix()
|
92
|
+
glutSwapBuffers()
|
93
|
+
end
|
100
94
|
|
101
|
-
reshape = Proc.new
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
95
|
+
reshape = Proc.new do |w, h|
|
96
|
+
glViewport(0, 0, w, h)
|
97
|
+
glMatrixMode(GL_PROJECTION)
|
98
|
+
glLoadIdentity()
|
99
|
+
gluPerspective(40.0, w/h, 1.0, 20.0)
|
100
|
+
glMatrixMode(GL_MODELVIEW)
|
101
|
+
glLoadIdentity()
|
102
|
+
end
|
110
103
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
}
|
104
|
+
mouse = Proc.new do |button, state, x, y|
|
105
|
+
case button
|
106
|
+
when GLUT_LEFT_BUTTON
|
107
|
+
if (state == GLUT_DOWN)
|
108
|
+
$spin = ($spin + 30) % 360
|
109
|
+
glutPostRedisplay()
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
121
113
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
}
|
114
|
+
keyboard = Proc.new do |key, x, y|
|
115
|
+
case key
|
116
|
+
when 27
|
117
|
+
exit(0)
|
118
|
+
end
|
119
|
+
end
|
129
120
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
121
|
+
# main
|
122
|
+
glutInit
|
123
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
124
|
+
glutInitWindowSize(500, 500)
|
125
|
+
glutInitWindowPosition(100, 100)
|
126
|
+
glutCreateWindow($0)
|
127
|
+
init()
|
128
|
+
glutDisplayFunc(display)
|
129
|
+
glutReshapeFunc(reshape)
|
130
|
+
glutMouseFunc(mouse)
|
131
|
+
glutKeyboardFunc(keyboard)
|
132
|
+
glutMainLoop()
|