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.
Files changed (117) hide show
  1. data/Rakefile +80 -0
  2. data/examples/NeHe/nehe_lesson02.rb +117 -0
  3. data/examples/NeHe/nehe_lesson03.rb +122 -0
  4. data/examples/NeHe/nehe_lesson04.rb +133 -0
  5. data/examples/NeHe/nehe_lesson05.rb +186 -0
  6. data/examples/NeHe/nehe_lesson36.rb +303 -0
  7. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  8. data/examples/OrangeBook/brick.frag +36 -0
  9. data/examples/OrangeBook/brick.rb +376 -0
  10. data/examples/OrangeBook/brick.vert +41 -0
  11. data/examples/OrangeBook/particle.frag +17 -0
  12. data/examples/OrangeBook/particle.rb +406 -0
  13. data/examples/OrangeBook/particle.vert +38 -0
  14. data/examples/README +16 -0
  15. data/examples/RedBook/aapoly.rb +142 -0
  16. data/examples/RedBook/aargb.rb +119 -0
  17. data/examples/RedBook/accanti.rb +162 -0
  18. data/examples/RedBook/accpersp.rb +215 -0
  19. data/examples/RedBook/alpha.rb +123 -0
  20. data/examples/RedBook/alpha3D.rb +158 -0
  21. data/examples/RedBook/bezcurve.rb +105 -0
  22. data/examples/RedBook/bezmesh.rb +137 -0
  23. data/examples/RedBook/checker.rb +124 -0
  24. data/examples/RedBook/clip.rb +95 -0
  25. data/examples/RedBook/colormat.rb +135 -0
  26. data/examples/RedBook/cube.rb +69 -0
  27. data/examples/RedBook/depthcue.rb +99 -0
  28. data/examples/RedBook/dof.rb +205 -0
  29. data/examples/RedBook/double.rb +105 -0
  30. data/examples/RedBook/drawf.rb +91 -0
  31. data/examples/RedBook/feedback.rb +145 -0
  32. data/examples/RedBook/fog.rb +167 -0
  33. data/examples/RedBook/font.rb +151 -0
  34. data/examples/RedBook/hello.rb +79 -0
  35. data/examples/RedBook/image.rb +137 -0
  36. data/examples/RedBook/jitter.rb +207 -0
  37. data/examples/RedBook/lines.rb +128 -0
  38. data/examples/RedBook/list.rb +111 -0
  39. data/examples/RedBook/material.rb +275 -0
  40. data/examples/RedBook/mipmap.rb +156 -0
  41. data/examples/RedBook/model.rb +113 -0
  42. data/examples/RedBook/movelight.rb +132 -0
  43. data/examples/RedBook/pickdepth.rb +179 -0
  44. data/examples/RedBook/planet.rb +108 -0
  45. data/examples/RedBook/quadric.rb +158 -0
  46. data/examples/RedBook/robot.rb +115 -0
  47. data/examples/RedBook/select.rb +196 -0
  48. data/examples/RedBook/smooth.rb +95 -0
  49. data/examples/RedBook/stencil.rb +163 -0
  50. data/examples/RedBook/stroke.rb +167 -0
  51. data/examples/RedBook/surface.rb +166 -0
  52. data/examples/RedBook/teaambient.rb +132 -0
  53. data/examples/RedBook/teapots.rb +182 -0
  54. data/examples/RedBook/tess.rb +183 -0
  55. data/examples/RedBook/texbind.rb +147 -0
  56. data/examples/RedBook/texgen.rb +169 -0
  57. data/examples/RedBook/texturesurf.rb +128 -0
  58. data/examples/RedBook/varray.rb +159 -0
  59. data/examples/RedBook/wrap.rb +148 -0
  60. data/examples/misc/OGLBench.rb +337 -0
  61. data/examples/misc/anisotropic.rb +194 -0
  62. data/examples/misc/fbo_test.rb +356 -0
  63. data/examples/misc/font-glut.rb +46 -0
  64. data/examples/misc/glfwtest.rb +30 -0
  65. data/examples/misc/plane.rb +161 -0
  66. data/examples/misc/readpixel.rb +65 -0
  67. data/examples/misc/sdltest.rb +34 -0
  68. data/examples/misc/trislam.rb +828 -0
  69. data/ext/common/common.h +423 -0
  70. data/ext/common/conv.h +243 -0
  71. data/ext/common/funcdef.h +280 -0
  72. data/ext/common/gl-enums.h +10031 -0
  73. data/ext/common/gl-error.h +23 -0
  74. data/ext/common/gl-types.h +63 -0
  75. data/ext/common/glu-enums.h +463 -0
  76. data/ext/gl/gl-1.0-1.1.c +2811 -0
  77. data/ext/gl/gl-1.2.c +814 -0
  78. data/ext/gl/gl-1.3.c +443 -0
  79. data/ext/gl/gl-1.4.c +348 -0
  80. data/ext/gl/gl-1.5.c +225 -0
  81. data/ext/gl/gl-2.0.c +657 -0
  82. data/ext/gl/gl-2.1.c +57 -0
  83. data/ext/gl/gl-enums.c +3354 -0
  84. data/ext/gl/gl-error.c +104 -0
  85. data/ext/gl/gl-ext-3dfx.c +27 -0
  86. data/ext/gl/gl-ext-arb.c +866 -0
  87. data/ext/gl/gl-ext-ati.c +41 -0
  88. data/ext/gl/gl-ext-ext.c +889 -0
  89. data/ext/gl/gl-ext-gremedy.c +41 -0
  90. data/ext/gl/gl-ext-nv.c +679 -0
  91. data/ext/gl/gl.c +214 -0
  92. data/ext/gl/mkrf_conf.rb +37 -0
  93. data/ext/glu/glu-enums.c +164 -0
  94. data/ext/glu/glu.c +1530 -0
  95. data/ext/glu/mkrf_conf.rb +39 -0
  96. data/ext/glut/glut.c +1627 -0
  97. data/ext/glut/mkrf_conf.rb +37 -0
  98. data/lib/opengl.rb +84 -0
  99. data/test/README +10 -0
  100. data/test/tc_common.rb +98 -0
  101. data/test/tc_ext_arb.rb +467 -0
  102. data/test/tc_ext_ati.rb +33 -0
  103. data/test/tc_ext_ext.rb +551 -0
  104. data/test/tc_ext_gremedy.rb +36 -0
  105. data/test/tc_ext_nv.rb +357 -0
  106. data/test/tc_func_10_11.rb +1281 -0
  107. data/test/tc_func_12.rb +186 -0
  108. data/test/tc_func_13.rb +229 -0
  109. data/test/tc_func_14.rb +197 -0
  110. data/test/tc_func_15.rb +270 -0
  111. data/test/tc_func_20.rb +346 -0
  112. data/test/tc_func_21.rb +541 -0
  113. data/test/tc_glu.rb +310 -0
  114. data/test/tc_include_gl.rb +35 -0
  115. data/test/tc_misc.rb +54 -0
  116. data/test/tc_require_gl.rb +34 -0
  117. metadata +164 -0
