ruby-opengl 0.60.1 → 0.61.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +36 -186
- data/Rakefile +0 -168
- data/doc/build_install.txt +0 -122
- data/doc/extensions.txt +0 -556
- data/doc/extensions.txt.in +0 -348
- data/doc/history.txt +0 -66
- data/doc/requirements_and_design.txt +0 -117
- data/doc/roadmap.txt +0 -28
- data/doc/scientific_use.txt +0 -35
- data/doc/supplies/page_template.html +0 -71
- data/doc/thanks.txt +0 -29
- data/doc/tutorial.txt +0 -469
- data/examples/NeHe/nehe_lesson02.rb +0 -117
- data/examples/NeHe/nehe_lesson03.rb +0 -122
- data/examples/NeHe/nehe_lesson04.rb +0 -133
- data/examples/NeHe/nehe_lesson05.rb +0 -186
- data/examples/NeHe/nehe_lesson36.rb +0 -303
- data/examples/OrangeBook/3Dlabs-License.txt +0 -33
- data/examples/OrangeBook/brick.frag +0 -36
- data/examples/OrangeBook/brick.rb +0 -376
- data/examples/OrangeBook/brick.vert +0 -41
- data/examples/OrangeBook/particle.frag +0 -17
- data/examples/OrangeBook/particle.rb +0 -406
- data/examples/OrangeBook/particle.vert +0 -38
- data/examples/README +0 -16
- data/examples/RedBook/aapoly.rb +0 -142
- data/examples/RedBook/aargb.rb +0 -119
- data/examples/RedBook/accanti.rb +0 -162
- data/examples/RedBook/accpersp.rb +0 -215
- data/examples/RedBook/alpha.rb +0 -123
- data/examples/RedBook/alpha3D.rb +0 -158
- data/examples/RedBook/bezcurve.rb +0 -105
- data/examples/RedBook/bezmesh.rb +0 -137
- data/examples/RedBook/checker.rb +0 -124
- data/examples/RedBook/clip.rb +0 -95
- data/examples/RedBook/colormat.rb +0 -135
- data/examples/RedBook/cube.rb +0 -69
- data/examples/RedBook/depthcue.rb +0 -99
- data/examples/RedBook/dof.rb +0 -205
- data/examples/RedBook/double.rb +0 -105
- data/examples/RedBook/drawf.rb +0 -91
- data/examples/RedBook/feedback.rb +0 -145
- data/examples/RedBook/fog.rb +0 -167
- data/examples/RedBook/font.rb +0 -151
- data/examples/RedBook/hello.rb +0 -79
- data/examples/RedBook/image.rb +0 -137
- data/examples/RedBook/jitter.rb +0 -207
- data/examples/RedBook/lines.rb +0 -128
- data/examples/RedBook/list.rb +0 -111
- data/examples/RedBook/material.rb +0 -275
- data/examples/RedBook/mipmap.rb +0 -156
- data/examples/RedBook/model.rb +0 -113
- data/examples/RedBook/movelight.rb +0 -132
- data/examples/RedBook/pickdepth.rb +0 -179
- data/examples/RedBook/planet.rb +0 -108
- data/examples/RedBook/quadric.rb +0 -158
- data/examples/RedBook/robot.rb +0 -115
- data/examples/RedBook/select.rb +0 -196
- data/examples/RedBook/smooth.rb +0 -95
- data/examples/RedBook/stencil.rb +0 -163
- data/examples/RedBook/stroke.rb +0 -167
- data/examples/RedBook/surface.rb +0 -166
- data/examples/RedBook/teaambient.rb +0 -132
- data/examples/RedBook/teapots.rb +0 -182
- data/examples/RedBook/tess.rb +0 -183
- data/examples/RedBook/texbind.rb +0 -147
- data/examples/RedBook/texgen.rb +0 -169
- data/examples/RedBook/texturesurf.rb +0 -128
- data/examples/RedBook/varray.rb +0 -159
- data/examples/RedBook/wrap.rb +0 -148
- data/examples/misc/OGLBench.rb +0 -337
- data/examples/misc/anisotropic.rb +0 -194
- data/examples/misc/fbo_test.rb +0 -356
- data/examples/misc/font-glut.rb +0 -46
- data/examples/misc/glfwtest.rb +0 -30
- data/examples/misc/plane.rb +0 -161
- data/examples/misc/readpixel.rb +0 -65
- data/examples/misc/sdltest.rb +0 -34
- data/examples/misc/trislam.rb +0 -828
- data/ext/common/common.h +0 -423
- data/ext/common/conv.h +0 -244
- data/ext/common/funcdef.h +0 -280
- data/ext/common/gl-enums.h +0 -10031
- data/ext/common/gl-error.h +0 -23
- data/ext/common/gl-types.h +0 -61
- data/ext/common/glu-enums.h +0 -463
- data/ext/gl/gl-1.0-1.1.c +0 -2817
- data/ext/gl/gl-1.2.c +0 -814
- data/ext/gl/gl-1.3.c +0 -444
- data/ext/gl/gl-1.4.c +0 -349
- data/ext/gl/gl-1.5.c +0 -225
- data/ext/gl/gl-2.0.c +0 -657
- data/ext/gl/gl-2.1.c +0 -57
- data/ext/gl/gl-enums.c +0 -3354
- data/ext/gl/gl-error.c +0 -104
- data/ext/gl/gl-ext-3dfx.c +0 -27
- data/ext/gl/gl-ext-arb.c +0 -866
- data/ext/gl/gl-ext-ati.c +0 -41
- data/ext/gl/gl-ext-ext.c +0 -890
- data/ext/gl/gl-ext-gremedy.c +0 -41
- data/ext/gl/gl-ext-nv.c +0 -679
- data/ext/gl/gl.c +0 -214
- data/ext/gl/mkrf_conf.rb +0 -34
- data/ext/glu/glu-enums.c +0 -164
- data/ext/glu/glu.c +0 -1530
- data/ext/glu/mkrf_conf.rb +0 -35
- data/ext/glut/glut.c +0 -1623
- data/ext/glut/mkrf_conf.rb +0 -37
- data/lib/opengl.rb +0 -84
- data/test/README +0 -10
- data/test/tc_common.rb +0 -98
- data/test/tc_ext_arb.rb +0 -467
- data/test/tc_ext_ati.rb +0 -33
- data/test/tc_ext_ext.rb +0 -551
- data/test/tc_ext_gremedy.rb +0 -36
- data/test/tc_ext_nv.rb +0 -357
- data/test/tc_func_10_11.rb +0 -1281
- data/test/tc_func_12.rb +0 -186
- data/test/tc_func_13.rb +0 -229
- data/test/tc_func_14.rb +0 -197
- data/test/tc_func_15.rb +0 -270
- data/test/tc_func_20.rb +0 -346
- data/test/tc_func_21.rb +0 -541
- data/test/tc_glu.rb +0 -310
- data/test/tc_include_gl.rb +0 -35
- data/test/tc_misc.rb +0 -54
- data/test/tc_require_gl.rb +0 -34
@@ -1,41 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Vertex 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 LightPosition;
|
13
|
-
|
14
|
-
const float SpecularContribution = 0.3;
|
15
|
-
const float DiffuseContribution = 1.0 - SpecularContribution;
|
16
|
-
|
17
|
-
varying float LightIntensity;
|
18
|
-
varying vec2 MCposition;
|
19
|
-
|
20
|
-
void main(void)
|
21
|
-
{
|
22
|
-
vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex);
|
23
|
-
vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
|
24
|
-
vec3 lightVec = normalize(LightPosition - ecPosition);
|
25
|
-
vec3 reflectVec = reflect(-lightVec, tnorm);
|
26
|
-
vec3 viewVec = normalize(-ecPosition);
|
27
|
-
float diffuse = max(dot(lightVec, tnorm), 0.0);
|
28
|
-
float spec = 0.0;
|
29
|
-
|
30
|
-
if (diffuse > 0.0)
|
31
|
-
{
|
32
|
-
spec = max(dot(reflectVec, viewVec), 0.0);
|
33
|
-
spec = pow(spec, 16.0);
|
34
|
-
}
|
35
|
-
|
36
|
-
LightIntensity = DiffuseContribution * diffuse +
|
37
|
-
SpecularContribution * spec;
|
38
|
-
|
39
|
-
MCposition = gl_Vertex.xy;
|
40
|
-
gl_Position = ftransform();
|
41
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Fragment shader for rendering a "confetti cannon"
|
3
|
-
// via a partcle system
|
4
|
-
//
|
5
|
-
// Author: Randi Rost
|
6
|
-
//
|
7
|
-
// Copyright (c) 2003-2004: 3Dlabs, Inc.
|
8
|
-
//
|
9
|
-
// See 3Dlabs-License.txt for license information
|
10
|
-
//
|
11
|
-
|
12
|
-
varying vec4 Color;
|
13
|
-
|
14
|
-
void main (void)
|
15
|
-
{
|
16
|
-
gl_FragColor = Color;
|
17
|
-
}
|
@@ -1,406 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
3
|
-
# All rights reserved.
|
4
|
-
#
|
5
|
-
# Redistribution and use in source and binary forms, with or without
|
6
|
-
# modification, are permitted provided that the following conditions
|
7
|
-
# are met:
|
8
|
-
#
|
9
|
-
# Redistributions of source code must retain the above copyright
|
10
|
-
# notice, this list of conditions and the following disclaimer.
|
11
|
-
#
|
12
|
-
# Redistributions in binary form must reproduce the above
|
13
|
-
# copyright notice, this list of conditions and the following
|
14
|
-
# disclaimer in the documentation and/or other materials provided
|
15
|
-
# with the distribution.
|
16
|
-
#
|
17
|
-
# Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
18
|
-
# contributors may be used to endorse or promote products derived
|
19
|
-
# from this software without specific prior written permission.
|
20
|
-
#
|
21
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
-
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
24
|
-
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
-
# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
26
|
-
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
27
|
-
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
28
|
-
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
29
|
-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
30
|
-
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
31
|
-
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
require 'opengl'
|
34
|
-
include Gl,Glu,Glut
|
35
|
-
|
36
|
-
$particleTime = 0
|
37
|
-
|
38
|
-
# Movement variables
|
39
|
-
$fXDiff = 206
|
40
|
-
$fYDiff = 16
|
41
|
-
$fZDiff = 10
|
42
|
-
$xLastIncr = 0
|
43
|
-
$yLastIncr = 0
|
44
|
-
$fXInertia = -0.5
|
45
|
-
$fYInertia = 0
|
46
|
-
$fXInertiaOld
|
47
|
-
$fYInertiaOld
|
48
|
-
$fScale = 0.25
|
49
|
-
$ftime = 0
|
50
|
-
$xLast = -1
|
51
|
-
$yLast = -1
|
52
|
-
$bmModifiers = 0
|
53
|
-
$rotate = 1
|
54
|
-
|
55
|
-
$programObject = 0
|
56
|
-
$vertexShaderObject = 0
|
57
|
-
$fragmentShaderObject = 0
|
58
|
-
|
59
|
-
# Rotation defines
|
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
|
-
VELOCITY_ARRAY = 3
|
67
|
-
START_TIME_ARRAY = 4
|
68
|
-
|
69
|
-
$clearColor = [[0,0,0,1], [0.2,0.2,0.3,1], [0.7,0.7,0.7,1]]
|
70
|
-
|
71
|
-
$arrayWidth = 0, $arrayHeight = 0
|
72
|
-
$verts = []
|
73
|
-
$colors = []
|
74
|
-
$velocities = []
|
75
|
-
$startTimes = []
|
76
|
-
|
77
|
-
def nextClearColor
|
78
|
-
glClearColor($clearColor[0][0],
|
79
|
-
$clearColor[0][1],
|
80
|
-
$clearColor[0][2],
|
81
|
-
$clearColor[0][3])
|
82
|
-
$clearColor << $clearColor.shift # rotate
|
83
|
-
end
|
84
|
-
|
85
|
-
def getUniLoc(program, name)
|
86
|
-
loc = glGetUniformLocation(program, name)
|
87
|
-
|
88
|
-
if (loc == -1)
|
89
|
-
puts "No such uniform named #{name}"
|
90
|
-
end
|
91
|
-
return loc
|
92
|
-
end
|
93
|
-
|
94
|
-
def updateAnim
|
95
|
-
location = getUniLoc($programObject,"Time")
|
96
|
-
|
97
|
-
$particleTime += 0.002
|
98
|
-
if $particleTime > 15.0
|
99
|
-
$particleTime = 0.0
|
100
|
-
end
|
101
|
-
|
102
|
-
glUniform1f(location,$particleTime)
|
103
|
-
end
|
104
|
-
|
105
|
-
def drawPoints
|
106
|
-
glPointSize(2.0)
|
107
|
-
glVertexPointer(3, GL_FLOAT, 0, $verts)
|
108
|
-
glColorPointer(3, GL_FLOAT, 0, $colors)
|
109
|
-
glVertexAttribPointer(VELOCITY_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, $velocities)
|
110
|
-
glVertexAttribPointer(START_TIME_ARRAY, 1, GL_FLOAT, GL_FALSE, 0, $startTimes)
|
111
|
-
|
112
|
-
glEnableClientState(GL_VERTEX_ARRAY)
|
113
|
-
glEnableClientState(GL_COLOR_ARRAY)
|
114
|
-
glEnableVertexAttribArray(VELOCITY_ARRAY)
|
115
|
-
glEnableVertexAttribArray(START_TIME_ARRAY)
|
116
|
-
|
117
|
-
glDrawArrays(GL_POINTS, 0, $arrayWidth * $arrayHeight)
|
118
|
-
|
119
|
-
glDisableClientState(GL_VERTEX_ARRAY)
|
120
|
-
glDisableClientState(GL_COLOR_ARRAY)
|
121
|
-
glDisableVertexAttribArray(VELOCITY_ARRAY)
|
122
|
-
glDisableVertexAttribArray(START_TIME_ARRAY)
|
123
|
-
end
|
124
|
-
|
125
|
-
def createPoints(w,h)
|
126
|
-
$verts = []
|
127
|
-
$colors = []
|
128
|
-
$velocities = []
|
129
|
-
$startTimes = []
|
130
|
-
|
131
|
-
i = 0.5 / w - 0.5
|
132
|
-
while (i<0.5)
|
133
|
-
j = 0.5 / h - 0.5
|
134
|
-
while (j<0.5)
|
135
|
-
$verts << i
|
136
|
-
$verts << 0.0
|
137
|
-
$verts << j
|
138
|
-
|
139
|
-
$colors << rand() * 0.5 + 0.5
|
140
|
-
$colors << rand() * 0.5 + 0.5
|
141
|
-
$colors << rand() * 0.5 + 0.5
|
142
|
-
|
143
|
-
$velocities << rand() + 3.0
|
144
|
-
$velocities << rand() * 10.0
|
145
|
-
$velocities << rand() + 3.0
|
146
|
-
|
147
|
-
$startTimes << rand() * 10.0
|
148
|
-
|
149
|
-
j += 1.0/h
|
150
|
-
end
|
151
|
-
i += 1.0/w
|
152
|
-
end
|
153
|
-
# convert from ruby Array to memory representation of float data that
|
154
|
-
# will be passed as array pointers to GL
|
155
|
-
$verts = $verts.pack("f*")
|
156
|
-
$colors = $colors.pack("f*")
|
157
|
-
$velocities = $velocities.pack("f*")
|
158
|
-
$startTimes = $startTimes.pack("f*")
|
159
|
-
|
160
|
-
$arrayWidth = w
|
161
|
-
$arrayHeight = h
|
162
|
-
end
|
163
|
-
|
164
|
-
play = lambda do
|
165
|
-
thisTime = glutGet(GLUT_ELAPSED_TIME)
|
166
|
-
updateAnim()
|
167
|
-
glutPostRedisplay()
|
168
|
-
end
|
169
|
-
|
170
|
-
display = lambda do
|
171
|
-
glLoadIdentity()
|
172
|
-
glTranslatef(0.0, 0.0, -5.0)
|
173
|
-
|
174
|
-
glRotatef($fYDiff, 1,0,0)
|
175
|
-
glRotatef($fXDiff, 0,1,0)
|
176
|
-
glRotatef($fZDiff, 0,0,1)
|
177
|
-
|
178
|
-
glScalef($fScale, $fScale, $fScale)
|
179
|
-
|
180
|
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
181
|
-
|
182
|
-
drawPoints()
|
183
|
-
|
184
|
-
glFlush()
|
185
|
-
glutSwapBuffers()
|
186
|
-
end
|
187
|
-
|
188
|
-
key = lambda do |key,x,y|
|
189
|
-
$particleTime = 0
|
190
|
-
|
191
|
-
case(key)
|
192
|
-
when ?b
|
193
|
-
nextClearColor()
|
194
|
-
when ?q, ?\e # esc
|
195
|
-
exit(0)
|
196
|
-
when ?\s # space
|
197
|
-
$rotate = !$rotate
|
198
|
-
|
199
|
-
if ($rotate==false)
|
200
|
-
$fXInertiaOld = $fXInertia
|
201
|
-
$fYInertiaOld = $fYInertia
|
202
|
-
else
|
203
|
-
$fXInertia = $fXInertiaOld
|
204
|
-
$fYInertia = $fYInertiaOld
|
205
|
-
|
206
|
-
# To prevent confusion, force some rotation
|
207
|
-
if ($fXInertia == 0 && $fYInertia == 0)
|
208
|
-
$fXInertia = -0.5
|
209
|
-
end
|
210
|
-
end
|
211
|
-
when ?+
|
212
|
-
$fScale += SCALE_INCREMENT
|
213
|
-
when ?-
|
214
|
-
$fScale -= SCALE_INCREMENT
|
215
|
-
else
|
216
|
-
puts "Keyboard commands:\n"
|
217
|
-
puts "b - Toggle among background clear colors"
|
218
|
-
puts "q, <esc> - Quit"
|
219
|
-
puts "? - Help"
|
220
|
-
puts "<home> - reset zoom and rotation"
|
221
|
-
puts "<space> or <click> - stop rotation"
|
222
|
-
puts "<+>, <-> or <ctrl + drag> - zoom model"
|
223
|
-
puts "<arrow keys> or <drag> - rotate model\n"
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
reshape = lambda do |w,h|
|
228
|
-
vp = 0.8
|
229
|
-
aspect = w/h
|
230
|
-
|
231
|
-
glViewport(0, 0, w, h)
|
232
|
-
glMatrixMode(GL_PROJECTION)
|
233
|
-
glLoadIdentity()
|
234
|
-
|
235
|
-
glFrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10.0)
|
236
|
-
|
237
|
-
glMatrixMode(GL_MODELVIEW)
|
238
|
-
glLoadIdentity()
|
239
|
-
glTranslatef(0.0, 0.0, -5.0)
|
240
|
-
end
|
241
|
-
|
242
|
-
motion = lambda do |x,y|
|
243
|
-
if ($xLast != -1 || $yLast != -1)
|
244
|
-
$xLastIncr = x - $xLast
|
245
|
-
$yLastIncr = y - $yLast
|
246
|
-
if ($bmModifiers & GLUT_ACTIVE_CTRL != 0)
|
247
|
-
if ($xLast != -1)
|
248
|
-
$fZDiff += $xLastIncr
|
249
|
-
$fScale += $yLastIncr*SCALE_FACTOR
|
250
|
-
end
|
251
|
-
else
|
252
|
-
if ($xLast != -1)
|
253
|
-
$fXDiff += $xLastIncr
|
254
|
-
$fYDiff += $yLastIncr
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
$xLast = x
|
259
|
-
$yLast = y
|
260
|
-
end
|
261
|
-
|
262
|
-
mouse = lambda do |button,state,x,y|
|
263
|
-
$bmModifiers = glutGetModifiers()
|
264
|
-
if (button == GLUT_LEFT_BUTTON)
|
265
|
-
if (state == GLUT_UP)
|
266
|
-
$xLast = -1
|
267
|
-
$yLast = -1
|
268
|
-
if $xLastIncr > INERTIA_THRESHOLD
|
269
|
-
$fXInertia = ($xLastIncr - INERTIA_THRESHOLD)*INERTIA_FACTOR
|
270
|
-
end
|
271
|
-
if -$xLastIncr > INERTIA_THRESHOLD
|
272
|
-
$fXInertia = ($xLastIncr + INERTIA_THRESHOLD)*INERTIA_FACTOR
|
273
|
-
end
|
274
|
-
|
275
|
-
if $yLastIncr > INERTIA_THRESHOLD
|
276
|
-
$fYInertia = ($yLastIncr - INERTIA_THRESHOLD)*INERTIA_FACTOR
|
277
|
-
end
|
278
|
-
if -$yLastIncr > INERTIA_THRESHOLD
|
279
|
-
$fYInertia = ($yLastIncr + INERTIA_THRESHOLD)*INERTIA_FACTOR
|
280
|
-
end
|
281
|
-
else
|
282
|
-
$fXInertia = 0
|
283
|
-
$fYInertia = 0
|
284
|
-
end
|
285
|
-
$xLastIncr = 0
|
286
|
-
$yLastIncr = 0
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
special = lambda do |key,x,y|
|
291
|
-
case key
|
292
|
-
when GLUT_KEY_HOME:
|
293
|
-
$fXDiff = 206
|
294
|
-
$fYDiff = 16
|
295
|
-
$fZDiff = 10
|
296
|
-
$xLastIncr = 0
|
297
|
-
$yLastIncr = 0
|
298
|
-
$fXInertia = -0.5
|
299
|
-
$fYInertia = 0
|
300
|
-
$fScale = 0.25
|
301
|
-
$particleTime = 0
|
302
|
-
when GLUT_KEY_LEFT:
|
303
|
-
$fXDiff -= 1
|
304
|
-
when GLUT_KEY_RIGHT:
|
305
|
-
$fXDiff += 1
|
306
|
-
when GLUT_KEY_UP:
|
307
|
-
$fYDiff -= 1
|
308
|
-
when GLUT_KEY_DOWN:
|
309
|
-
$fYDiff += 1
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
timer = lambda do |value|
|
314
|
-
$ftime += 0.01
|
315
|
-
if $rotate
|
316
|
-
$fXDiff += $fXInertia
|
317
|
-
$fYDiff += $fYInertia
|
318
|
-
end
|
319
|
-
glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
|
320
|
-
end
|
321
|
-
|
322
|
-
def installParticleShaders(vs_name,fs_name)
|
323
|
-
# Create a vertex shader object and a fragment shader object
|
324
|
-
$vertexShaderObject = glCreateShader(GL_VERTEX_SHADER)
|
325
|
-
$fragmentShaderObject = glCreateShader(GL_FRAGMENT_SHADER)
|
326
|
-
|
327
|
-
# Load source code strings into shaders
|
328
|
-
glShaderSource($vertexShaderObject, File.read(vs_name))
|
329
|
-
glShaderSource($fragmentShaderObject, File.read(fs_name))
|
330
|
-
|
331
|
-
# Compile the particle vertex shader, and print out
|
332
|
-
# the compiler log file.
|
333
|
-
glCompileShader($vertexShaderObject)
|
334
|
-
vertCompiled = glGetShaderiv($vertexShaderObject, GL_COMPILE_STATUS)
|
335
|
-
puts "Shader InfoLog:\n#{glGetShaderInfoLog($vertexShaderObject)}\n"
|
336
|
-
|
337
|
-
# Compile the particle fragment shader, and print out
|
338
|
-
# the compiler log file.
|
339
|
-
glCompileShader($fragmentShaderObject)
|
340
|
-
fragCompiled = glGetShaderiv($fragmentShaderObject, GL_COMPILE_STATUS)
|
341
|
-
puts "Shader InfoLog:\n#{glGetShaderInfoLog($fragmentShaderObject)}\n"
|
342
|
-
|
343
|
-
return false if (vertCompiled == 0 || fragCompiled == 0)
|
344
|
-
|
345
|
-
# Create a program object and attach the two compiled shaders
|
346
|
-
$programObject = glCreateProgram()
|
347
|
-
glAttachShader($programObject, $vertexShaderObject)
|
348
|
-
glAttachShader($programObject, $fragmentShaderObject)
|
349
|
-
|
350
|
-
#Bind generic attribute indices to attribute variable names
|
351
|
-
glBindAttribLocation($programObject, VELOCITY_ARRAY, "Velocity")
|
352
|
-
glBindAttribLocation($programObject, START_TIME_ARRAY, "StartTime");
|
353
|
-
|
354
|
-
# Link the program object and print out the info log
|
355
|
-
glLinkProgram($programObject)
|
356
|
-
linked = glGetProgramiv($programObject, GL_LINK_STATUS)
|
357
|
-
puts "Program InfoLog:\n#{glGetProgramInfoLog($programObject)}\n"
|
358
|
-
|
359
|
-
return false if linked==0
|
360
|
-
|
361
|
-
# Install program object as part of current state
|
362
|
-
glUseProgram($programObject)
|
363
|
-
|
364
|
-
# Set up initial uniform values
|
365
|
-
glUniform4f(getUniLoc($programObject, "Background"), 0.0, 0.0, 0.0, 1.0)
|
366
|
-
glUniform1f(getUniLoc($programObject, "Time"), -5.0)
|
367
|
-
|
368
|
-
return true
|
369
|
-
end
|
370
|
-
|
371
|
-
# Main
|
372
|
-
glutInit()
|
373
|
-
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE)
|
374
|
-
glutInitWindowSize(500, 500)
|
375
|
-
glutInitWindowPosition(100,100)
|
376
|
-
window = glutCreateWindow("3Dlabs OpenGL Shading Language Particle System Demo")
|
377
|
-
|
378
|
-
glutIdleFunc(play)
|
379
|
-
glutDisplayFunc(display)
|
380
|
-
glutKeyboardFunc(key)
|
381
|
-
glutReshapeFunc(reshape)
|
382
|
-
glutMotionFunc(motion)
|
383
|
-
glutMouseFunc(mouse)
|
384
|
-
glutSpecialFunc(special)
|
385
|
-
glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
|
386
|
-
|
387
|
-
# Make sure that OpenGL 2.0 is supported by the driver
|
388
|
-
if Gl.is_available?(2.0)==false
|
389
|
-
major,minor,*rest = glGetString(GL_VERSION).split(/\.| /)
|
390
|
-
puts "GL_VERSION major=#{major} minor=#{minor}"
|
391
|
-
puts "Support for OpenGL 2.0 is required for this demo...exiting"
|
392
|
-
exit(1)
|
393
|
-
end
|
394
|
-
|
395
|
-
createPoints(100, 100)
|
396
|
-
|
397
|
-
glDepthFunc(GL_LESS)
|
398
|
-
glEnable(GL_DEPTH_TEST)
|
399
|
-
nextClearColor()
|
400
|
-
|
401
|
-
key.call('?', 0, 0)
|
402
|
-
|
403
|
-
success = installParticleShaders("particle.vert", "particle.frag")
|
404
|
-
if (success)
|
405
|
-
glutMainLoop()
|
406
|
-
end
|