opengl 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +2 -1
  5. data/.travis.yml +19 -0
  6. data/History.rdoc +26 -0
  7. data/Manifest.txt +3 -23
  8. data/README.rdoc +43 -37
  9. data/Rakefile +6 -62
  10. data/examples/NeHe/nehe_lesson02.rb +3 -2
  11. data/examples/NeHe/nehe_lesson03.rb +3 -2
  12. data/examples/NeHe/nehe_lesson04.rb +3 -1
  13. data/examples/NeHe/nehe_lesson05.rb +4 -1
  14. data/examples/NeHe/nehe_lesson06.rb +9 -6
  15. data/examples/NeHe/nehe_lesson07.rb +9 -6
  16. data/examples/NeHe/nehe_lesson08.rb +9 -6
  17. data/examples/NeHe/nehe_lesson09.rb +10 -6
  18. data/examples/NeHe/nehe_lesson11.rb +9 -6
  19. data/examples/NeHe/nehe_lesson12.rb +9 -6
  20. data/examples/NeHe/nehe_lesson16.rb +50 -47
  21. data/examples/NeHe/nehe_lesson19.rb +10 -7
  22. data/examples/NeHe/nehe_lesson36.rb +234 -229
  23. data/examples/OrangeBook/brick.rb +227 -225
  24. data/examples/OrangeBook/particle.rb +233 -231
  25. data/examples/RedBook/aapoly.rb +71 -70
  26. data/examples/RedBook/aargb.rb +54 -52
  27. data/examples/RedBook/accanti.rb +96 -94
  28. data/examples/RedBook/accpersp.rb +106 -104
  29. data/examples/RedBook/alpha.rb +54 -52
  30. data/examples/RedBook/alpha3D.rb +90 -88
  31. data/examples/RedBook/bezcurve.rb +48 -46
  32. data/examples/RedBook/bezmesh.rb +71 -69
  33. data/examples/RedBook/checker.rb +57 -55
  34. data/examples/RedBook/clip.rb +41 -39
  35. data/examples/RedBook/colormat.rb +72 -70
  36. data/examples/RedBook/cube.rb +39 -37
  37. data/examples/RedBook/depthcue.rb +37 -35
  38. data/examples/RedBook/dof.rb +110 -109
  39. data/examples/RedBook/double.rb +40 -38
  40. data/examples/RedBook/drawf.rb +30 -28
  41. data/examples/RedBook/feedback.rb +79 -77
  42. data/examples/RedBook/fog.rb +90 -89
  43. data/examples/RedBook/font.rb +78 -76
  44. data/examples/RedBook/hello.rb +29 -27
  45. data/examples/RedBook/image.rb +57 -55
  46. data/examples/RedBook/jitter.rb +131 -131
  47. data/examples/RedBook/light.rb +2 -1
  48. data/examples/RedBook/lines.rb +70 -68
  49. data/examples/RedBook/list.rb +48 -46
  50. data/examples/RedBook/material.rb +200 -199
  51. data/examples/RedBook/mipmap.rb +84 -82
  52. data/examples/RedBook/model.rb +55 -53
  53. data/examples/RedBook/movelight.rb +52 -50
  54. data/examples/RedBook/pickdepth.rb +103 -101
  55. data/examples/RedBook/planet.rb +46 -44
  56. data/examples/RedBook/quadric.rb +97 -95
  57. data/examples/RedBook/robot.rb +55 -53
  58. data/examples/RedBook/select.rb +118 -116
  59. data/examples/RedBook/smooth.rb +35 -33
  60. data/examples/RedBook/stencil.rb +96 -94
  61. data/examples/RedBook/stroke.rb +75 -73
  62. data/examples/RedBook/surface.rb +93 -91
  63. data/examples/RedBook/teaambient.rb +71 -69
  64. data/examples/RedBook/teapots.rb +105 -103
  65. data/examples/RedBook/tess.rb +96 -94
  66. data/examples/RedBook/texbind.rb +79 -77
  67. data/examples/RedBook/texgen.rb +88 -86
  68. data/examples/RedBook/texturesurf.rb +57 -55
  69. data/examples/RedBook/varray.rb +85 -83
  70. data/examples/RedBook/wrap.rb +76 -74
  71. data/examples/misc/OGLBench.rb +114 -113
  72. data/examples/misc/anisotropic.rb +154 -152
  73. data/examples/misc/fbo_test.rb +37 -36
  74. data/examples/misc/font-glut.rb +47 -46
  75. data/examples/misc/glfwtest.rb +16 -16
  76. data/examples/misc/plane.rb +13 -13
  77. data/examples/misc/readpixel.rb +66 -65
  78. data/examples/misc/sdltest.rb +21 -19
  79. data/examples/misc/trislam.rb +548 -547
  80. data/ext/opengl/common.h +16 -38
  81. data/ext/opengl/conv.h +39 -41
  82. data/ext/opengl/extconf.rb +4 -31
  83. data/ext/opengl/funcdef.h +126 -124
  84. data/ext/opengl/gl-1.0-1.1.c +1917 -1917
  85. data/ext/opengl/gl-1.2.c +4 -667
  86. data/ext/opengl/gl-1.3.c +9 -9
  87. data/ext/opengl/gl-1.4.c +8 -8
  88. data/ext/opengl/gl-1.5.c +1 -1
  89. data/ext/opengl/gl-2.0.c +392 -388
  90. data/ext/opengl/gl-3.0.c +493 -0
  91. data/ext/opengl/gl-enums.c +1523 -5
  92. data/ext/opengl/gl-enums.h +4679 -122
  93. data/ext/opengl/gl-error.c +7 -7
  94. data/ext/opengl/gl-error.h +4 -4
  95. data/ext/opengl/gl-ext-arb.c +468 -464
  96. data/ext/opengl/gl-ext-ext.c +18 -18
  97. data/ext/opengl/gl-ext-nv.c +15 -15
  98. data/ext/opengl/gl.c +2 -0
  99. data/ext/opengl/gl_buffer.c +92 -92
  100. data/ext/opengl/opengl.c +1 -7
  101. data/lib/opengl.rb +23 -59
  102. data/lib/opengl/test_case.rb +1 -2
  103. data/test/dummy.xorg.conf +140 -0
  104. data/test/test_gl.rb +18 -22
  105. data/test/test_gl_10_11.rb +220 -220
  106. data/test/test_gl_12.rb +11 -122
  107. data/test/test_gl_13.rb +202 -210
  108. data/test/test_gl_14.rb +16 -19
  109. data/test/test_gl_15.rb +2 -4
  110. data/test/test_gl_20.rb +45 -58
  111. data/test/test_gl_21.rb +46 -163
  112. data/test/test_gl_ext_arb.rb +54 -72
  113. data/test/test_gl_ext_ati.rb +0 -2
  114. data/test/test_gl_ext_ext.rb +66 -66
  115. data/test/test_gl_ext_gremedy.rb +8 -15
  116. data/test/test_gl_ext_nv.rb +109 -112
  117. data/test/test_opengl_buffer.rb +8 -25
  118. data/utils/README +0 -5
  119. data/utils/enumgen.rb +72 -76
  120. data/utils/extlistgen.rb +55 -55
  121. metadata +87 -66
  122. metadata.gz.sig +2 -0
  123. data/Rakefile.cross +0 -107
  124. data/docs/build_install.txt +0 -119
  125. data/docs/extensions.txt.in +0 -348
  126. data/docs/history.txt +0 -66
  127. data/docs/requirements_and_design.txt +0 -117
  128. data/docs/roadmap.txt +0 -28
  129. data/docs/scientific_use.txt +0 -35
  130. data/docs/supplies/page_template.html +0 -71
  131. data/docs/thanks.txt +0 -29
  132. data/docs/tutorial.txt +0 -469
  133. data/ext/opengl/glu-enums.c +0 -164
  134. data/ext/opengl/glu-enums.h +0 -463
  135. data/ext/opengl/glu.c +0 -1534
  136. data/ext/opengl/glut.c +0 -1145
  137. data/ext/opengl/glut_callbacks.c +0 -845
  138. data/lib/glu.rb +0 -1
  139. data/lib/glut.rb +0 -1
  140. data/test/test_glu.rb +0 -309
  141. data/utils/mkdn2html.rb +0 -59
  142. data/utils/post-mkdn2html.rb +0 -91
  143. data/website/images/ogl.jpg +0 -0
  144. data/website/images/tab_bottom.gif +0 -0
  145. data/website/style.css +0 -198