@@ -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,376 @@
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, ?\e # esc
160
+ exit(0)
161
+ when ?t
162
+ $gleModel << $gleModel.shift # rotate the array
163
+ when ?\s # space
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 getUniLoc(program, name)
290
+ loc = glGetUniformLocation(program, name)
291
+
292
+ if (loc == -1)
293
+ puts "No such uniform named #{name}"
294
+ end
295
+ return loc
296
+ end
297
+
298
+ def installBrickShaders(vs_fname,fs_fname)
299
+ # Create a vertex shader object and a fragment shader object
300
+ brickVS = glCreateShader(GL_VERTEX_SHADER)
301
+ brickFS = glCreateShader(GL_FRAGMENT_SHADER)
302
+
303
+ # Load source code strings into shaders
304
+ glShaderSource(brickVS, File.read(vs_fname))
305
+ glShaderSource(brickFS, File.read(fs_fname))
306
+
307
+ # Compile the brick vertex shader, and print out
308
+ # the compiler log file.
309
+ glCompileShader(brickVS)
310
+ vertCompiled = glGetShaderiv(brickVS, GL_COMPILE_STATUS)
311
+ puts "Shader InfoLog:\n#{glGetShaderInfoLog(brickVS)}\n"
312
+
313
+ # Compile the brick fragment shader, and print out
314
+ # the compiler log file.
315
+ glCompileShader(brickFS)
316
+ fragCompiled = glGetShaderiv(brickFS, GL_COMPILE_STATUS)
317
+ puts "Shader InfoLog:\n#{glGetShaderInfoLog(brickFS)}\n"
318
+
319
+ return false if (vertCompiled == 0 || fragCompiled == 0)
320
+ # Create a program object and attach the two compiled shaders
321
+ brickProg = glCreateProgram()
322
+ glAttachShader(brickProg,brickVS)
323
+ glAttachShader(brickProg,brickFS)
324
+ # Link the program object and print out the info log
325
+ glLinkProgram(brickProg)
326
+ linked = glGetProgramiv(brickProg,GL_LINK_STATUS)
327
+ puts "Program InfoLog:\n#{glGetProgramInfoLog(brickProg)}\n"
328
+ return false if linked==0
329
+
330
+ # Install program object as part of current state
331
+ glUseProgram(brickProg)
332
+
333
+ # Set up initial uniform values
334
+ glUniform3f(getUniLoc(brickProg, "BrickColor"), 1.0, 0.3, 0.2)
335
+ glUniform3f(getUniLoc(brickProg, "MortarColor"), 0.85, 0.86, 0.84)
336
+ glUniform2f(getUniLoc(brickProg, "BrickSize"), 0.30, 0.15)
337
+ glUniform2f(getUniLoc(brickProg, "BrickPct"), 0.90, 0.85)
338
+ glUniform3f(getUniLoc(brickProg, "LightPosition"), 0.0, 0.0, 4.0)
339
+
340
+ return true
341
+ end
342
+
343
+ # Main
344
+
345
+ glutInit()
346
+ glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE)
347
+ glutInitWindowPosition(100,100)
348
+ glutInitWindowSize(500, 500)
349
+ glutCreateWindow( "3Dlabs Brick Shader")
350
+
351
+ glutIdleFunc(play)
352
+ glutDisplayFunc(display)
353
+ glutKeyboardFunc(key)
354
+ glutReshapeFunc(reshape)
355
+ glutMotionFunc(motion)
356
+ glutMouseFunc(mouse)
357
+ glutSpecialFunc(special)
358
+ glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
359
+
360
+ # Make sure that OpenGL 2.0 is supported by the driver
361
+ if Gl.is_available?(2.0)==false
362
+ major,minor,*rest = glGetString(GL_VERSION).split(/\.| /)
363
+ puts "GL_VERSION major=#{major} minor=#{minor}"
364
+ puts "Support for OpenGL 2.0 is required for this demo...exiting"
365
+ exit(1)
366
+ end
367
+
368
+ glDepthFunc(GL_LESS)
369
+ glEnable(GL_DEPTH_TEST)
370
+
371
+ nextClearColor()
372
+
373
+ key.call('?', 0, 0)
374
+
375
+ success = installBrickShaders("brick.vert","brick.frag")
376
+ glutMainLoop() if success == true
@@ -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
+ }