opengl 0.7.0.pre1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +8 -0
- data/History.txt +36 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +140 -0
- data/README.rdoc +51 -0
- data/Rakefile +129 -0
- data/Rakefile.cross +104 -0
- data/doc/build_install.txt +119 -0
- data/doc/extensions.txt.in +348 -0
- data/doc/history.txt +66 -0
- data/doc/requirements_and_design.txt +117 -0
- data/doc/roadmap.txt +28 -0
- data/doc/scientific_use.txt +35 -0
- data/doc/supplies/page_template.html +71 -0
- data/doc/thanks.txt +29 -0
- data/doc/tutorial.txt +469 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +122 -0
- data/examples/NeHe/nehe_lesson04.rb +133 -0
- data/examples/NeHe/nehe_lesson05.rb +186 -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 +376 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +406 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -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/RedBook/double.rb +105 -0
- data/examples/RedBook/drawf.rb +91 -0
- 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/RedBook/jitter.rb +207 -0
- 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/RedBook/model.rb +113 -0
- data/examples/RedBook/movelight.rb +132 -0
- data/examples/RedBook/pickdepth.rb +179 -0
- data/examples/RedBook/planet.rb +108 -0
- 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/OGLBench.rb +337 -0
- data/examples/misc/anisotropic.rb +194 -0
- data/examples/misc/fbo_test.rb +356 -0
- data/examples/misc/font-glut.rb +46 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +65 -0
- data/examples/misc/sdltest.rb +34 -0
- data/examples/misc/trislam.rb +828 -0
- data/ext/common/common.h +448 -0
- data/ext/common/conv.h +234 -0
- data/ext/common/funcdef.h +280 -0
- data/ext/common/gl-enums.h +10031 -0
- data/ext/common/gl-error.h +23 -0
- data/ext/common/gl-types.h +67 -0
- data/ext/common/glu-enums.h +463 -0
- data/ext/gl/extconf.rb +43 -0
- data/ext/gl/gl-1.0-1.1.c +2811 -0
- data/ext/gl/gl-1.2.c +814 -0
- data/ext/gl/gl-1.3.c +443 -0
- data/ext/gl/gl-1.4.c +348 -0
- data/ext/gl/gl-1.5.c +225 -0
- data/ext/gl/gl-2.0.c +657 -0
- data/ext/gl/gl-2.1.c +57 -0
- data/ext/gl/gl-enums.c +3354 -0
- data/ext/gl/gl-error.c +104 -0
- data/ext/gl/gl-ext-3dfx.c +27 -0
- data/ext/gl/gl-ext-arb.c +866 -0
- data/ext/gl/gl-ext-ati.c +41 -0
- data/ext/gl/gl-ext-ext.c +889 -0
- data/ext/gl/gl-ext-gremedy.c +41 -0
- data/ext/gl/gl-ext-nv.c +679 -0
- data/ext/gl/gl.c +216 -0
- data/ext/glu/extconf.rb +51 -0
- data/ext/glu/glu-enums.c +164 -0
- data/ext/glu/glu.c +1530 -0
- data/ext/glut/extconf.rb +67 -0
- data/ext/glut/glut.c +1624 -0
- data/lib/opengl.rb +89 -0
- data/test/README +10 -0
- data/test/tc_common.rb +98 -0
- data/test/tc_ext_arb.rb +467 -0
- data/test/tc_ext_ati.rb +33 -0
- data/test/tc_ext_ext.rb +551 -0
- data/test/tc_ext_gremedy.rb +36 -0
- data/test/tc_ext_nv.rb +357 -0
- data/test/tc_func_10_11.rb +1281 -0
- data/test/tc_func_12.rb +186 -0
- data/test/tc_func_13.rb +229 -0
- data/test/tc_func_14.rb +197 -0
- data/test/tc_func_15.rb +270 -0
- data/test/tc_func_20.rb +346 -0
- data/test/tc_func_21.rb +541 -0
- data/test/tc_glu.rb +310 -0
- data/test/tc_include_gl.rb +35 -0
- data/test/tc_misc.rb +54 -0
- data/test/tc_require_gl.rb +34 -0
- data/utils/README +11 -0
- data/utils/enumgen.rb +112 -0
- data/utils/extlistgen.rb +90 -0
- data/utils/mkdn2html.rb +59 -0
- data/utils/post-mkdn2html.rb +91 -0
- data/website/images/ogl.jpg +0 -0
- data/website/images/tab_bottom.gif +0 -0
- data/website/style.css +198 -0
- metadata +274 -0
@@ -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 ?\e
|
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()
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 1993-1997, Silicon Graphics, Inc.
|
3
|
+
# ALL RIGHTS RESERVED
|
4
|
+
# Permission to use, copy, modify, and distribute this software for
|
5
|
+
# any purpose and without fee is hereby granted, provided that the above
|
6
|
+
# copyright notice appear in all copies and that both the copyright notice
|
7
|
+
# and this permission notice appear in supporting documentation, and that
|
8
|
+
# the name of Silicon Graphics, Inc. not be used in advertising
|
9
|
+
# or publicity pertaining to distribution of the software without specific,
|
10
|
+
# written prior permission.
|
11
|
+
#
|
12
|
+
# THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
13
|
+
# AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
14
|
+
# INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
16
|
+
# GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
17
|
+
# SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
18
|
+
# KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
19
|
+
# LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
20
|
+
# THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
21
|
+
# ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
22
|
+
# ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
23
|
+
# POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
24
|
+
#
|
25
|
+
# US Government Users Restricted Rights
|
26
|
+
# Use, duplication, or disclosure by the Government is subject to
|
27
|
+
# restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
28
|
+
# (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
29
|
+
# clause at DFARS 252.227-7013 and/or in similar or successor
|
30
|
+
# clauses in the FAR or the DOD or NASA FAR Supplement.
|
31
|
+
# Unpublished-- rights reserved under the copyright laws of the
|
32
|
+
# United States. Contractor/manufacturer is Silicon Graphics,
|
33
|
+
# Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
34
|
+
#
|
35
|
+
# OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
36
|
+
#
|
37
|
+
# model.c
|
38
|
+
# This program demonstrates modeling transformations
|
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
|
+
def draw_triangle
|
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()
|
54
|
+
end
|
55
|
+
|
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
|
83
|
+
|
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
|
95
|
+
|
96
|
+
keyboard = Proc.new do |key, x, y|
|
97
|
+
case key
|
98
|
+
when ?\e
|
99
|
+
exit(0)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
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()
|
@@ -0,0 +1,132 @@
|
|
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 'rational'
|
53
|
+
require 'mathn'
|
54
|
+
include Gl,Glu,Glut
|
55
|
+
|
56
|
+
$spin = 0
|
57
|
+
|
58
|
+
# Initialize material property, light source, lighting model,
|
59
|
+
# and depth buffer.
|
60
|
+
def init
|
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)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Here is where the light position is reset after the modeling
|
69
|
+
# transformation (glRotated) is called. This places the
|
70
|
+
# light at a new position in world coordinates. The cube
|
71
|
+
# represents the position of the light.
|
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
|
94
|
+
|
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
|
103
|
+
|
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
|
113
|
+
|
114
|
+
keyboard = Proc.new do |key, x, y|
|
115
|
+
case key
|
116
|
+
when ?\e
|
117
|
+
exit(0)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
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()
|
@@ -0,0 +1,179 @@
|
|
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
|
+
include Gl,Glu,Glut
|
50
|
+
|
51
|
+
def myinit
|
52
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
53
|
+
glDepthFunc(GL_LESS)
|
54
|
+
glEnable(GL_DEPTH_TEST)
|
55
|
+
glShadeModel(GL_FLAT)
|
56
|
+
glDepthRange(0.0, 1.0) #/* The default z mapping */
|
57
|
+
end
|
58
|
+
|
59
|
+
# The three rectangles are drawn. In selection mode,
|
60
|
+
# each rectangle is given the same name. Note that
|
61
|
+
# each rectangle is drawn with a different z value.
|
62
|
+
def drawRects(mode)
|
63
|
+
if (mode == GL_SELECT)
|
64
|
+
glLoadName(1)
|
65
|
+
end
|
66
|
+
glBegin(GL_QUADS)
|
67
|
+
glColor(1.0, 1.0, 0.0)
|
68
|
+
glVertex(2, 0, 0)
|
69
|
+
glVertex(2, 6, 0)
|
70
|
+
glVertex(6, 6, 0)
|
71
|
+
glVertex(6, 0, 0)
|
72
|
+
glEnd()
|
73
|
+
if (mode == GL_SELECT)
|
74
|
+
glLoadName(2)
|
75
|
+
end
|
76
|
+
glBegin(GL_QUADS)
|
77
|
+
glColor(0.0, 1.0, 1.0)
|
78
|
+
glVertex(3, 2, -1)
|
79
|
+
glVertex(3, 8, -1)
|
80
|
+
glVertex(8, 8, -1)
|
81
|
+
glVertex(8, 2, -1)
|
82
|
+
glEnd()
|
83
|
+
if (mode == GL_SELECT)
|
84
|
+
glLoadName(3)
|
85
|
+
end
|
86
|
+
glBegin(GL_QUADS)
|
87
|
+
glColor(1.0, 0.0, 1.0)
|
88
|
+
glVertex(0, 2, -2)
|
89
|
+
glVertex(0, 7, -2)
|
90
|
+
glVertex(5, 7, -2)
|
91
|
+
glVertex(5, 2, -2)
|
92
|
+
glEnd()
|
93
|
+
end
|
94
|
+
|
95
|
+
# processHits() prints out the contents of the
|
96
|
+
# selection array.
|
97
|
+
def processHits(hits, buffer)
|
98
|
+
printf("hits = %d\n", hits)
|
99
|
+
ptr = buffer.unpack("I*")
|
100
|
+
p = 0
|
101
|
+
for i in 0...hits # for each hit
|
102
|
+
names = ptr[p]
|
103
|
+
printf(" number of names for hit = %d\n", names); p+=1
|
104
|
+
printf(" z1 is %g", ptr[p].to_f/0xffffffff); p+=1
|
105
|
+
printf(" z2 is %g\n", ptr[p].to_f/0xffffffff); p+=1
|
106
|
+
printf(" the name is ")
|
107
|
+
for j in 0...names # for each name
|
108
|
+
printf("%d ", ptr[p]) ; p+=1
|
109
|
+
end
|
110
|
+
printf("\n")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# pickRects() sets up selection mode, name stack,
|
115
|
+
# and projection matrix for picking. Then the objects
|
116
|
+
# are drawn.
|
117
|
+
BUFSIZE=512
|
118
|
+
|
119
|
+
pickRects = proc do |button, state, x, y|
|
120
|
+
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
|
121
|
+
viewport = glGetDoublev(GL_VIEWPORT)
|
122
|
+
|
123
|
+
selectBuf = glSelectBuffer(BUFSIZE)
|
124
|
+
glRenderMode(GL_SELECT)
|
125
|
+
|
126
|
+
glInitNames()
|
127
|
+
glPushName(~0)
|
128
|
+
|
129
|
+
glMatrixMode(GL_PROJECTION)
|
130
|
+
glPushMatrix()
|
131
|
+
glLoadIdentity()
|
132
|
+
# create 5x5 pixel picking region near cursor location
|
133
|
+
gluPickMatrix( x, viewport[3] - y, 5.0, 5.0, viewport)
|
134
|
+
glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
|
135
|
+
drawRects(GL_SELECT)
|
136
|
+
glPopMatrix()
|
137
|
+
glFlush()
|
138
|
+
|
139
|
+
hits = glRenderMode(GL_RENDER)
|
140
|
+
processHits(hits, selectBuf)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
display = proc do
|
145
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
146
|
+
drawRects(GL_RENDER)
|
147
|
+
glutSwapBuffers()
|
148
|
+
end
|
149
|
+
|
150
|
+
myReshape = proc do |w, h|
|
151
|
+
glViewport(0, 0, w, h)
|
152
|
+
glMatrixMode(GL_PROJECTION)
|
153
|
+
glLoadIdentity()
|
154
|
+
glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5)
|
155
|
+
glMatrixMode(GL_MODELVIEW)
|
156
|
+
glLoadIdentity()
|
157
|
+
end
|
158
|
+
|
159
|
+
keyboard = Proc.new do |key, x, y|
|
160
|
+
case (key)
|
161
|
+
when ?\e
|
162
|
+
exit(0)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Main Loop
|
167
|
+
# Open window with initial window size, title bar,
|
168
|
+
# RGBA display mode, depth buffer, and handle input events.
|
169
|
+
glutInitWindowSize(500, 500)
|
170
|
+
glutInitWindowPosition(100, 100)
|
171
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
172
|
+
glutInit()
|
173
|
+
glutCreateWindow()
|
174
|
+
myinit()
|
175
|
+
glutMouseFunc(pickRects)
|
176
|
+
glutReshapeFunc(myReshape)
|
177
|
+
glutDisplayFunc(display)
|
178
|
+
glutKeyboardFunc(keyboard)
|
179
|
+
glutMainLoop()
|