@@ -31,6 +31,8 @@
31
31
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
32
  # POSSIBILITY OF SUCH DAMAGE.
33
33
  require 'opengl'
34
+ require 'glu'
35
+ require 'glut'
34
36
  include Gl,Glu,Glut
35
37
 
36
38
  $particleTime = 0
@@ -63,7 +65,7 @@ SCALE_FACTOR = 0.01
63
65
  SCALE_INCREMENT = 0.5
64
66
  TIMER_FREQUENCY_MILLIS = 20
65
67
 
66
- VELOCITY_ARRAY = 3
68
+ VELOCITY_ARRAY = 5
67
69
  START_TIME_ARRAY = 4
68
70
 
69
71
  $clearColor = [[0,0,0,1], [0.2,0.2,0.3,1], [0.7,0.7,0.7,1]]
@@ -75,158 +77,158 @@ $velocities = []
75
77
  $startTimes = []
76
78
 
77
79
  def nextClearColor
78
- glClearColor($clearColor[0][0],
79
- $clearColor[0][1],
80
- $clearColor[0][2],
81
- $clearColor[0][3])
82
- $clearColor << $clearColor.shift # rotate
80
+ glClearColor($clearColor[0][0],
81
+ $clearColor[0][1],
82
+ $clearColor[0][2],
83
+ $clearColor[0][3])
84
+ $clearColor << $clearColor.shift # rotate
83
85
  end
