ruby-opengl2 0.60.2
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 +80 -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 +423 -0
- data/ext/common/conv.h +243 -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 +63 -0
- data/ext/common/glu-enums.h +463 -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 +214 -0
- data/ext/gl/mkrf_conf.rb +37 -0
- data/ext/glu/glu-enums.c +164 -0
- data/ext/glu/glu.c +1530 -0
- data/ext/glu/mkrf_conf.rb +39 -0
- data/ext/glut/glut.c +1627 -0
- data/ext/glut/mkrf_conf.rb +37 -0
- data/lib/opengl.rb +84 -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
- metadata +164 -0
@@ -0,0 +1,205 @@
|
|
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
|
+
# dof.c
|
40
|
+
# This program demonstrates use of the accumulation buffer to
|
41
|
+
# create an out-of-focus depth-of-field effect. The teapots
|
42
|
+
# are drawn several times into the accumulation buffer. The
|
43
|
+
# viewing volume is jittered, except at the focal point, where
|
44
|
+
# the viewing volume is at the same position, each time. In
|
45
|
+
# this case, the gold teapot remains in focus.
|
46
|
+
require 'opengl'
|
47
|
+
require 'jitter'
|
48
|
+
include Gl,Glu,Glut
|
49
|
+
|
50
|
+
# accFrustum()
|
51
|
+
# The first 6 arguments are identical to the glFrustum() call.
|
52
|
+
#
|
53
|
+
# pixdx and pixdy are anti-alias jitter in pixels.
|
54
|
+
# Set both equal to 0.0 for no anti-alias jitter.
|
55
|
+
# eyedx and eyedy are depth-of field jitter in pixels.
|
56
|
+
# Set both equal to 0.0 for no depth of field effects.
|
57
|
+
#
|
58
|
+
# focus is distance from eye to plane in focus.
|
59
|
+
# focus must be greater than, but not equal to 0.0.
|
60
|
+
#
|
61
|
+
# Note that accFrustum() calls glTranslatef(). You will
|
62
|
+
# probably want to insure that your ModelView matrix has been
|
63
|
+
# initialized to identity before calling accFrustum().
|
64
|
+
def accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
|
65
|
+
viewport = glGetDoublev(GL_VIEWPORT)
|
66
|
+
|
67
|
+
xwsize = right - left
|
68
|
+
ywsize = top - bottom
|
69
|
+
|
70
|
+
dx = -(pixdx*xwsize/viewport[2] + eyedx*nnear/focus)
|
71
|
+
dy = -(pixdy*ywsize/viewport[3] + eyedy*nnear/focus)
|
72
|
+
|
73
|
+
glMatrixMode(GL_PROJECTION)
|
74
|
+
glLoadIdentity()
|
75
|
+
glFrustum(left + dx, right + dx, bottom + dy, top + dy, nnear, ffar)
|
76
|
+
glMatrixMode(GL_MODELVIEW)
|
77
|
+
glLoadIdentity()
|
78
|
+
glTranslate(-eyedx, -eyedy, 0.0)
|
79
|
+
end
|
80
|
+
|
81
|
+
# accPerspective()
|
82
|
+
#
|
83
|
+
# The first 4 arguments are identical to the gluPerspective() call.
|
84
|
+
# pixdx and pixdy are anti-alias jitter in pixels.
|
85
|
+
# Set both equal to 0.0 for no anti-alias jitter.
|
86
|
+
# eyedx and eyedy are depth-of field jitter in pixels.
|
87
|
+
# Set both equal to 0.0 for no depth of field effects.
|
88
|
+
#
|
89
|
+
# focus is distance from eye to plane in focus.
|
90
|
+
# focus must be greater than, but not equal to 0.0.
|
91
|
+
#
|
92
|
+
# Note that accPerspective() calls accFrustum().
|
93
|
+
def accPerspective(fovy, aspect, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
|
94
|
+
fov2 = ((fovy*Math::PI) / 180.0) / 2.0
|
95
|
+
|
96
|
+
top = nnear / (Math::cos(fov2) / Math::sin(fov2))
|
97
|
+
bottom = -top
|
98
|
+
|
99
|
+
right = top * aspect
|
100
|
+
left = -right
|
101
|
+
|
102
|
+
accFrustum(left, right, bottom, top, nnear, ffar, pixdx, pixdy, eyedx, eyedy, focus)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def myinit
|
107
|
+
ambient = [ 0.0, 0.0, 0.0, 1.0 ]
|
108
|
+
diffuse = [ 1.0, 1.0, 1.0, 1.0 ]
|
109
|
+
position = [ 0.0, 3.0, 3.0, 0.0 ]
|
110
|
+
|
111
|
+
lmodel_ambient = [ 0.2, 0.2, 0.2, 1.0 ]
|
112
|
+
local_view = [ 0.0 ]
|
113
|
+
|
114
|
+
glEnable(GL_DEPTH_TEST)
|
115
|
+
glDepthFunc(GL_LESS)
|
116
|
+
|
117
|
+
glLight(GL_LIGHT0, GL_AMBIENT, ambient)
|
118
|
+
glLight(GL_LIGHT0, GL_DIFFUSE, diffuse)
|
119
|
+
glLight(GL_LIGHT0, GL_POSITION, position)
|
120
|
+
|
121
|
+
glLightModel(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient)
|
122
|
+
glLightModel(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view)
|
123
|
+
|
124
|
+
glFrontFace(GL_CW)
|
125
|
+
glEnable(GL_LIGHTING)
|
126
|
+
glEnable(GL_LIGHT0)
|
127
|
+
glEnable(GL_AUTO_NORMAL)
|
128
|
+
glEnable(GL_NORMALIZE)
|
129
|
+
|
130
|
+
glMatrixMode(GL_MODELVIEW)
|
131
|
+
glLoadIdentity()
|
132
|
+
|
133
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
134
|
+
glClearAccum(0.0, 0.0, 0.0, 0.0)
|
135
|
+
end
|
136
|
+
|
137
|
+
def renderTeapot (x, y, z, ambr, ambg, ambb, difr, difg, difb, specr, specg, specb, shine)
|
138
|
+
glPushMatrix()
|
139
|
+
glTranslate(x, y, z)
|
140
|
+
mat = []
|
141
|
+
mat[0] = ambr; mat[1] = ambg; mat[2] = ambb; mat[3] = 1.0
|
142
|
+
glMaterial(GL_FRONT, GL_AMBIENT, mat)
|
143
|
+
mat[0] = difr; mat[1] = difg; mat[2] = difb
|
144
|
+
glMaterial(GL_FRONT, GL_DIFFUSE, mat)
|
145
|
+
mat[0] = specr; mat[1] = specg; mat[2] = specb
|
146
|
+
glMaterial(GL_FRONT, GL_SPECULAR, mat)
|
147
|
+
glMaterial(GL_FRONT, GL_SHININESS, shine*128.0)
|
148
|
+
glutSolidTeapot(0.5)
|
149
|
+
glPopMatrix()
|
150
|
+
end
|
151
|
+
|
152
|
+
# display() draws 5 teapots into the accumulation buffer
|
153
|
+
# several times each time with a jittered perspective.
|
154
|
+
# The focal point is at z = 5.0, so the gold teapot will
|
155
|
+
# stay in focus. The amount of jitter is adjusted by the
|
156
|
+
# magnitude of the accPerspective() jitter in this example, 0.33.
|
157
|
+
# In this example, the teapots are drawn 8 times. See jitter.rb
|
158
|
+
display = proc do
|
159
|
+
viewport = glGetDoublev(GL_VIEWPORT)
|
160
|
+
glClear(GL_ACCUM_BUFFER_BIT)
|
161
|
+
|
162
|
+
for jitter in 0...8
|
163
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
164
|
+
accPerspective(45.0,
|
165
|
+
viewport[2]/ viewport[3],
|
166
|
+
1.0, 15.0, 0.0, 0.0,
|
167
|
+
0.33*$j8[jitter][0], 0.33*$j8[jitter][1], 5.0)
|
168
|
+
# ruby, gold, silver, emerald, and cyan teapots
|
169
|
+
renderTeapot(-1.1, -0.5, -4.5, 0.1745, 0.01175, 0.01175, 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6)
|
170
|
+
renderTeapot(-0.5, -0.5, -5.0, 0.24725, 0.1995, 0.0745, 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4)
|
171
|
+
renderTeapot(0.2, -0.5, -5.5, 0.19225, 0.19225, 0.19225, 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4)
|
172
|
+
renderTeapot(1.0, -0.5, -6.0, 0.0215, 0.1745, 0.0215, 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6)
|
173
|
+
renderTeapot(1.8, -0.5, -6.5, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392, 0.50196078, 0.50196078, 0.50196078, 0.25)
|
174
|
+
glAccum(GL_ACCUM, 0.125)
|
175
|
+
end
|
176
|
+
|
177
|
+
glAccum(GL_RETURN, 1.0)
|
178
|
+
glutSwapBuffers()
|
179
|
+
end
|
180
|
+
|
181
|
+
myReshape = proc do |w, h|
|
182
|
+
glViewport(0, 0, w, h)
|
183
|
+
end
|
184
|
+
|
185
|
+
keyboard = proc do |key, x, y|
|
186
|
+
case (key)
|
187
|
+
when ?\e
|
188
|
+
exit(0)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Main Loop
|
193
|
+
# Open window with initial window size, title bar,
|
194
|
+
# RGBA display mode, depth buffer, and handle input events.
|
195
|
+
glutInit()
|
196
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_ACCUM | GLUT_DEPTH)
|
197
|
+
glutInitWindowSize(500, 500)
|
198
|
+
glutInitWindowPosition(100, 100)
|
199
|
+
glutCreateWindow()
|
200
|
+
myinit()
|
201
|
+
glutReshapeFunc(myReshape)
|
202
|
+
glutDisplayFunc(display)
|
203
|
+
glutKeyboardFunc(keyboard)
|
204
|
+
glutMainLoop()
|
205
|
+
|
@@ -0,0 +1,105 @@
|
|
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
|
+
# double.c
|
38
|
+
# This is a simple double buffered program.
|
39
|
+
# Pressing the left mouse button rotates the rectangle.
|
40
|
+
# Pressing the middle mouse button stops the rotation.
|
41
|
+
require 'opengl'
|
42
|
+
require 'rational'
|
43
|
+
include Gl,Glu,Glut
|
44
|
+
|
45
|
+
$spin = 0.0
|
46
|
+
|
47
|
+
display = Proc.new do
|
48
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
49
|
+
glPushMatrix()
|
50
|
+
glRotate($spin, 0.0, 0.0, 1.0)
|
51
|
+
glColor(1.0, 1.0, 1.0)
|
52
|
+
glRect(-25.0, -25.0, 25.0, 25.0)
|
53
|
+
glPopMatrix()
|
54
|
+
glutSwapBuffers()
|
55
|
+
end
|
56
|
+
|
57
|
+
$spinDisplay = Proc.new do
|
58
|
+
$spin = $spin + 4.0
|
59
|
+
$spin = $spin - 360.0 if ($spin > 360.0)
|
60
|
+
glutPostRedisplay()
|
61
|
+
end
|
62
|
+
|
63
|
+
def init
|
64
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
65
|
+
glShadeModel(GL_FLAT)
|
66
|
+
end
|
67
|
+
|
68
|
+
reshape = Proc.new do |w, h|
|
69
|
+
glViewport(0, 0, w, h)
|
70
|
+
glMatrixMode(GL_PROJECTION)
|
71
|
+
glLoadIdentity()
|
72
|
+
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0)
|
73
|
+
glMatrixMode(GL_MODELVIEW)
|
74
|
+
glLoadIdentity()
|
75
|
+
end
|
76
|
+
|
77
|
+
mouse = Proc.new do |button, state, x, y|
|
78
|
+
case button
|
79
|
+
when GLUT_LEFT_BUTTON
|
80
|
+
glutIdleFunc($spinDisplay) if (state == GLUT_DOWN)
|
81
|
+
when GLUT_MIDDLE_BUTTON
|
82
|
+
glutIdleFunc(nil) if (state == GLUT_DOWN)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
keyboard = Proc.new do |key, x, y|
|
87
|
+
case (key)
|
88
|
+
when ?\e
|
89
|
+
exit(0)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Request double buffer display mode.
|
94
|
+
# Register mouse input callback functions
|
95
|
+
glutInit
|
96
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
97
|
+
glutInitWindowSize(500, 500)
|
98
|
+
glutInitWindowPosition(100, 100)
|
99
|
+
glutCreateWindow($0)
|
100
|
+
init()
|
101
|
+
glutDisplayFunc(display)
|
102
|
+
glutReshapeFunc(reshape)
|
103
|
+
glutKeyboardFunc(keyboard)
|
104
|
+
glutMouseFunc(mouse)
|
105
|
+
glutMainLoop()
|
@@ -0,0 +1,91 @@
|
|
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
|
+
# drawf.c
|
38
|
+
# Draws the bitmapped letter F on the screen (several times).
|
39
|
+
# This demonstrates use of the glBitmap() call.
|
40
|
+
require 'opengl'
|
41
|
+
include Gl,Glu,Glut
|
42
|
+
|
43
|
+
$rasters = [
|
44
|
+
0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
|
45
|
+
0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
|
46
|
+
0xff, 0xc0, 0xff, 0xc0
|
47
|
+
].pack("C*")
|
48
|
+
|
49
|
+
def init
|
50
|
+
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
|
51
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
52
|
+
end
|
53
|
+
|
54
|
+
display = Proc.new do
|
55
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
56
|
+
glColor(1.0, 1.0, 1.0)
|
57
|
+
glRasterPos2i(20, 20)
|
58
|
+
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters)
|
59
|
+
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters)
|
60
|
+
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, $rasters)
|
61
|
+
glutSwapBuffers()
|
62
|
+
end
|
63
|
+
|
64
|
+
reshape = Proc.new do |w, h|
|
65
|
+
glViewport(0, 0, w, h)
|
66
|
+
glMatrixMode(GL_PROJECTION)
|
67
|
+
glLoadIdentity()
|
68
|
+
glOrtho(0, w, 0, h, -1.0, 1.0)
|
69
|
+
glMatrixMode(GL_MODELVIEW)
|
70
|
+
end
|
71
|
+
|
72
|
+
keyboard = Proc.new do |key, x, y|
|
73
|
+
case (key)
|
74
|
+
when ?\e
|
75
|
+
exit(0)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Main Loop
|
80
|
+
# Open window with initial window size, title bar,
|
81
|
+
# RGBA display mode, and handle input events.
|
82
|
+
glutInit
|
83
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
84
|
+
glutInitWindowSize(100, 100)
|
85
|
+
glutInitWindowPosition(100, 100)
|
86
|
+
glutCreateWindow($0)
|
87
|
+
init()
|
88
|
+
glutReshapeFunc(reshape)
|
89
|
+
glutKeyboardFunc(keyboard)
|
90
|
+
glutDisplayFunc(display)
|
91
|
+
glutMainLoop()
|
@@ -0,0 +1,145 @@
|
|
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
|
+
# feedback.c
|
38
|
+
# This program demonstrates use of OpenGL feedback. First,
|
39
|
+
# a lighting environment is set up and a few lines are drawn.
|
40
|
+
# Then feedback mode is entered, and the same lines are
|
41
|
+
# drawn. The results in the feedback buffer are printed.
|
42
|
+
require 'opengl'
|
43
|
+
include Gl,Glu,Glut
|
44
|
+
|
45
|
+
# Initialize lighting.
|
46
|
+
def init
|
47
|
+
glEnable(GL_LIGHTING)
|
48
|
+
glEnable(GL_LIGHT0)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Draw a few lines and two points, one of which will
|
52
|
+
# be clipped. If in feedback mode, a passthrough token
|
53
|
+
# is issued between the each primitive.
|
54
|
+
def drawGeometry(mode)
|
55
|
+
glBegin(GL_LINE_STRIP)
|
56
|
+
glNormal(0.0, 0.0, 1.0)
|
57
|
+
glVertex(30.0, 30.0, 0.0)
|
58
|
+
glVertex(50.0, 60.0, 0.0)
|
59
|
+
glVertex(70.0, 40.0, 0.0)
|
60
|
+
glEnd()
|
61
|
+
if (mode == GL_FEEDBACK)
|
62
|
+
glPassThrough(1.0)
|
63
|
+
end
|
64
|
+
glBegin(GL_POINTS)
|
65
|
+
glVertex(-100.0, -100.0, -100.0) # will be clipped
|
66
|
+
glEnd()
|
67
|
+
if (mode == GL_FEEDBACK)
|
68
|
+
glPassThrough(2.0)
|
69
|
+
end
|
70
|
+
glBegin(GL_POINTS)
|
71
|
+
glNormal(0.0, 0.0, 1.0)
|
72
|
+
glVertex(50.0, 50.0, 0.0)
|
73
|
+
glEnd()
|
74
|
+
end
|
75
|
+
|
76
|
+
# Write contents of one vertex to stdout.
|
77
|
+
def print3DcolorVertex(size, count, buffer)
|
78
|
+
printf(" ")
|
79
|
+
for i in 0...7
|
80
|
+
printf("%4.2f ", buffer[size-count])
|
81
|
+
count -= 1
|
82
|
+
end
|
83
|
+
printf("\n")
|
84
|
+
return count
|
85
|
+
end
|
86
|
+
|
87
|
+
# Write contents of entire buffer. (Parse tokens!)
|
88
|
+
def printBuffer(size, buffer)
|
89
|
+
count = size
|
90
|
+
while (count!=0)
|
91
|
+
token = buffer[size-count]
|
92
|
+
count-=1
|
93
|
+
if (token == GL_PASS_THROUGH_TOKEN)
|
94
|
+
printf("GL_PASS_THROUGH_TOKEN\n")
|
95
|
+
printf(" %4.2f\n", buffer[size-count])
|
96
|
+
count-=1
|
97
|
+
elsif (token == GL_POINT_TOKEN)
|
98
|
+
printf("GL_POINT_TOKEN\n")
|
99
|
+
count = print3DcolorVertex(size, count, buffer)
|
100
|
+
elsif (token == GL_LINE_TOKEN)
|
101
|
+
printf("GL_LINE_TOKEN\n")
|
102
|
+
count = print3DcolorVertex(size, count, buffer)
|
103
|
+
count = print3DcolorVertex(size, count, buffer)
|
104
|
+
elsif (token == GL_LINE_RESET_TOKEN)
|
105
|
+
printf("GL_LINE_RESET_TOKEN\n")
|
106
|
+
count = print3DcolorVertex(size, count, buffer)
|
107
|
+
count = print3DcolorVertex(size, count, buffer)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
display = proc do
|
113
|
+
glMatrixMode(GL_PROJECTION)
|
114
|
+
glLoadIdentity()
|
115
|
+
glOrtho(0.0, 100.0, 0.0, 100.0, 0.0, 1.0)
|
116
|
+
|
117
|
+
glClearColor(0.0, 0.0, 0.0, 0.0)
|
118
|
+
glClear(GL_COLOR_BUFFER_BIT)
|
119
|
+
drawGeometry(GL_RENDER)
|
120
|
+
|
121
|
+
feedBuffer = glFeedbackBuffer(1024, GL_3D_COLOR)
|
122
|
+
glRenderMode(GL_FEEDBACK)
|
123
|
+
drawGeometry(GL_FEEDBACK)
|
124
|
+
|
125
|
+
size = glRenderMode(GL_RENDER)
|
126
|
+
printBuffer(size, feedBuffer.unpack("f#{size}"))
|
127
|
+
glutSwapBuffers()
|
128
|
+
end
|
129
|
+
|
130
|
+
keyboard = proc do |key, x, y|
|
131
|
+
case (key)
|
132
|
+
when ?\e
|
133
|
+
exit(0)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
glutInit()
|
138
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
|
139
|
+
glutInitWindowSize(100, 100)
|
140
|
+
glutInitWindowPosition(100, 100)
|
141
|
+
glutCreateWindow()
|
142
|
+
init()
|
143
|
+
glutDisplayFunc(display)
|
144
|
+
glutKeyboardFunc(keyboard)
|
145
|
+
glutMainLoop()
|