ruby-opengl 0.40.1 → 0.50.0

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