84
86
 
85
87
  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
88
+ loc = glGetUniformLocation(program, name)
89
+
90
+ if (loc == -1)
91
+ puts "No such uniform named #{name}"
92
+ end
93
+ return loc
92
94
  end
93
95
 
94
96
  def updateAnim
95
- location = getUniLoc($programObject,"Time")
97
+ location = getUniLoc($programObject,"Time")
96
98
 
97
- $particleTime += 0.002
98
- if $particleTime > 15.0
99
- $particleTime = 0.0
100
- end
99
+ $particleTime += 0.002
100
+ if $particleTime > 15.0
101
+ $particleTime = 0.0
102
+ end
101
103
 
102
- glUniform1f(location,$particleTime)
104
+ glUniform1f(location,$particleTime)
103
105
  end
104
106
 
105
107
  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)
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)
123
125
  end
124
126
 
125
127
  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
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
162
164
  end
163
165
 
164
166
  play = lambda do
165
- thisTime = glutGet(GLUT_ELAPSED_TIME)
166
- updateAnim()
167
- glutPostRedisplay()
167
+ thisTime = glutGet(GLUT_ELAPSED_TIME)
168
+ updateAnim()
169
+ glutPostRedisplay()
168
170
  end
169
171
 
170
172
  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()
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()
186
188
  end
187
189
 
188
190
  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
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
205
207
 
206
208
  # 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
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
225
227
  end
226
228
 
227
229
  reshape = lambda do |w,h|
228
230
  vp = 0.8
229
- aspect = w/h
231
+ aspect = w/h
230
232
 
231
233
  glViewport(0, 0, w, h)
232
234
  glMatrixMode(GL_PROJECTION)
@@ -240,132 +242,132 @@ reshape = lambda do |w,h|
240
242
  end
241
243
 
242
244
  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
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
260
262
  end
261
263
 
262
264
  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
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
288
290
  end
289
291
 
290
292
  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
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
311
313
  end
312
314
 
313
315
  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)
316
+ $ftime += 0.01
317
+ if $rotate
318
+ $fXDiff += $fXInertia
319
+ $fYDiff += $fYInertia
320
+ end
321
+ glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
320
322
  end
321
323
 
322
324
  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)
325
+ # Create a vertex shader object and a fragment shader object
326
+ $vertexShaderObject = glCreateShader(GL_VERTEX_SHADER)
327
+ $fragmentShaderObject = glCreateShader(GL_FRAGMENT_SHADER)
326
328
 
