opengl 0.9.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.autotest +29 -0
- data/.gemtest +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +19 -0
- data/History.rdoc +77 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +138 -0
- data/README.rdoc +102 -0
- data/Rakefile +60 -0
- data/examples/NeHe/NeHe.png +0 -0
- data/examples/NeHe/crate.png +0 -0
- data/examples/NeHe/glass.png +0 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +123 -0
- data/examples/NeHe/nehe_lesson04.rb +132 -0
- data/examples/NeHe/nehe_lesson05.rb +182 -0
- data/examples/NeHe/nehe_lesson06.rb +186 -0
- data/examples/NeHe/nehe_lesson07.rb +240 -0
- data/examples/NeHe/nehe_lesson08.rb +255 -0
- data/examples/NeHe/nehe_lesson09.rb +203 -0
- data/examples/NeHe/nehe_lesson11.rb +176 -0
- data/examples/NeHe/nehe_lesson12.rb +203 -0
- data/examples/NeHe/nehe_lesson16.rb +211 -0
- data/examples/NeHe/nehe_lesson19.rb +209 -0
- data/examples/NeHe/nehe_lesson36.rb +308 -0
- data/examples/NeHe/particle.png +0 -0
- data/examples/NeHe/star.png +0 -0
- data/examples/NeHe/tim.png +0 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +378 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +408 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -0
- data/examples/RedBook/aapoly.rb +143 -0
- data/examples/RedBook/aargb.rb +121 -0
- data/examples/RedBook/accanti.rb +164 -0
- data/examples/RedBook/accpersp.rb +217 -0
- data/examples/RedBook/alpha.rb +125 -0
- data/examples/RedBook/alpha3D.rb +160 -0
- data/examples/RedBook/bezcurve.rb +107 -0
- data/examples/RedBook/bezmesh.rb +139 -0
- data/examples/RedBook/checker.rb +126 -0
- data/examples/RedBook/clip.rb +97 -0
- data/examples/RedBook/colormat.rb +137 -0
- data/examples/RedBook/cube.rb +71 -0
- data/examples/RedBook/depthcue.rb +101 -0
- data/examples/RedBook/dof.rb +206 -0
- data/examples/RedBook/double.rb +107 -0
- data/examples/RedBook/drawf.rb +93 -0
- data/examples/RedBook/feedback.rb +147 -0
- data/examples/RedBook/fog.rb +168 -0
- data/examples/RedBook/font.rb +153 -0
- data/examples/RedBook/hello.rb +81 -0
- data/examples/RedBook/image.rb +139 -0
- data/examples/RedBook/jitter.rb +207 -0
- data/examples/RedBook/light.rb +155 -0
- data/examples/RedBook/lines.rb +130 -0
- data/examples/RedBook/list.rb +113 -0
- data/examples/RedBook/material.rb +276 -0
- data/examples/RedBook/mipmap.rb +158 -0
- data/examples/RedBook/model.rb +115 -0
- data/examples/RedBook/movelight.rb +134 -0
- data/examples/RedBook/pickdepth.rb +181 -0
- data/examples/RedBook/planet.rb +110 -0
- data/examples/RedBook/quadric.rb +160 -0
- data/examples/RedBook/robot.rb +117 -0
- data/examples/RedBook/select.rb +198 -0
- data/examples/RedBook/smooth.rb +97 -0
- data/examples/RedBook/stencil.rb +165 -0
- data/examples/RedBook/stroke.rb +169 -0
- data/examples/RedBook/surface.rb +168 -0
- data/examples/RedBook/teaambient.rb +134 -0
- data/examples/RedBook/teapots.rb +184 -0
- data/examples/RedBook/tess.rb +185 -0
- data/examples/RedBook/texbind.rb +149 -0
- data/examples/RedBook/texgen.rb +171 -0
- data/examples/RedBook/texturesurf.rb +130 -0
- data/examples/RedBook/varray.rb +161 -0
- data/examples/RedBook/wrap.rb +150 -0
- data/examples/misc/OGLBench.rb +338 -0
- data/examples/misc/anisotropic.rb +196 -0
- data/examples/misc/fbo_test.rb +357 -0
- data/examples/misc/font-glut.rb +47 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +66 -0
- data/examples/misc/sdltest.rb +36 -0
- data/examples/misc/trislam.rb +829 -0
- data/ext/opengl/common.h +428 -0
- data/ext/opengl/conv.h +244 -0
- data/ext/opengl/extconf.rb +47 -0
- data/ext/opengl/funcdef.h +313 -0
- data/ext/opengl/gl-1.0-1.1.c +3075 -0
- data/ext/opengl/gl-1.2.c +155 -0
- data/ext/opengl/gl-1.3.c +443 -0
- data/ext/opengl/gl-1.4.c +348 -0
- data/ext/opengl/gl-1.5.c +224 -0
- data/ext/opengl/gl-2.0.c +667 -0
- data/ext/opengl/gl-2.1.c +57 -0
- data/ext/opengl/gl-3.0.c +493 -0
- data/ext/opengl/gl-enums.c +4873 -0
- data/ext/opengl/gl-enums.h +14588 -0
- data/ext/opengl/gl-error.c +112 -0
- data/ext/opengl/gl-error.h +28 -0
- data/ext/opengl/gl-ext-3dfx.c +27 -0
- data/ext/opengl/gl-ext-arb.c +875 -0
- data/ext/opengl/gl-ext-ati.c +41 -0
- data/ext/opengl/gl-ext-ext.c +889 -0
- data/ext/opengl/gl-ext-gremedy.c +41 -0
- data/ext/opengl/gl-ext-nv.c +680 -0
- data/ext/opengl/gl-types.h +67 -0
- data/ext/opengl/gl.c +220 -0
- data/ext/opengl/gl_buffer.c +177 -0
- data/ext/opengl/opengl.c +7 -0
- data/lib/gl.rb +1 -0
- data/lib/opengl.rb +53 -0
- data/lib/opengl/2.0/opengl.so +0 -0
- data/lib/opengl/2.1/opengl.so +0 -0
- data/lib/opengl/test_case.rb +86 -0
- data/test/dummy.xorg.conf +140 -0
- data/test/test_gl.rb +38 -0
- data/test/test_gl_10_11.rb +1363 -0
- data/test/test_gl_12.rb +71 -0
- data/test/test_gl_13.rb +221 -0
- data/test/test_gl_14.rb +218 -0
- data/test/test_gl_15.rb +258 -0
- data/test/test_gl_20.rb +417 -0
- data/test/test_gl_21.rb +436 -0
- data/test/test_gl_ext_arb.rb +508 -0
- data/test/test_gl_ext_ati.rb +28 -0
- data/test/test_gl_ext_ext.rb +608 -0
- data/test/test_gl_ext_gremedy.rb +29 -0
- data/test/test_gl_ext_nv.rb +349 -0
- data/test/test_opengl_buffer.rb +120 -0
- data/utils/README +6 -0
- data/utils/enumgen.rb +108 -0
- data/utils/extlistgen.rb +90 -0
- metadata +319 -0
- metadata.gz.sig +1 -0
@@ -0,0 +1,41 @@
|
|
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
|
+
}
|
@@ -0,0 +1,17 @@
|
|
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
|
+
}
|
@@ -0,0 +1,408 @@
|
|
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
|
+
require 'glu'
|
35
|
+
require 'glut'
|
36
|
+
include Gl,Glu,Glut
|
37
|
+
|
38
|
+
$particleTime = 0
|
39
|
+
|
40
|
+
# Movement variables
|
41
|
+
$fXDiff = 206
|
42
|
+
$fYDiff = 16
|
43
|
+
$fZDiff = 10
|
44
|
+
$xLastIncr = 0
|
45
|
+
$yLastIncr = 0
|
46
|
+
$fXInertia = -0.5
|
47
|
+
$fYInertia = 0
|
48
|
+
$fXInertiaOld
|
49
|
+
$fYInertiaOld
|
50
|
+
$fScale = 0.25
|
51
|
+
$ftime = 0
|
52
|
+
$xLast = -1
|
53
|
+
$yLast = -1
|
54
|
+
$bmModifiers = 0
|
55
|
+
$rotate = 1
|
56
|
+
|
57
|
+
$programObject = 0
|
58
|
+
$vertexShaderObject = 0
|
59
|
+
$fragmentShaderObject = 0
|
60
|
+
|
61
|
+
# Rotation defines
|
62
|
+
INERTIA_THRESHOLD = 1.0
|
63
|
+
INERTIA_FACTOR = 0.5
|
64
|
+
SCALE_FACTOR = 0.01
|
65
|
+
SCALE_INCREMENT = 0.5
|
66
|
+
TIMER_FREQUENCY_MILLIS = 20
|
67
|
+
|
68
|
+
VELOCITY_ARRAY = 5
|
69
|
+
START_TIME_ARRAY = 4
|
70
|
+
|
71
|
+
$clearColor = [[0,0,0,1], [0.2,0.2,0.3,1], [0.7,0.7,0.7,1]]
|
72
|
+
|
73
|
+
$arrayWidth = 0, $arrayHeight = 0
|
74
|
+
$verts = []
|
75
|
+
$colors = []
|
76
|
+
$velocities = []
|
77
|
+
$startTimes = []
|
78
|
+
|
79
|
+
def nextClearColor
|
80
|
+
glClearColor($clearColor[0][0],
|
81
|
+
$clearColor[0][1],
|
82
|
+
$clearColor[0][2],
|
83
|
+
$clearColor[0][3])
|
84
|
+
$clearColor << $clearColor.shift # rotate
|
85
|
+
end
|
86
|
+
|
87
|
+
def getUniLoc(program, name)
|
88
|
+
loc = glGetUniformLocation(program, name)
|
89
|
+
|
90
|
+
if (loc == -1)
|
91
|
+
puts "No such uniform named #{name}"
|
92
|
+
end
|
93
|
+
return loc
|
94
|
+
end
|
95
|
+
|
96
|
+
def updateAnim
|
97
|
+
location = getUniLoc($programObject,"Time")
|
98
|
+
|
99
|
+
$particleTime += 0.002
|
100
|
+
if $particleTime > 15.0
|
101
|
+
$particleTime = 0.0
|
102
|
+
end
|
103
|
+
|
104
|
+
glUniform1f(location,$particleTime)
|
105
|
+
end
|
106
|
+
|
107
|
+
def drawPoints
|
108
|
+
glPointSize(2.0)
|
109
|
+
glVertexPointer(3, GL_FLOAT, 0, $verts)
|
110
|
+
glColorPointer(3, GL_FLOAT, 0, $colors)
|
111
|
+
glVertexAttribPointer(VELOCITY_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, $velocities)
|
112
|
+
glVertexAttribPointer(START_TIME_ARRAY, 1, GL_FLOAT, GL_FALSE, 0, $startTimes)
|
113
|
+
|
114
|
+
glEnableClientState(GL_VERTEX_ARRAY)
|
115
|
+
glEnableClientState(GL_COLOR_ARRAY)
|
116
|
+
glEnableVertexAttribArray(VELOCITY_ARRAY)
|
117
|
+
glEnableVertexAttribArray(START_TIME_ARRAY)
|
118
|
+
|
119
|
+
glDrawArrays(GL_POINTS, 0, $arrayWidth * $arrayHeight)
|
120
|
+
|
121
|
+
glDisableClientState(GL_VERTEX_ARRAY)
|
122
|
+
glDisableClientState(GL_COLOR_ARRAY)
|
123
|
+
glDisableVertexAttribArray(VELOCITY_ARRAY)
|
124
|
+
glDisableVertexAttribArray(START_TIME_ARRAY)
|
125
|
+
end
|
126
|
+
|
127
|
+
def createPoints(w,h)
|
128
|
+
$verts = []
|
129
|
+
$colors = []
|
130
|
+
$velocities = []
|
131
|
+
$startTimes = []
|
132
|
+
|
133
|
+
i = 0.5 / w - 0.5
|
134
|
+
while (i<0.5)
|
135
|
+
j = 0.5 / h - 0.5
|
136
|
+
while (j<0.5)
|
137
|
+
$verts << i
|
138
|
+
$verts << 0.0
|
139
|
+
$verts << j
|
140
|
+
|
141
|
+
$colors << rand() * 0.5 + 0.5
|
142
|
+
$colors << rand() * 0.5 + 0.5
|
143
|
+
$colors << rand() * 0.5 + 0.5
|
144
|
+
|
145
|
+
$velocities << rand() + 3.0
|
146
|
+
$velocities << rand() * 10.0
|
147
|
+
$velocities << rand() + 3.0
|
148
|
+
|
149
|
+
$startTimes << rand() * 10.0
|
150
|
+
|
151
|
+
j += 1.0/h
|
152
|
+
end
|
153
|
+
i += 1.0/w
|
154
|
+
end
|
155
|
+
# convert from ruby Array to memory representation of float data that
|
156
|
+
# will be passed as array pointers to GL
|
157
|
+
$verts = $verts.pack("f*")
|
158
|
+
$colors = $colors.pack("f*")
|
159
|
+
$velocities = $velocities.pack("f*")
|
160
|
+
$startTimes = $startTimes.pack("f*")
|
161
|
+
|
162
|
+
$arrayWidth = w
|
163
|
+
$arrayHeight = h
|
164
|
+
end
|
165
|
+
|
166
|
+
play = lambda do
|
167
|
+
thisTime = glutGet(GLUT_ELAPSED_TIME)
|
168
|
+
updateAnim()
|
169
|
+
glutPostRedisplay()
|
170
|
+
end
|
171
|
+
|
172
|
+
display = lambda do
|
173
|
+
glLoadIdentity()
|
174
|
+
glTranslatef(0.0, 0.0, -5.0)
|
175
|
+
|
176
|
+
glRotatef($fYDiff, 1,0,0)
|
177
|
+
glRotatef($fXDiff, 0,1,0)
|
178
|
+
glRotatef($fZDiff, 0,0,1)
|
179
|
+
|
180
|
+
glScalef($fScale, $fScale, $fScale)
|
181
|
+
|
182
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
183
|
+
|
184
|
+
drawPoints()
|
185
|
+
|
186
|
+
glFlush()
|
187
|
+
glutSwapBuffers()
|
188
|
+
end
|
189
|
+
|
190
|
+
key = lambda do |key,x,y|
|
191
|
+
$particleTime = 0
|
192
|
+
|
193
|
+
case(key)
|
194
|
+
when ?b
|
195
|
+
nextClearColor()
|
196
|
+
when ?q, ?\e # esc
|
197
|
+
exit(0)
|
198
|
+
when ?\s # space
|
199
|
+
$rotate = !$rotate
|
200
|
+
|
201
|
+
if ($rotate==false)
|
202
|
+
$fXInertiaOld = $fXInertia
|
203
|
+
$fYInertiaOld = $fYInertia
|
204
|
+
else
|
205
|
+
$fXInertia = $fXInertiaOld
|
206
|
+
$fYInertia = $fYInertiaOld
|
207
|
+
|
208
|
+
# To prevent confusion, force some rotation
|
209
|
+
if ($fXInertia == 0 && $fYInertia == 0)
|
210
|
+
$fXInertia = -0.5
|
211
|
+
end
|
212
|
+
end
|
213
|
+
when ?+
|
214
|
+
$fScale += SCALE_INCREMENT
|
215
|
+
when ?-
|
216
|
+
$fScale -= SCALE_INCREMENT
|
217
|
+
else
|
218
|
+
puts "Keyboard commands:\n"
|
219
|
+
puts "b - Toggle among background clear colors"
|
220
|
+
puts "q, <esc> - Quit"
|
221
|
+
puts "? - Help"
|
222
|
+
puts "<home> - reset zoom and rotation"
|
223
|
+
puts "<space> or <click> - stop rotation"
|
224
|
+
puts "<+>, <-> or <ctrl + drag> - zoom model"
|
225
|
+
puts "<arrow keys> or <drag> - rotate model\n"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
reshape = lambda do |w,h|
|
230
|
+
vp = 0.8
|
231
|
+
aspect = w/h
|
232
|
+
|
233
|
+
glViewport(0, 0, w, h)
|
234
|
+
glMatrixMode(GL_PROJECTION)
|
235
|
+
glLoadIdentity()
|
236
|
+
|
237
|
+
glFrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10.0)
|
238
|
+
|
239
|
+
glMatrixMode(GL_MODELVIEW)
|
240
|
+
glLoadIdentity()
|
241
|
+
glTranslatef(0.0, 0.0, -5.0)
|
242
|
+
end
|
243
|
+
|
244
|
+
motion = lambda do |x,y|
|
245
|
+
if ($xLast != -1 || $yLast != -1)
|
246
|
+
$xLastIncr = x - $xLast
|
247
|
+
$yLastIncr = y - $yLast
|
248
|
+
if ($bmModifiers & GLUT_ACTIVE_CTRL != 0)
|
249
|
+
if ($xLast != -1)
|
250
|
+
$fZDiff += $xLastIncr
|
251
|
+
$fScale += $yLastIncr*SCALE_FACTOR
|
252
|
+
end
|
253
|
+
else
|
254
|
+
if ($xLast != -1)
|
255
|
+
$fXDiff += $xLastIncr
|
256
|
+
$fYDiff += $yLastIncr
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
$xLast = x
|
261
|
+
$yLast = y
|
262
|
+
end
|
263
|
+
|
264
|
+
mouse = lambda do |button,state,x,y|
|
265
|
+
$bmModifiers = glutGetModifiers()
|
266
|
+
if (button == GLUT_LEFT_BUTTON)
|
267
|
+
if (state == GLUT_UP)
|
268
|
+
$xLast = -1
|
269
|
+
$yLast = -1
|
270
|
+
if $xLastIncr > INERTIA_THRESHOLD
|
271
|
+
$fXInertia = ($xLastIncr - INERTIA_THRESHOLD)*INERTIA_FACTOR
|
272
|
+
end
|
273
|
+
if -$xLastIncr > INERTIA_THRESHOLD
|
274
|
+
$fXInertia = ($xLastIncr + INERTIA_THRESHOLD)*INERTIA_FACTOR
|
275
|
+
end
|
276
|
+
|
277
|
+
if $yLastIncr > INERTIA_THRESHOLD
|
278
|
+
$fYInertia = ($yLastIncr - INERTIA_THRESHOLD)*INERTIA_FACTOR
|
279
|
+
end
|
280
|
+
if -$yLastIncr > INERTIA_THRESHOLD
|
281
|
+
$fYInertia = ($yLastIncr + INERTIA_THRESHOLD)*INERTIA_FACTOR
|
282
|
+
end
|
283
|
+
else
|
284
|
+
$fXInertia = 0
|
285
|
+
$fYInertia = 0
|
286
|
+
end
|
287
|
+
$xLastIncr = 0
|
288
|
+
$yLastIncr = 0
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
special = lambda do |key,x,y|
|
293
|
+
case key
|
294
|
+
when GLUT_KEY_HOME
|
295
|
+
$fXDiff = 206
|
296
|
+
$fYDiff = 16
|
297
|
+
$fZDiff = 10
|
298
|
+
$xLastIncr = 0
|
299
|
+
$yLastIncr = 0
|
300
|
+
$fXInertia = -0.5
|
301
|
+
$fYInertia = 0
|
302
|
+
$fScale = 0.25
|
303
|
+
$particleTime = 0
|
304
|
+
when GLUT_KEY_LEFT
|
305
|
+
$fXDiff -= 1
|
306
|
+
when GLUT_KEY_RIGHT
|
307
|
+
$fXDiff += 1
|
308
|
+
when GLUT_KEY_UP
|
309
|
+
$fYDiff -= 1
|
310
|
+
when GLUT_KEY_DOWN
|
311
|
+
$fYDiff += 1
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
timer = lambda do |value|
|
316
|
+
$ftime += 0.01
|
317
|
+
if $rotate
|
318
|
+
$fXDiff += $fXInertia
|
319
|
+
$fYDiff += $fYInertia
|
320
|
+
end
|
321
|
+
glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
|
322
|
+
end
|
323
|
+
|
324
|
+
def installParticleShaders(vs_name,fs_name)
|
325
|
+
# Create a vertex shader object and a fragment shader object
|
326
|
+
$vertexShaderObject = glCreateShader(GL_VERTEX_SHADER)
|
327
|
+
$fragmentShaderObject = glCreateShader(GL_FRAGMENT_SHADER)
|
328
|
+
|
329
|
+
# Load source code strings into shaders
|
330
|
+
glShaderSource($vertexShaderObject, File.read(vs_name))
|
331
|
+
glShaderSource($fragmentShaderObject, File.read(fs_name))
|
332
|
+
|
333
|
+
# Compile the particle vertex shader, and print out
|
334
|
+
# the compiler log file.
|
335
|
+
glCompileShader($vertexShaderObject)
|
336
|
+
vertCompiled = glGetShaderiv($vertexShaderObject, GL_COMPILE_STATUS)
|
337
|
+
puts "Shader InfoLog:\n#{glGetShaderInfoLog($vertexShaderObject)}\n"
|
338
|
+
|
339
|
+
# Compile the particle fragment shader, and print out
|
340
|
+
# the compiler log file.
|
341
|
+
glCompileShader($fragmentShaderObject)
|
342
|
+
fragCompiled = glGetShaderiv($fragmentShaderObject, GL_COMPILE_STATUS)
|
343
|
+
puts "Shader InfoLog:\n#{glGetShaderInfoLog($fragmentShaderObject)}\n"
|
344
|
+
|
345
|
+
return false if (vertCompiled == 0 || fragCompiled == 0)
|
346
|
+
|
347
|
+
# Create a program object and attach the two compiled shaders
|
348
|
+
$programObject = glCreateProgram()
|
349
|
+
glAttachShader($programObject, $vertexShaderObject)
|
350
|
+
glAttachShader($programObject, $fragmentShaderObject)
|
351
|
+
|
352
|
+
#Bind generic attribute indices to attribute variable names
|
353
|
+
glBindAttribLocation($programObject, VELOCITY_ARRAY, "Velocity")
|
354
|
+
glBindAttribLocation($programObject, START_TIME_ARRAY, "StartTime")
|
355
|
+
|
356
|
+
# Link the program object and print out the info log
|
357
|
+
glLinkProgram($programObject)
|
358
|
+
linked = glGetProgramiv($programObject, GL_LINK_STATUS)
|
359
|
+
puts "Program InfoLog:\n#{glGetProgramInfoLog($programObject)}\n"
|
360
|
+
|
361
|
+
return false if linked==0
|
362
|
+
|
363
|
+
# Install program object as part of current state
|
364
|
+
glUseProgram($programObject)
|
365
|
+
|
366
|
+
# Set up initial uniform values
|
367
|
+
glUniform4f(getUniLoc($programObject, "Background"), 0.0, 0.0, 0.0, 1.0)
|
368
|
+
glUniform1f(getUniLoc($programObject, "Time"), -5.0)
|
369
|
+
|
370
|
+
return true
|
371
|
+
end
|
372
|
+
|
373
|
+
# Main
|
374
|
+
glutInit()
|
375
|
+
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE)
|
376
|
+
glutInitWindowSize(500, 500)
|
377
|
+
glutInitWindowPosition(100,100)
|
378
|
+
window = glutCreateWindow("3Dlabs OpenGL Shading Language Particle System Demo")
|
379
|
+
|
380
|
+
glutIdleFunc(play)
|
381
|
+
glutDisplayFunc(display)
|
382
|
+
glutKeyboardFunc(key)
|
383
|
+
glutReshapeFunc(reshape)
|
384
|
+
glutMotionFunc(motion)
|
385
|
+
glutMouseFunc(mouse)
|
386
|
+
glutSpecialFunc(special)
|
387
|
+
glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
|
388
|
+
|
389
|
+
# Make sure that OpenGL 2.0 is supported by the driver
|
390
|
+
if Gl.is_available?(2.0)==false
|
391
|
+
major,minor,*rest = glGetString(GL_VERSION).split(/\.| /)
|
392
|
+
puts "GL_VERSION major=#{major} minor=#{minor}"
|
393
|
+
puts "Support for OpenGL 2.0 is required for this demo...exiting"
|
394
|
+
exit(1)
|
395
|
+
end
|
396
|
+
|
397
|
+
createPoints(100, 100)
|
398
|
+
|
399
|
+
glDepthFunc(GL_LESS)
|
400
|
+
glEnable(GL_DEPTH_TEST)
|
401
|
+
nextClearColor()
|
402
|
+
|
403
|
+
key.call('?', 0, 0)
|
404
|
+
|
405
|
+
success = installParticleShaders("particle.vert", "particle.frag")
|
406
|
+
if (success)
|
407
|
+
glutMainLoop()
|
408
|
+
end
|