ruby-opengl 0.40.1 → 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,33 @@
|
|
1
|
+
Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions
|
6
|
+
are met:
|
7
|
+
|
8
|
+
Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
Redistributions in binary form must reproduce the above
|
12
|
+
copyright notice, this list of conditions and the following
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
14
|
+
with the distribution.
|
15
|
+
|
16
|
+
Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived
|
18
|
+
from this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
//
|
2
|
+
// Fragment shader for procedural bricks
|
3
|
+
//
|
4
|
+
// Authors: Dave Baldwin, Steve Koren, Randi Rost
|
5
|
+
// based on a shader by Darwyn Peachey
|
6
|
+
//
|
7
|
+
// Copyright (c) 2002-2004 3Dlabs Inc. Ltd.
|
8
|
+
//
|
9
|
+
// See 3Dlabs-License.txt for license information
|
10
|
+
//
|
11
|
+
|
12
|
+
uniform vec3 BrickColor, MortarColor;
|
13
|
+
uniform vec2 BrickSize;
|
14
|
+
uniform vec2 BrickPct;
|
15
|
+
|
16
|
+
varying vec2 MCposition;
|
17
|
+
varying float LightIntensity;
|
18
|
+
|
19
|
+
void main(void)
|
20
|
+
{
|
21
|
+
vec3 color;
|
22
|
+
vec2 position, useBrick;
|
23
|
+
|
24
|
+
position = MCposition / BrickSize;
|
25
|
+
|
26
|
+
if (fract(position.y * 0.5) > 0.5)
|
27
|
+
position.x += 0.5;
|
28
|
+
|
29
|
+
position = fract(position);
|
30
|
+
|
31
|
+
useBrick = step(position, BrickPct);
|
32
|
+
|
33
|
+
color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y);
|
34
|
+
color *= LightIntensity;
|
35
|
+
gl_FragColor = vec4 (color, 1.0);
|
36
|
+
}
|
@@ -0,0 +1,388 @@
|
|
1
|
+
# Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above
|
12
|
+
# copyright notice, this list of conditions and the following
|
13
|
+
# disclaimer in the documentation and/or other materials provided
|
14
|
+
# with the distribution.
|
15
|
+
#
|
16
|
+
# Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
17
|
+
# contributors may be used to endorse or promote products derived
|
18
|
+
# from this software without specific prior written permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
# ===========================================================================
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# The source of the shaders itself are in plain text files. Files ending in
|
36
|
+
# .vert are vertex shaders, and files ending in .frag are fragment shaders.
|
37
|
+
|
38
|
+
require 'opengl'
|
39
|
+
include Gl,Glu,Glut
|
40
|
+
|
41
|
+
$rotl = 1 * Math::PI / 180
|
42
|
+
$last_time = 0
|
43
|
+
|
44
|
+
$fXDiff = 206
|
45
|
+
$fYDiff = 16
|
46
|
+
$fZDiff = 10
|
47
|
+
$xLastIncr = 0
|
48
|
+
$yLastIncr = 0
|
49
|
+
$fXInertia = -0.5
|
50
|
+
$fYInertia = 0
|
51
|
+
$fXInertiaOld = 0
|
52
|
+
$fYInertiaOld = 0
|
53
|
+
$fScale = 1.0
|
54
|
+
$ftime = 0
|
55
|
+
$xLast = -1
|
56
|
+
$yLast = -1
|
57
|
+
$bmModifiers = 0
|
58
|
+
$rotate = true
|
59
|
+
|
60
|
+
INERTIA_THRESHOLD = 1.0
|
61
|
+
INERTIA_FACTOR = 0.5
|
62
|
+
SCALE_FACTOR = 0.01
|
63
|
+
SCALE_INCREMENT = 0.5
|
64
|
+
TIMER_FREQUENCY_MILLIS = 20
|
65
|
+
|
66
|
+
|
67
|
+
$gleModel = [:cube, :teapot,:torus,:sphere]
|
68
|
+
$clearColor = [[0,0,0,1], [0.2,0.2,0.3,1], [0.7,0.7,0.7,1]]
|
69
|
+
|
70
|
+
def drawCube
|
71
|
+
size = 1.0
|
72
|
+
scale = 0.2
|
73
|
+
delta = 0.1
|
74
|
+
|
75
|
+
v = [
|
76
|
+
[ size, size, size * scale + delta ],
|
77
|
+
[ size, size, -size * scale + delta ],
|
78
|
+
[ size, -size, -size * scale ],
|
79
|
+
[ size, -size, size * scale ],
|
80
|
+
[-size, size, size * scale + delta ],
|
81
|
+
[-size, size, -size * scale + delta ],
|
82
|
+
[-size, -size, -size * scale ],
|
83
|
+
[-size, -size, size * scale ]
|
84
|
+
]
|
85
|
+
|
86
|
+
cube = [
|
87
|
+
[ [1,0,0], v[3],v[2],v[1],v[0] ], # normal, vertices
|
88
|
+
[ [-1,0,0], v[6],v[7],v[4],v[5] ],
|
89
|
+
[ [0,0,-1], v[2],v[6],v[5],v[1] ],
|
90
|
+
[ [0,0,1], v[7],v[3],v[0],v[4] ],
|
91
|
+
[ [0,1,0], v[4],v[0],v[1],v[5] ],
|
92
|
+
[ [0,-1,0], v[6],v[2],v[3],v[7] ]
|
93
|
+
]
|
94
|
+
|
95
|
+
glBegin(GL_QUADS)
|
96
|
+
cube.each do |side|
|
97
|
+
glNormal3fv(side[0])
|
98
|
+
|
99
|
+
glTexCoord2f(1,1)
|
100
|
+
glVertex3fv(side[1])
|
101
|
+
glTexCoord2f(0,1)
|
102
|
+
glVertex3fv(side[2])
|
103
|
+
glTexCoord2f(0,0)
|
104
|
+
glVertex3fv(side[3])
|
105
|
+
glTexCoord2f(1,0)
|
106
|
+
glVertex3fv(side[4])
|
107
|
+
end
|
108
|
+
glEnd()
|
109
|
+
end
|
110
|
+
|
111
|
+
def nextClearColor
|
112
|
+
glClearColor($clearColor[0][0],
|
113
|
+
$clearColor[0][1],
|
114
|
+
$clearColor[0][2],
|
115
|
+
$clearColor[0][3])
|
116
|
+
$clearColor << $clearColor.shift # rotate
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
play = lambda do
|
121
|
+
this_time = glutGet(GLUT_ELAPSED_TIME)
|
122
|
+
|
123
|
+
$rotl+=(this_time - $last_time) * -0.001
|
124
|
+
$last_time = this_time
|
125
|
+
|
126
|
+
glutPostRedisplay()
|
127
|
+
end
|
128
|
+
|
129
|
+
display = lambda do
|
130
|
+
glLoadIdentity()
|
131
|
+
glTranslatef(0.0, 0.0, -5.0)
|
132
|
+
|
133
|
+
glRotatef($fYDiff, 1,0,0)
|
134
|
+
glRotatef($fXDiff, 0,1,0)
|
135
|
+
glRotatef($fZDiff, 0,0,1)
|
136
|
+
|
137
|
+
glScalef($fScale, $fScale, $fScale)
|
138
|
+
|
139
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
140
|
+
|
141
|
+
case $gleModel[0]
|
142
|
+
when :teapot :
|
143
|
+
glutSolidTeapot(0.6)
|
144
|
+
when :torus :
|
145
|
+
glutSolidTorus(0.2, 0.6, 64, 64)
|
146
|
+
when :sphere :
|
147
|
+
glutSolidSphere(0.6, 64, 64)
|
148
|
+
when :cube :
|
149
|
+
drawCube()
|
150
|
+
end
|
151
|
+
glFlush()
|
152
|
+
glutSwapBuffers()
|
153
|
+
end
|
154
|
+
|
155
|
+
key = lambda do |key,x,y|
|
156
|
+
case(key)
|
157
|
+
when ?b
|
158
|
+
nextClearColor()
|
159
|
+
when ?q, 27 # esc
|
160
|
+
exit(0)
|
161
|
+
when ?t
|
162
|
+
$gleModel << $gleModel.shift # rotate the array
|
163
|
+
when 32 # spacebar
|
164
|
+
$rotate = !$rotate
|
165
|
+
|
166
|
+
if ($rotate==false)
|
167
|
+
$fXInertiaOld = $fXInertia
|
168
|
+
$fYInertiaOld = $fYInertia
|
169
|
+
else
|
170
|
+
$fXInertia = $fXInertiaOld
|
171
|
+
$fYInertia = $fYInertiaOld
|
172
|
+
|
173
|
+
# To prevent confusion, force some rotation
|
174
|
+
if ($fXInertia == 0 && $fYInertia == 0)
|
175
|
+
$fXInertia = -0.5
|
176
|
+
end
|
177
|
+
end
|
178
|
+
when ?+
|
179
|
+
$fScale += SCALE_INCREMENT
|
180
|
+
when ?-
|
181
|
+
$fScale -= SCALE_INCREMENT
|
182
|
+
else
|
183
|
+
puts "Keyboard commands:\n"
|
184
|
+
puts "b - Toggle among background clear colors"
|
185
|
+
puts "q, <esc> - Quit"
|
186
|
+
puts "t - Toggle among models to render"
|
187
|
+
puts "? - Help"
|
188
|
+
puts "<home> - reset zoom and rotation"
|
189
|
+
puts "<space> or <click> - stop rotation"
|
190
|
+
puts "<+>, <-> or <ctrl + drag> - zoom model"
|
191
|
+
puts "<arrow keys> or <drag> - rotate model\n"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
reshape = lambda do |w,h|
|
196
|
+
vp = 0.8
|
197
|
+
aspect = w.to_f/h.to_f
|
198
|
+
|
199
|
+
glViewport(0, 0, w, h)
|
200
|
+
glMatrixMode(GL_PROJECTION)
|
201
|
+
glLoadIdentity()
|
202
|
+
|
203
|
+
glFrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10)
|
204
|
+
|
205
|
+
glMatrixMode(GL_MODELVIEW)
|
206
|
+
glLoadIdentity()
|
207
|
+
glTranslatef(0.0, 0.0, -5.0)
|
208
|
+
end
|
209
|
+
|
210
|
+
motion = lambda do |x,y|
|
211
|
+
if ($xLast != -1 || $yLast != -1)
|
212
|
+
$xLastIncr = x - $xLast
|
213
|
+
$yLastIncr = y - $yLast
|
214
|
+
if ($bmModifiers & GLUT_ACTIVE_CTRL != 0)
|
215
|
+
if ($xLast != -1)
|
216
|
+
$fZDiff += $xLastIncr
|
217
|
+
$fScale += $yLastIncr*SCALE_FACTOR
|
218
|
+
end
|
219
|
+
else
|
220
|
+
if ($xLast != -1)
|
221
|
+
$fXDiff += $xLastIncr
|
222
|
+
$fYDiff += $yLastIncr
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
$xLast = x
|
227
|
+
$yLast = y
|
228
|
+
end
|
229
|
+
|
230
|
+
mouse = lambda do |button,state,x,y|
|
231
|
+
$bmModifiers = glutGetModifiers()
|
232
|
+
if (button == GLUT_LEFT_BUTTON)
|
233
|
+
if (state == GLUT_UP)
|
234
|
+
$xLast = -1
|
235
|
+
$yLast = -1
|
236
|
+
if $xLastIncr > INERTIA_THRESHOLD
|
237
|
+
$fXInertia = ($xLastIncr - INERTIA_THRESHOLD)*INERTIA_FACTOR
|
238
|
+
end
|
239
|
+
if -$xLastIncr > INERTIA_THRESHOLD
|
240
|
+
$fXInertia = ($xLastIncr + INERTIA_THRESHOLD)*INERTIA_FACTOR
|
241
|
+
end
|
242
|
+
|
243
|
+
if $yLastIncr > INERTIA_THRESHOLD
|
244
|
+
$fYInertia = ($yLastIncr - INERTIA_THRESHOLD)*INERTIA_FACTOR
|
245
|
+
end
|
246
|
+
if -$yLastIncr > INERTIA_THRESHOLD
|
247
|
+
$fYInertia = ($yLastIncr + INERTIA_THRESHOLD)*INERTIA_FACTOR
|
248
|
+
end
|
249
|
+
else
|
250
|
+
$fXInertia = 0
|
251
|
+
$fYInertia = 0
|
252
|
+
end
|
253
|
+
$xLastIncr = 0
|
254
|
+
$yLastIncr = 0
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
special = lambda do |key,x,y|
|
259
|
+
case key
|
260
|
+
when GLUT_KEY_HOME:
|
261
|
+
$fXDiff = 0
|
262
|
+
$fYDiff = 35
|
263
|
+
$fZDiff = 0
|
264
|
+
$xLastIncr = 0
|
265
|
+
$yLastIncr = 0
|
266
|
+
$fXInertia = -0.5
|
267
|
+
$fYInertia = 0
|
268
|
+
$fScale = 1.0
|
269
|
+
when GLUT_KEY_LEFT:
|
270
|
+
$fXDiff -= 1
|
271
|
+
when GLUT_KEY_RIGHT:
|
272
|
+
$fXDiff += 1
|
273
|
+
when GLUT_KEY_UP:
|
274
|
+
$fYDiff -= 1
|
275
|
+
when GLUT_KEY_DOWN:
|
276
|
+
$fYDiff += 1
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
timer = lambda do |value|
|
281
|
+
$ftime += 0.01
|
282
|
+
if $rotate
|
283
|
+
$fXDiff += $fXInertia
|
284
|
+
$fYDiff += $fYInertia
|
285
|
+
end
|
286
|
+
glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
|
287
|
+
end
|
288
|
+
|
289
|
+
def printOpenGLError
|
290
|
+
glErr = glGetError()
|
291
|
+
if (glErr != GL_NO_ERROR)
|
292
|
+
puts "glError - #{gluErrorString(glErr)}"
|
293
|
+
raise
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
def getUniLoc(program, name)
|
298
|
+
loc = glGetUniformLocation(program, name)
|
299
|
+
|
300
|
+
if (loc == -1)
|
301
|
+
puts "No such uniform named #{name}"
|
302
|
+
end
|
303
|
+
printOpenGLError()
|
304
|
+
return loc
|
305
|
+
end
|
306
|
+
|
307
|
+
def installBrickShaders(vs_fname,fs_fname)
|
308
|
+
# Create a vertex shader object and a fragment shader object
|
309
|
+
brickVS = glCreateShader(GL_VERTEX_SHADER)
|
310
|
+
brickFS = glCreateShader(GL_FRAGMENT_SHADER)
|
311
|
+
|
312
|
+
# Load source code strings into shaders
|
313
|
+
glShaderSource(brickVS, File.read(vs_fname))
|
314
|
+
glShaderSource(brickFS, File.read(fs_fname))
|
315
|
+
|
316
|
+
# Compile the brick vertex shader, and print out
|
317
|
+
# the compiler log file.
|
318
|
+
glCompileShader(brickVS)
|
319
|
+
printOpenGLError()
|
320
|
+
vertCompiled = glGetShaderiv(brickVS, GL_COMPILE_STATUS)
|
321
|
+
puts "Shader InfoLog:\n#{glGetShaderInfoLog(brickVS)}\n"
|
322
|
+
|
323
|
+
# Compile the brick fragment shader, and print out
|
324
|
+
# the compiler log file.
|
325
|
+
glCompileShader(brickFS)
|
326
|
+
printOpenGLError()
|
327
|
+
fragCompiled = glGetShaderiv(brickFS, GL_COMPILE_STATUS)
|
328
|
+
puts "Shader InfoLog:\n#{glGetShaderInfoLog(brickFS)}\n"
|
329
|
+
|
330
|
+
return false if (vertCompiled == 0 || fragCompiled == 0)
|
331
|
+
# Create a program object and attach the two compiled shaders
|
332
|
+
brickProg = glCreateProgram()
|
333
|
+
glAttachShader(brickProg,brickVS)
|
334
|
+
glAttachShader(brickProg,brickFS)
|
335
|
+
# Link the program object and print out the info log
|
336
|
+
glLinkProgram(brickProg)
|
337
|
+
printOpenGLError()
|
338
|
+
linked = glGetProgramiv(brickProg,GL_LINK_STATUS)
|
339
|
+
puts "Program InfoLog:\n#{glGetProgramInfoLog(brickProg)}\n"
|
340
|
+
return false if linked==0
|
341
|
+
|
342
|
+
# Install program object as part of current state
|
343
|
+
glUseProgram(brickProg)
|
344
|
+
|
345
|
+
# Set up initial uniform values
|
346
|
+
glUniform3f(getUniLoc(brickProg, "BrickColor"), 1.0, 0.3, 0.2)
|
347
|
+
glUniform3f(getUniLoc(brickProg, "MortarColor"), 0.85, 0.86, 0.84)
|
348
|
+
glUniform2f(getUniLoc(brickProg, "BrickSize"), 0.30, 0.15)
|
349
|
+
glUniform2f(getUniLoc(brickProg, "BrickPct"), 0.90, 0.85)
|
350
|
+
glUniform3f(getUniLoc(brickProg, "LightPosition"), 0.0, 0.0, 4.0)
|
351
|
+
|
352
|
+
return true
|
353
|
+
end
|
354
|
+
|
355
|
+
# Main
|
356
|
+
|
357
|
+
glutInit()
|
358
|
+
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE)
|
359
|
+
glutInitWindowPosition(100,100)
|
360
|
+
glutInitWindowSize(500, 500)
|
361
|
+
glutCreateWindow( "3Dlabs Brick Shader")
|
362
|
+
|
363
|
+
glutIdleFunc(play)
|
364
|
+
glutDisplayFunc(display)
|
365
|
+
glutKeyboardFunc(key)
|
366
|
+
glutReshapeFunc(reshape)
|
367
|
+
glutMotionFunc(motion)
|
368
|
+
glutMouseFunc(mouse)
|
369
|
+
glutSpecialFunc(special)
|
370
|
+
glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
|
371
|
+
|
372
|
+
# Make sure that OpenGL 2.0 is supported by the driver
|
373
|
+
if Gl.is_available?(2.0)==false
|
374
|
+
major,minor,*rest = glGetString(GL_VERSION).split(/\.| /)
|
375
|
+
puts "GL_VERSION major=#{major} minor=#{minor}"
|
376
|
+
puts "Support for OpenGL 2.0 is required for this demo...exiting"
|
377
|
+
exit(1)
|
378
|
+
end
|
379
|
+
|
380
|
+
glDepthFunc(GL_LESS)
|
381
|
+
glEnable(GL_DEPTH_TEST)
|
382
|
+
|
383
|
+
nextClearColor()
|
384
|
+
|
385
|
+
key.call('?', 0, 0)
|
386
|
+
|
387
|
+
success = installBrickShaders("brick.vert","brick.frag")
|
388
|
+
glutMainLoop() if success == true
|