327
- # Load source code strings into shaders
328
- glShaderSource($vertexShaderObject, File.read(vs_name))
329
- glShaderSource($fragmentShaderObject, File.read(fs_name))
329
+ # Load source code strings into shaders
330
+ glShaderSource($vertexShaderObject, File.read(vs_name))
331
+ glShaderSource($fragmentShaderObject, File.read(fs_name))
330
332
 
331
- # Compile the particle vertex shader, and print out
332
- # the compiler log file.
333
- glCompileShader($vertexShaderObject)
333
+ # Compile the particle vertex shader, and print out
334
+ # the compiler log file.
335
+ glCompileShader($vertexShaderObject)
334
336
  vertCompiled = glGetShaderiv($vertexShaderObject, GL_COMPILE_STATUS)
335
- puts "Shader InfoLog:\n#{glGetShaderInfoLog($vertexShaderObject)}\n"
337
+ puts "Shader InfoLog:\n#{glGetShaderInfoLog($vertexShaderObject)}\n"
336
338
 
337
- # Compile the particle fragment shader, and print out
338
- # the compiler log file.
339
- glCompileShader($fragmentShaderObject)
339
+ # Compile the particle fragment shader, and print out
340
+ # the compiler log file.
341
+ glCompileShader($fragmentShaderObject)
340
342
  fragCompiled = glGetShaderiv($fragmentShaderObject, GL_COMPILE_STATUS)
341
- puts "Shader InfoLog:\n#{glGetShaderInfoLog($fragmentShaderObject)}\n"
343
+ puts "Shader InfoLog:\n#{glGetShaderInfoLog($fragmentShaderObject)}\n"
342
344
 
343
- return false if (vertCompiled == 0 || fragCompiled == 0)
345
+ return false if (vertCompiled == 0 || fragCompiled == 0)
344
346
 
345
- # Create a program object and attach the two compiled shaders
346
- $programObject = glCreateProgram()
347
- glAttachShader($programObject, $vertexShaderObject)
348
- glAttachShader($programObject, $fragmentShaderObject)
347
+ # Create a program object and attach the two compiled shaders
348
+ $programObject = glCreateProgram()
349
+ glAttachShader($programObject, $vertexShaderObject)
350
+ glAttachShader($programObject, $fragmentShaderObject)
349
351
 
350
- #Bind generic attribute indices to attribute variable names
351
- glBindAttribLocation($programObject, VELOCITY_ARRAY, "Velocity")
352
- glBindAttribLocation($programObject, START_TIME_ARRAY, "StartTime");
352
+ #Bind generic attribute indices to attribute variable names
353
+ glBindAttribLocation($programObject, VELOCITY_ARRAY, "Velocity")
354
+ glBindAttribLocation($programObject, START_TIME_ARRAY, "StartTime")
353
355
 
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"
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"
358
360
 
359
- return false if linked==0
361
+ return false if linked==0
360
362
 
361
- # Install program object as part of current state
362
- glUseProgram($programObject)
363
+ # Install program object as part of current state
364
+ glUseProgram($programObject)
363
365
 
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)
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)
367
369
 
368
- return true
370
+ return true
369
371
  end
370
372
 
371
373
  # Main
@@ -374,7 +376,7 @@ glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE)
374
376
  glutInitWindowSize(500, 500)
375
377
  glutInitWindowPosition(100,100)
376
378
  window = glutCreateWindow("3Dlabs OpenGL Shading Language Particle System Demo")
377
-
379
+
378
380
  glutIdleFunc(play)
379
381
  glutDisplayFunc(display)
380
382
  glutKeyboardFunc(key)
@@ -386,10 +388,10 @@ glutTimerFunc(TIMER_FREQUENCY_MILLIS , timer, 0)
386
388
 
387
389
  # Make sure that OpenGL 2.0 is supported by the driver
388
390
  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)
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)
393
395
  end
394
396
 
395
397
  createPoints(100, 100)
@@ -402,5 +404,5 @@ key.call('?', 0, 0)
402
404
 
403
405
  success = installParticleShaders("particle.vert", "particle.frag")
404
406
  if (success)
405
- glutMainLoop()
407
+ glutMainLoop()
406
408
  end