opengl 0.8.0-x86-mingw32 → 0.9.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +2 -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/1.9/opengl.so +0 -0
  103. data/lib/opengl/2.0/opengl.so +0 -0
  104. data/lib/opengl/2.1/opengl.so +0 -0
  105. data/lib/opengl/test_case.rb +1 -2
  106. data/test/dummy.xorg.conf +140 -0
  107. data/test/test_gl.rb +18 -22
  108. data/test/test_gl_10_11.rb +220 -220
  109. data/test/test_gl_12.rb +11 -122
  110. data/test/test_gl_13.rb +202 -210
  111. data/test/test_gl_14.rb +16 -19
  112. data/test/test_gl_15.rb +2 -4
  113. data/test/test_gl_20.rb +45 -58
  114. data/test/test_gl_21.rb +46 -163
  115. data/test/test_gl_ext_arb.rb +54 -72
  116. data/test/test_gl_ext_ati.rb +0 -2
  117. data/test/test_gl_ext_ext.rb +66 -66
  118. data/test/test_gl_ext_gremedy.rb +8 -15
  119. data/test/test_gl_ext_nv.rb +109 -112
  120. data/test/test_opengl_buffer.rb +8 -25
  121. data/utils/README +0 -5
  122. data/utils/enumgen.rb +72 -76
  123. data/utils/extlistgen.rb +55 -55
  124. metadata +90 -67
  125. metadata.gz.sig +0 -0
  126. data/Rakefile.cross +0 -107
  127. data/docs/build_install.txt +0 -119
  128. data/docs/extensions.txt.in +0 -348
  129. data/docs/history.txt +0 -66
  130. data/docs/requirements_and_design.txt +0 -117
  131. data/docs/roadmap.txt +0 -28
  132. data/docs/scientific_use.txt +0 -35
  133. data/docs/supplies/page_template.html +0 -71
  134. data/docs/thanks.txt +0 -29
  135. data/docs/tutorial.txt +0 -469
  136. data/ext/opengl/glu-enums.c +0 -164
  137. data/ext/opengl/glu-enums.h +0 -463
  138. data/ext/opengl/glu.c +0 -1534
  139. data/ext/opengl/glut.c +0 -1145
  140. data/ext/opengl/glut_callbacks.c +0 -845
  141. data/lib/glu.rb +0 -1
  142. data/lib/glut.rb +0 -1
  143. data/lib/opengl/opengl.so +0 -0
  144. data/test/test_glu.rb +0 -309
  145. data/utils/mkdn2html.rb +0 -59
  146. data/utils/post-mkdn2html.rb +0 -91
  147. data/website/images/ogl.jpg +0 -0
  148. data/website/images/tab_bottom.gif +0 -0
  149. data/website/style.css +0 -198
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson07
6
9
  include Gl
@@ -186,7 +189,7 @@ class Lesson07
186
189
  @filter %= 3
187
190
 
188
191
  puts "texture #{@filter}"
189
- when 'F' then
192
+ when 'F' then
190
193
  @fullscreen = !@fullscreen
191
194
 
192
195
  if @fullscreen then
@@ -208,11 +211,12 @@ class Lesson07
208
211
  end
209
212
 
210
213
  def load_texture
211
- png = PNG.load_file File.expand_path('../crate.png', __FILE__)
214
+ png = ChunkyPNG::Image.from_file(File.expand_path('../crate.png', __FILE__))
215
+
212
216
  height = png.height
213
217
  width = png.width
214
218
 
215
- image = png.data.flatten.map { |c| c.values }.join
219
+ image = png.to_rgba_stream
216
220
 
217
221
  @textures = glGenTextures 3
218
222
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -234,4 +238,3 @@ class Lesson07
234
238
  end
235
239
 
236
240
  Lesson07.new
237
-
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson08
6
9
  include Gl
@@ -189,7 +192,7 @@ class Lesson08
189
192
  @filter %= 3
190
193
 
191
194
  puts "texture #{@filter}"
192
- when 'F' then
195
+ when 'F' then
193
196
  @fullscreen = !@fullscreen
194
197
 
195
198
  if @fullscreen then
@@ -223,11 +226,12 @@ class Lesson08
223
226
  end
224
227
 
225
228
  def load_texture
226
- png = PNG.load_file File.expand_path('../glass.png', __FILE__)
229
+ png = ChunkyPNG::Image.from_file(File.expand_path('../glass.png', __FILE__))
230
+
227
231
  height = png.height
228
232
  width = png.width
229
233
 
230
- image = png.data.flatten.map { |c| c.values }.join
234
+ image = png.to_rgba_stream
231
235
 
232
236
  @textures = glGenTextures 3
233
237
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -249,4 +253,3 @@ class Lesson08
249
253
  end
250
254
 
251
255
  Lesson08.new
252
-
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson09
6
9
  include Gl
@@ -141,7 +144,7 @@ class Lesson09
141
144
  when ?\e then
142
145
  glutDestroyWindow @window
143
146
  exit 0
144
- when 'F' then
147
+ when 'F' then
145
148
  @fullscreen = !@fullscreen
146
149
 
147
150
  if @fullscreen then
@@ -170,11 +173,13 @@ class Lesson09
170
173
  end
171
174
 
172
175
  def load_texture
173
- png = PNG.load_file File.expand_path('../star.png', __FILE__)
176
+
177
+ png = ChunkyPNG::Image.from_file(File.expand_path('../star.png', __FILE__))
178
+
174
179
  height = png.height
175
180
  width = png.width
176
181
 
177
- image = png.data.flatten.map { |c| c.values }.join
182
+ image = png.to_rgba_stream
178
183
 
179
184
  @textures = glGenTextures 3
180
185
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -196,4 +201,3 @@ class Lesson09
196
201
  end
197
202
 
198
203
  Lesson09.new
199
-
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson11
6
9
  include Gl
@@ -140,7 +143,7 @@ class Lesson11
140
143
  when ?\e
141
144
  glutDestroyWindow @window
142
145
  exit 0
143
- when 'F' then
146
+ when 'F' then
144
147
  @fullscreen = !@fullscreen
145
148
 
146
149
  if @fullscreen then
@@ -154,11 +157,12 @@ class Lesson11
154
157
  end
155
158
 
156
159
  def load_texture
157
- png = PNG.load_file File.expand_path('../tim.png', __FILE__)
160
+ png = ChunkyPNG::Image.from_file(File.expand_path('../tim.png', __FILE__))
161
+
158
162
  height = png.height
159
163
  width = png.width
160
164
 
161
- image = png.data.flatten.map { |c| c.values }.join
165
+ image = png.to_rgba_stream.each_byte.to_a
162
166
 
163
167
  @textures = glGenTextures 1
164
168
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -170,4 +174,3 @@ class Lesson11
170
174
  end
171
175
 
172
176
  Lesson11.new
173
-
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson12
6
9
  include Gl
@@ -163,7 +166,7 @@ class Lesson12
163
166
  when ?\e
164
167
  glutDestroyWindow @window
165
168
  exit 0
166
- when 'F' then
169
+ when 'F' then
167
170
  @fullscreen = !@fullscreen
168
171
 
169
172
  if @fullscreen then
@@ -181,11 +184,12 @@ class Lesson12
181
184
  end
182
185
 
183
186
  def load_texture
184
- png = PNG.load_file File.expand_path('../crate.png', __FILE__)
187
+ png = ChunkyPNG::Image.from_file(File.expand_path('../crate.png', __FILE__))
188
+
185
189
  height = png.height
186
190
  width = png.width
187
191
 
188
- image = png.data.flatten.map { |c| c.values }.join
192
+ image = png.to_rgba_stream.each_byte.to_a
189
193
 
190
194
  @textures = glGenTextures 1
191
195
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -197,4 +201,3 @@ class Lesson12
197
201
  end
198
202
 
199
203
  Lesson12.new
200
-
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson16
6
9
  include Gl
@@ -16,9 +19,9 @@ class Lesson16
16
19
  @filter = 0
17
20
 
18
21
  @fog_mode = [
19
- GL_EXP,
20
- GL_EXP2,
21
- GL_LINEAR
22
+ GL_EXP,
23
+ GL_EXP2,
24
+ GL_LINEAR
22
25
  ]
23
26
 
24
27
  @fog_filter = 0
@@ -64,7 +67,7 @@ class Lesson16
64
67
  end
65
68
 
66
69
  def reshape width, height
67
- width = width.to_f
70
+ width = width.to_f
68
71
  height = height.to_f
69
72
  height = 1.0 if height.zero?
70
73
 
@@ -94,63 +97,63 @@ class Lesson16
94
97
  glBegin GL_QUADS do
95
98
  # front face
96
99
  glTexCoord2f(0.0, 1.0)
97
- glVertex3f(-1.0, -1.0, 1.0)
100
+ glVertex3f(-1.0, -1.0, 1.0)
98
101
  glTexCoord2f(1.0, 1.0)
99
- glVertex3f( 1.0, -1.0, 1.0)
102
+ glVertex3f(1.0, -1.0, 1.0)
100
103
  glTexCoord2f(1.0, 0.0)
101
- glVertex3f( 1.0, 1.0, 1.0)
104
+ glVertex3f(1.0, 1.0, 1.0)
102
105
  glTexCoord2f(0.0, 0.0)
103
- glVertex3f(-1.0, 1.0, 1.0)
106
+ glVertex3f(-1.0, 1.0, 1.0)
104
107
 
105
108
  # back face
106
109
  glTexCoord2f(0.0, 1.0)
107
110
  glVertex3f(-1.0, -1.0, -1.0)
108
111
  glTexCoord2f(1.0, 1.0)
109
- glVertex3f(-1.0, 1.0, -1.0)
112
+ glVertex3f(-1.0, 1.0, -1.0)
110
113
  glTexCoord2f(1.0, 0.0)
111
- glVertex3f( 1.0, 1.0, -1.0)
114
+ glVertex3f(1.0, 1.0, -1.0)
112
115
  glTexCoord2f(0.0, 0.0)
113
- glVertex3f( 1.0, -1.0, -1.0)
116
+ glVertex3f(1.0, -1.0, -1.0)
114
117
 
115
118
  # top face
116
119
  glTexCoord2f(0.0, 1.0)
117
- glVertex3f(-1.0, 1.0, -1.0)
120
+ glVertex3f(-1.0, 1.0, -1.0)
118
121
  glTexCoord2f(1.0, 1.0)
119
- glVertex3f(-1.0, 1.0, 1.0)
122
+ glVertex3f(-1.0, 1.0, 1.0)
120
123
  glTexCoord2f(1.0, 0.0)
121
- glVertex3f( 1.0, 1.0, 1.0)
124
+ glVertex3f(1.0, 1.0, 1.0)
122
125
  glTexCoord2f(0.0, 0.0)
123
- glVertex3f( 1.0, 1.0, -1.0)
126
+ glVertex3f(1.0, 1.0, -1.0)
124
127
 
125
128
  # bottom face
126
129
  glTexCoord2f(1.0, 1.0)
127
130
  glVertex3f(-1.0, -1.0, -1.0)
128
131
  glTexCoord2f(1.0, 0.0)
129
- glVertex3f( 1.0, -1.0, -1.0)
132
+ glVertex3f(1.0, -1.0, -1.0)
130
133
  glTexCoord2f(0.0, 0.0)
131
- glVertex3f( 1.0, -1.0, 1.0)
134
+ glVertex3f(1.0, -1.0, 1.0)
132
135
  glTexCoord2f(0.0, 1.0)
133
- glVertex3f(-1.0, -1.0, 1.0)
136
+ glVertex3f(-1.0, -1.0, 1.0)
134
137
 
135
138
  # right face
136
139
  glTexCoord2f(1.0, 0.0)
137
- glVertex3f( 1.0, -1.0, -1.0)
140
+ glVertex3f(1.0, -1.0, -1.0)
138
141
  glTexCoord2f(0.0, 0.0)
139
- glVertex3f( 1.0, 1.0, -1.0)
142
+ glVertex3f(1.0, 1.0, -1.0)
140
143
  glTexCoord2f(0.0, 1.0)
141
- glVertex3f( 1.0, 1.0, 1.0)
144
+ glVertex3f(1.0, 1.0, 1.0)
142
145
  glTexCoord2f(1.0, 1.0)
143
- glVertex3f( 1.0, -1.0, 1.0)
146
+ glVertex3f(1.0, -1.0, 1.0)
144
147
 
145
148
  # left face
146
149
  glTexCoord2f(0.0, 0.0)
147
150
  glVertex3f(-1.0, -1.0, -1.0)
148
151
  glTexCoord2f(0.0, 1.0)
149
- glVertex3f(-1.0, -1.0, 1.0)
152
+ glVertex3f(-1.0, -1.0, 1.0)
150
153
  glTexCoord2f(1.0, 1.0)
151
- glVertex3f(-1.0, 1.0, 1.0)
154
+ glVertex3f(-1.0, 1.0, 1.0)
152
155
  glTexCoord2f(1.0, 0.0)
153
- glVertex3f(-1.0, 1.0, -1.0)
156
+ glVertex3f(-1.0, 1.0, -1.0)
154
157
  end
155
158
 
156
159
  @xrot += 0.03
@@ -166,34 +169,35 @@ class Lesson16
166
169
 
167
170
  def keyboard key, x, y
168
171
  case key
169
- when ?\e
170
- glutDestroyWindow @window
171
- exit 0
172
- when 'F' then
173
- @fullscreen = !@fullscreen
174
-
175
- if @fullscreen then
176
- glutFullScreen
177
- else
178
- glutPositionWindow 0, 0
179
- end
180
- when 'f' then
181
- @fog_filter += 1
182
- @fog_filter %= 3
183
-
184
- glFogi GL_FOG_MODE, @fog_mode[@fog_filter]
185
- puts "fog #{@fog_filter}"
172
+ when ?\e
173
+ glutDestroyWindow @window
174
+ exit 0
175
+ when 'F' then
176
+ @fullscreen = !@fullscreen
177
+
178
+ if @fullscreen then
179
+ glutFullScreen
180
+ else
181
+ glutPositionWindow 0, 0
182
+ end
183
+ when 'f' then
184
+ @fog_filter += 1
185
+ @fog_filter %= 3
186
+
187
+ glFogi GL_FOG_MODE, @fog_mode[@fog_filter]
188
+ puts "fog #{@fog_filter}"
186
189
  end
187
190
 
188
191
  glutPostRedisplay
189
192
  end
190
193
 
191
194
  def load_texture
192
- png = PNG.load_file File.expand_path('../crate.png', __FILE__)
195
+ png = ChunkyPNG::Image.from_file(File.expand_path('../crate.png', __FILE__))
196
+
193
197
  height = png.height
194
198
  width = png.width
195
199
 
196
- image = png.data.flatten.map { |c| c.values }.join
200
+ image = png.to_rgba_stream.each_byte.to_a
197
201
 
198
202
  @textures = glGenTextures 1
199
203
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -205,4 +209,3 @@ class Lesson16
205
209
  end
206
210
 
207
211
  Lesson16.new
208
-
@@ -1,6 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'opengl'
2
- require 'png'
3
- require 'png/reader'
4
+ require 'glu'
5
+ require 'glut'
6
+ require 'chunky_png'
4
7
 
5
8
  class Lesson19
6
9
  include Gl
@@ -110,7 +113,7 @@ class Lesson19
110
113
 
111
114
  @particles.each do |particle|
112
115
  next unless particle.active
113
-
116
+
114
117
  x = particle.x
115
118
  y = particle.y
116
119
  z = particle.z + @zoom
@@ -167,7 +170,7 @@ class Lesson19
167
170
  when ?\e
168
171
  glutDestroyWindow @window
169
172
  exit 0
170
- when 'F' then
173
+ when 'F' then
171
174
  @fullscreen = !@fullscreen
172
175
 
173
176
  if @fullscreen then
@@ -187,11 +190,12 @@ class Lesson19
187
190
  end
188
191
 
189
192
  def load_texture
190
- png = PNG.load_file File.expand_path('../particle.png', __FILE__)
193
+ png = ChunkyPNG::Image.from_file(File.expand_path('../particle.png', __FILE__))
194
+
191
195
  height = png.height
192
196
  width = png.width
193
197
 
194
- image = png.data.flatten.map { |c| c.values }.join
198
+ image = png.to_rgba_stream.each_byte.to_a
195
199
 
196
200
  @textures = glGenTextures 1
197
201
  glBindTexture GL_TEXTURE_2D, @textures[0]
@@ -203,4 +207,3 @@ class Lesson19
203
207
  end
204
208
 
205
209
  Lesson19.new
206
-
@@ -1,290 +1,295 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  # Nehe Lesson 36 Code
2
4
  # modified from immediate mode to use vertex arrays for helix drawing
3
5
  require 'opengl'
6
+ require 'glu'
7
+ require 'glut'
8
+
4
9
  include Gl,Glu,Glut
5
10
  include Math
6
11
 
7
12
  def emptyTexture
8
- # Create Storage Space For Texture Data (128x128x4)
9
- data = ([0]*4*128*128).pack("f*")
10
- txtnumber = glGenTextures(1) # Create 1 Texture
11
- glBindTexture(GL_TEXTURE_2D, txtnumber[0]) # Bind The Texture
12
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 128, 128, 0,
13
- GL_RGBA, GL_FLOAT, data) # Build Texture Using Information In data
14
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
15
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
16
- return txtnumber[0] # Return The Texture ID
13
+ # Create Storage Space For Texture Data (128x128x4)
14
+ data = ([0]*4*128*128).pack("f*")
15
+ txtnumber = glGenTextures(1) # Create 1 Texture
16
+ glBindTexture(GL_TEXTURE_2D, txtnumber[0]) # Bind The Texture
17
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 128, 128, 0,
18
+ GL_RGBA, GL_FLOAT, data) # Build Texture Using Information In data
19
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
20
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
21
+ return txtnumber[0] # Return The Texture ID
17
22
  end
18
23
 
19
24
  def init
20
- global_ambient = [0.2, 0.2, 0.2, 1.0] # Set Ambient Lighting To Fairly Dark Light (No Color)
21
- light0pos = [0.0, 5.0, 10.0, 1.0] # Set The Light Position
22
- light0ambient = [0.2, 0.2, 0.2, 1.0] # More Ambient Light
23
- light0diffuse = [0.3, 0.3, 0.3, 1.0] # Set The Diffuse Light A Bit Brighter
24
- light0specular = [0.8, 0.8, 0.8, 1.0] # Fairly Bright Specular Lighting
25
-
26
- lmodel_ambient = [0.2,0.2,0.2,1.0] # And More Ambient Light
27
-
28
- $angle = 0.0 # Set Starting Angle To Zero
29
-
30
- $lasttime = 0
31
-
32
- $blurTexture = emptyTexture() # Create Our Empty Texture
33
-
34
- $helix_v,$helix_n = createHelix()
35
- glVertexPointer(3,GL_FLOAT,0,$helix_v.flatten.pack("f*"))
36
- glNormalPointer(GL_FLOAT,0,$helix_n.flatten.pack("f*"))
37
-
38
- glLoadIdentity() # Reset The Modelview Matrix
39
-
40
- glEnable(GL_DEPTH_TEST) # Enable Depth Testing
41
-
42
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient) # Set The Ambient Light Model
43
-
44
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT,global_ambient) # Set The Global Ambient Light Model
45
- glLightfv(GL_LIGHT0, GL_POSITION, light0pos) # Set The Lights Position
46
- glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient) # Set The Ambient Light
47
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse) # Set The Diffuse Light
48
- glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular) # Set Up Specular Lighting
49
- glEnable(GL_LIGHTING) # Enable Lighting
50
- glEnable(GL_LIGHT0) # Enable Light0
51
-
52
- glShadeModel(GL_SMOOTH) # Select Smooth Shading
53
-
54
- glMateriali(GL_FRONT, GL_SHININESS, 128)
55
- glClearColor(0.0, 0.0, 0.0, 0.5) # Set The Clear Color To Black
25
+ global_ambient = [0.2, 0.2, 0.2, 1.0] # Set Ambient Lighting To Fairly Dark Light (No Color)
26
+ light0pos = [0.0, 5.0, 10.0, 1.0] # Set The Light Position
27
+ light0ambient = [0.2, 0.2, 0.2, 1.0] # More Ambient Light
28
+ light0diffuse = [0.3, 0.3, 0.3, 1.0] # Set The Diffuse Light A Bit Brighter
29
+ light0specular = [0.8, 0.8, 0.8, 1.0] # Fairly Bright Specular Lighting
30
+
31
+ lmodel_ambient = [0.2,0.2,0.2,1.0] # And More Ambient Light
32
+
33
+ $angle = 0.0 # Set Starting Angle To Zero
34
+
35
+ $lasttime = 0
36
+
37
+ $blurTexture = emptyTexture() # Create Our Empty Texture
38
+
39
+ $helix_v,$helix_n = createHelix()
40
+ glVertexPointer(3,GL_FLOAT,0,$helix_v.flatten.pack("f*"))
41
+ glNormalPointer(GL_FLOAT,0,$helix_n.flatten.pack("f*"))
42
+
43
+ glLoadIdentity() # Reset The Modelview Matrix
44
+
45
+ glEnable(GL_DEPTH_TEST) # Enable Depth Testing
46
+
47
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient) # Set The Ambient Light Model
48
+
49
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,global_ambient) # Set The Global Ambient Light Model
50
+ glLightfv(GL_LIGHT0, GL_POSITION, light0pos) # Set The Lights Position
51
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient) # Set The Ambient Light
52
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse) # Set The Diffuse Light
53
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular) # Set Up Specular Lighting
54
+ glEnable(GL_LIGHTING) # Enable Lighting
55
+ glEnable(GL_LIGHT0) # Enable Light0
56
+
57
+ glShadeModel(GL_SMOOTH) # Select Smooth Shading
58
+
59
+ glMateriali(GL_FRONT, GL_SHININESS, 128)
60
+ glClearColor(0.0, 0.0, 0.0, 0.5) # Set The Clear Color To Black
56
61
  end
57
62
 
58
63
  # Keyboard handler to exit when ESC is typed
59
64
  keyboard = lambda do |key, x, y|
60
- case(key)
61
- when ?\e
62
- exit(0)
63
- end
64
- glutPostRedisplay
65
+ case(key)
66
+ when ?\e
67
+ exit(0)
68
+ end
69
+ glutPostRedisplay
65
70
  end
66
71
 
67
72
  reshape = lambda do |w,h|
68
- glMatrixMode(GL_PROJECTION)
69
- glViewport(0,0,w,h)
70
- glLoadIdentity()
71
- width = 0.5
72
- height = 0.5 * h/w;
73
- glFrustum(-width,width,-height,height,1.0,2000.0)
74
- glMatrixMode(GL_MODELVIEW)
75
- glViewport(0,0,w,h)
73
+ glMatrixMode(GL_PROJECTION)
74
+ glViewport(0,0,w,h)
75
+ glLoadIdentity()
76
+ width = 0.5
77
+ height = 0.5 * h/w;
78
+ glFrustum(-width,width,-height,height,1.0,2000.0)
79
+ glMatrixMode(GL_MODELVIEW)
80
+ glViewport(0,0,w,h)
76
81
  end
77
82
 
78
83
  def viewOrtho
79
- glMatrixMode(GL_PROJECTION) # Select Projection
80
- glPushMatrix() # Push The Matrix
81
- glLoadIdentity() # Reset The Matrix
82
- width = glutGet(GLUT_WINDOW_WIDTH)
83
- height = glutGet(GLUT_WINDOW_HEIGHT)
84
- glOrtho( 0, width , height , 0, -1, 1 ) # Select Ortho Mode (widthxheight)
85
- glMatrixMode(GL_MODELVIEW) # Select Modelview Matrix
86
- glPushMatrix() # Push The Matrix
87
- glLoadIdentity() # Reset The Matrix
84
+ glMatrixMode(GL_PROJECTION) # Select Projection
85
+ glPushMatrix() # Push The Matrix
86
+ glLoadIdentity() # Reset The Matrix
87
+ width = glutGet(GLUT_WINDOW_WIDTH)
88
+ height = glutGet(GLUT_WINDOW_HEIGHT)
89
+ glOrtho( 0, width , height , 0, -1, 1 ) # Select Ortho Mode (widthxheight)
90
+ glMatrixMode(GL_MODELVIEW) # Select Modelview Matrix
91
+ glPushMatrix() # Push The Matrix
92
+ glLoadIdentity() # Reset The Matrix
88
93
  end
89
94
 
90
95
  def viewPerspective # Set Up A Perspective View
91
- glMatrixMode( GL_PROJECTION ) # Select Projection
92
- glPopMatrix() # Pop The Matrix
93
- glMatrixMode( GL_MODELVIEW ) # Select Modelview
94
- glPopMatrix() # Pop The Matrix
96
+ glMatrixMode( GL_PROJECTION ) # Select Projection
97
+ glPopMatrix() # Pop The Matrix
98
+ glMatrixMode( GL_MODELVIEW ) # Select Modelview
99
+ glPopMatrix() # Pop The Matrix
95
100
  end
96
101
 
97
102
  def normalize(v)
98
- len = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
99
- return v if len==0
100
- [ v[0] / len, v[1] / len, v[2] / len ]
103
+ len = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
104
+ return v if len==0
105
+ [ v[0] / len, v[1] / len, v[2] / len ]
101
106
  end
102
107
 
103
108
  def calcNormal(v) # Calculates Normal For A Quad Using 3 Points
104
- # Finds The Vector Between 2 Points By Subtracting
105
- # The x,y,z Coordinates From One Point To Another.
106
- # Calculate The Vector From Point 1 To Point 0
107
- v1, v2, out = [], [], []
108
- x,y,z = 0,1,2
109
-
110
- v1[x] = v[0][x] - v[1][x] # Vector 1.x=Vertex[0].x-Vertex[1].x
111
- v1[y] = v[0][y] - v[1][y] # Vector 1.y=Vertex[0].y-Vertex[1].y
112
- v1[z] = v[0][z] - v[1][z] # Vector 1.z=Vertex[0].y-Vertex[1].z
113
- # Calculate The Vector From Point 2 To Point 1
114
- v2[x] = v[1][x] - v[2][x] # Vector 2.x=Vertex[0].x-Vertex[1].x
115
- v2[y] = v[1][y] - v[2][y] # Vector 2.y=Vertex[0].y-Vertex[1].y
116
- v2[z] = v[1][z] - v[2][z] # Vector 2.z=Vertex[0].z-Vertex[1].z
117
- # Compute The Cross Product To Give Us A Surface Normal
118
- out[x] = v1[y]*v2[z] - v1[z]*v2[y] # Cross Product For Y - Z
119
- out[y] = v1[z]*v2[x] - v1[x]*v2[z] # Cross Product For X - Z
120
- out[z] = v1[x]*v2[y] - v1[y]*v2[x] # Cross Product For X - Y
121
-
122
- normalize(out)
109
+ # Finds The Vector Between 2 Points By Subtracting
110
+ # The x,y,z Coordinates From One Point To Another.
111
+ # Calculate The Vector From Point 1 To Point 0
112
+ v1, v2, out = [], [], []
113
+ x,y,z = 0,1,2
114
+
115
+ v1[x] = v[0][x] - v[1][x] # Vector 1.x=Vertex[0].x-Vertex[1].x
116
+ v1[y] = v[0][y] - v[1][y] # Vector 1.y=Vertex[0].y-Vertex[1].y
117
+ v1[z] = v[0][z] - v[1][z] # Vector 1.z=Vertex[0].y-Vertex[1].z
118
+ # Calculate The Vector From Point 2 To Point 1
119
+ v2[x] = v[1][x] - v[2][x] # Vector 2.x=Vertex[0].x-Vertex[1].x
120
+ v2[y] = v[1][y] - v[2][y] # Vector 2.y=Vertex[0].y-Vertex[1].y
121
+ v2[z] = v[1][z] - v[2][z] # Vector 2.z=Vertex[0].z-Vertex[1].z
122
+ # Compute The Cross Product To Give Us A Surface Normal
123
+ out[x] = v1[y]*v2[z] - v1[z]*v2[y] # Cross Product For Y - Z
124
+ out[y] = v1[z]*v2[x] - v1[x]*v2[z] # Cross Product For X - Z
125
+ out[z] = v1[x]*v2[y] - v1[y]*v2[x] # Cross Product For X - Y
126
+
127
+ normalize(out)
123
128
  end
124
129
 
125
130
  def createHelix() # creates helix VA
126
- twists = 5
127
- r = 1.5
128
-
129
- helix_v = []
130
- helix_n = []
131
-
132
- 0.step(360,20) do |phi| # 360 Degrees In Steps Of 20
133
- 0.step(360*twists,20) do |theta| # 360 Degrees * Number Of Twists In Steps Of 20
134
- v= phi/180.0*PI # Calculate Angle Of First Point ( 0 )
135
- u= theta/180.0*PI # Calculate Angle Of First Point ( 0 )
136
-
137
- x= cos(u)*(2.0+cos(v))*r # Calculate x Position (1st Point)
138
- y= sin(u)*(2.0+cos(v))*r # Calculate y Position (1st Point)
139
- z=((u-(2.0*PI)) + sin(v))*r # Calculate z Position (1st Point)
140
-
141
- v0 = [x,y,z]
142
-
143
- v= phi/180.0*PI # Calculate Angle Of Second Point ( 0 )
144
- u= (theta+20)/180.0*PI # Calculate Angle Of Second Point ( 20 )
145
-
146
- x= cos(u)*(2.0+cos(v))*r # Calculate x Position (2nd Point)
147
- y= sin(u)*(2.0+cos(v))*r # Calculate y Position (2nd Point)
148
- z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (2nd Point)
149
-
150
- v1 = [x,y,z]
151
-
152
- v= (phi+20)/180.0*PI # Calculate Angle Of Third Point ( 20 )
153
- u= (theta+20)/180.0*PI # Calculate Angle Of Third Point ( 20 )
154
-
155
- x= cos(u)*(2.0+cos(v))*r # Calculate x Position (3rd Point)
156
- y= sin(u)*(2.0+cos(v))*r # Calculate y Position (3rd Point)
157
- z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (3rd Point)
158
-
159
- v2 = [x,y,z]
160
-
161
- v= (phi+20)/180.0*PI # Calculate Angle Of Fourth Point ( 20 )
162
- u= (theta)/180.0*PI # Calculate Angle Of Fourth Point ( 0 )
163
-
164
- x= cos(u)*(2.0+cos(v))*r # Calculate x Position (4th Point)
165
- y= sin(u)*(2.0+cos(v))*r # Calculate y Position (4th Point)
166
- z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (4th Point)
167
-
168
- v3 = [x,y,z]
169
-
170
- normal = calcNormal([v0,v1,v2,v3]) # Calculate The Quad Normal
171
- helix_v << v0 << v1 << v2 << v3
172
- helix_n << normal << normal << normal << normal
173
- end
174
- end
175
- [helix_v,helix_n]
131
+ twists = 5
132
+ r = 1.5
133
+
134
+ helix_v = []
135
+ helix_n = []
136
+
137
+ 0.step(360,20) do |phi| # 360 Degrees In Steps Of 20
138
+ 0.step(360*twists,20) do |theta| # 360 Degrees * Number Of Twists In Steps Of 20
139
+ v= phi/180.0*PI # Calculate Angle Of First Point ( 0 )
140
+ u= theta/180.0*PI # Calculate Angle Of First Point ( 0 )
141
+
142
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (1st Point)
143
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (1st Point)
144
+ z=((u-(2.0*PI)) + sin(v))*r # Calculate z Position (1st Point)
145
+
146
+ v0 = [x,y,z]
147
+
148
+ v= phi/180.0*PI # Calculate Angle Of Second Point ( 0 )
149
+ u= (theta+20)/180.0*PI # Calculate Angle Of Second Point ( 20 )
150
+
151
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (2nd Point)
152
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (2nd Point)
153
+ z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (2nd Point)
154
+
155
+ v1 = [x,y,z]
156
+
157
+ v= (phi+20)/180.0*PI # Calculate Angle Of Third Point ( 20 )
158
+ u= (theta+20)/180.0*PI # Calculate Angle Of Third Point ( 20 )
159
+
160
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (3rd Point)
161
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (3rd Point)
162
+ z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (3rd Point)
163
+
164
+ v2 = [x,y,z]
165
+
166
+ v= (phi+20)/180.0*PI # Calculate Angle Of Fourth Point ( 20 )
167
+ u= (theta)/180.0*PI # Calculate Angle Of Fourth Point ( 0 )
168
+
169
+ x= cos(u)*(2.0+cos(v))*r # Calculate x Position (4th Point)
170
+ y= sin(u)*(2.0+cos(v))*r # Calculate y Position (4th Point)
171
+ z= ((u-(2.0*PI)) + sin(v))*r # Calculate z Position (4th Point)
172
+
173
+ v3 = [x,y,z]
174
+
175
+ normal = calcNormal([v0,v1,v2,v3]) # Calculate The Quad Normal
176
+ helix_v << v0 << v1 << v2 << v3
177
+ helix_n << normal << normal << normal << normal
178
+ end
179
+ end
180
+ [helix_v,helix_n]
176
181
  end
177
182
 
178
- def processHelix() # Draws A Helix
179
- glfMaterialColor = [0.4,0.2,0.8,1.0] # Set The Material Color
180
- specular = [1.0,1.0,1.0,1.0] # Sets Up Specular Lighting
183
+ def processHelix() # Draws A Helix
184
+ glfMaterialColor = [0.4,0.2,0.8,1.0] # Set The Material Color
185
+ specular = [1.0,1.0,1.0,1.0] # Sets Up Specular Lighting
181
186
 
182
- glLoadIdentity() # Reset The Modelview Matrix
183
- gluLookAt(0, 5, 50, 0, 0, 0, 0, 1, 0) # Eye Position (0,5,50) Center Of Scene (0,0,0), Up On Y Axis
187
+ glLoadIdentity() # Reset The Modelview Matrix
188
+ gluLookAt(0, 5, 50, 0, 0, 0, 0, 1, 0) # Eye Position (0,5,50) Center Of Scene (0,0,0), Up On Y Axis
184
189
 
185
- glPushMatrix() # Push The Modelview Matrix
190
+ glPushMatrix() # Push The Modelview Matrix
186
191
 
187
- glTranslatef(0,0,-50) # Translate 50 Units Into The Screen
188
- glRotatef($angle/2.0,1,0,0) # Rotate By angle/2 On The X-Axis
189
- glRotatef($angle/3.0,0,1,0) # Rotate By angle/3 On The Y-Axis
192
+ glTranslatef(0,0,-50) # Translate 50 Units Into The Screen
193
+ glRotatef($angle/2.0,1,0,0) # Rotate By angle/2 On The X-Axis
194
+ glRotatef($angle/3.0,0,1,0) # Rotate By angle/3 On The Y-Axis
190
195
 
191
- glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,glfMaterialColor)
192
- glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular)
196
+ glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,glfMaterialColor)
197
+ glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular)
193
198
 
194
- glEnableClientState(GL_VERTEX_ARRAY)
195
- glEnableClientState(GL_NORMAL_ARRAY)
196
- glDrawArrays(GL_QUADS,0,$helix_v.size)
197
- glDisableClientState(GL_VERTEX_ARRAY)
198
- glDisableClientState(GL_NORMAL_ARRAY)
199
+ glEnableClientState(GL_VERTEX_ARRAY)
200
+ glEnableClientState(GL_NORMAL_ARRAY)
201
+ glDrawArrays(GL_QUADS,0,$helix_v.size)
202
+ glDisableClientState(GL_VERTEX_ARRAY)
203
+ glDisableClientState(GL_NORMAL_ARRAY)
199
204
 
200
- glPopMatrix() # Pop The Matrix
205
+ glPopMatrix() # Pop The Matrix
201
206
  end
202
207
 
203
208
  def drawBlur(times,inc)
204
- spost = 0.0 # Starting Texture Coordinate Offset
205
- alphainc = 0.9 / times # Fade Speed For Alpha Blending
206
- alpha = 0.2 # Starting Alpha Value
207
-
208
- width = glutGet(GLUT_WINDOW_WIDTH)
209
- height = glutGet(GLUT_WINDOW_HEIGHT)
210
- # Disable AutoTexture Coordinates
211
- glDisable(GL_TEXTURE_GEN_S)
212
- glDisable(GL_TEXTURE_GEN_T)
213
-
214
- glEnable(GL_TEXTURE_2D) # Enable 2D Texture Mapping
215
- glDisable(GL_DEPTH_TEST) # Disable Depth Testing
216
- glBlendFunc(GL_SRC_ALPHA,GL_ONE) # Set Blending Mode
217
- glEnable(GL_BLEND) # Enable Blending
218
- glBindTexture(GL_TEXTURE_2D,$blurTexture) # Bind To The Blur Texture
219
- viewOrtho() # Switch To An Ortho View
220
-
221
- alphainc = alpha / times # alphainc=0.2 / Times To Render Blur
222
-
223
- glBegin(GL_QUADS) # Begin Drawing Quads
224
- 0.upto(times-1) do |num| # Number Of Times To Render Blur
225
- glColor4f(1.0, 1.0, 1.0, alpha) # Set The Alpha Value (Starts At 0.2)
226
- glTexCoord2f(0+spost,1-spost) # Texture Coordinate ( 0, 1 )
227
- glVertex2f(0,0) # First Vertex ( 0, 0 )
228
-
229
- glTexCoord2f(0+spost,0+spost) # Texture Coordinate ( 0, 0 )
230
- glVertex2f(0,height) # Second Vertex ( 0, height )
231
-
232
- glTexCoord2f(1-spost,0+spost) # Texture Coordinate ( 1, 0 )
233
- glVertex2f(width,height) # Third Vertex ( width, height )
234
-
235
- glTexCoord2f(1-spost,1-spost) # Texture Coordinate ( 1, 1 )
236
- glVertex2f(width,0) # Fourth Vertex ( width, 0 )
237
-
238
- spost += inc # Gradually Increase spost (Zooming Closer To Texture Center)
239
- alpha = alpha - alphainc # Gradually Decrease alpha (Gradually Fading Image Out)
240
- end
241
- glEnd() # Done Drawing Quads
242
-
243
- viewPerspective() # Switch To A Perspective View
244
-
245
- glEnable(GL_DEPTH_TEST) # Enable Depth Testing
246
- glDisable(GL_TEXTURE_2D) # Disable 2D Texture Mapping
247
- glDisable(GL_BLEND) # Disable Blending
248
- glBindTexture(GL_TEXTURE_2D,0) # Unbind The Blur Texture
209
+ spost = 0.0 # Starting Texture Coordinate Offset
210
+ alphainc = 0.9 / times # Fade Speed For Alpha Blending
211
+ alpha = 0.2 # Starting Alpha Value
212
+
213
+ width = glutGet(GLUT_WINDOW_WIDTH)
214
+ height = glutGet(GLUT_WINDOW_HEIGHT)
215
+ # Disable AutoTexture Coordinates
216
+ glDisable(GL_TEXTURE_GEN_S)
217
+ glDisable(GL_TEXTURE_GEN_T)
218
+
219
+ glEnable(GL_TEXTURE_2D) # Enable 2D Texture Mapping
220
+ glDisable(GL_DEPTH_TEST) # Disable Depth Testing
221
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE) # Set Blending Mode
222
+ glEnable(GL_BLEND) # Enable Blending
223
+ glBindTexture(GL_TEXTURE_2D,$blurTexture) # Bind To The Blur Texture
224
+ viewOrtho() # Switch To An Ortho View
225
+
226
+ alphainc = alpha / times # alphainc=0.2 / Times To Render Blur
227
+
228
+ glBegin(GL_QUADS) # Begin Drawing Quads
229
+ 0.upto(times-1) do |num| # Number Of Times To Render Blur
230
+ glColor4f(1.0, 1.0, 1.0, alpha) # Set The Alpha Value (Starts At 0.2)
231
+ glTexCoord2f(0+spost,1-spost) # Texture Coordinate ( 0, 1 )
232
+ glVertex2f(0,0) # First Vertex ( 0, 0 )
233
+
234
+ glTexCoord2f(0+spost,0+spost) # Texture Coordinate ( 0, 0 )
235
+ glVertex2f(0,height) # Second Vertex ( 0, height )
236
+
237
+ glTexCoord2f(1-spost,0+spost) # Texture Coordinate ( 1, 0 )
238
+ glVertex2f(width,height) # Third Vertex ( width, height )
239
+
240
+ glTexCoord2f(1-spost,1-spost) # Texture Coordinate ( 1, 1 )
241
+ glVertex2f(width,0) # Fourth Vertex ( width, 0 )
242
+
243
+ spost += inc # Gradually Increase spost (Zooming Closer To Texture Center)
244
+ alpha = alpha - alphainc # Gradually Decrease alpha (Gradually Fading Image Out)
245
+ end
246
+ glEnd() # Done Drawing Quads
247
+
248
+ viewPerspective() # Switch To A Perspective View
249
+
250
+ glEnable(GL_DEPTH_TEST) # Enable Depth Testing
251
+ glDisable(GL_TEXTURE_2D) # Disable 2D Texture Mapping
252
+ glDisable(GL_BLEND) # Disable Blending
253
+ glBindTexture(GL_TEXTURE_2D,0) # Unbind The Blur Texture
249
254
  end
250
255
 
251
256
 
252
257
  def renderToTexture
253
- glViewport(0,0,128,128); # Set Our Viewport (Match Texture Size)
258
+ glViewport(0,0,128,128); # Set Our Viewport (Match Texture Size)
254
259
 
255
- processHelix() # Render The Helix
260
+ processHelix() # Render The Helix
256
261
 
257
- glBindTexture(GL_TEXTURE_2D,$blurTexture) # Bind To The Blur Texture
262
+ glBindTexture(GL_TEXTURE_2D,$blurTexture) # Bind To The Blur Texture
258
263
 
259
- # Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border)
260
- glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0)
264
+ # Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No Border)
265
+ glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0)
261
266
 
262
- glClearColor(0.0, 0.0, 0.5, 0.5) # Set The Clear Color To Medium Blue
263
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear The Screen And Depth Buffer
264
- width = glutGet(GLUT_WINDOW_WIDTH)
265
- height = glutGet(GLUT_WINDOW_HEIGHT)
266
- glViewport(0 , 0,width,height) # Set Viewport (0,0 to widthxheight)
267
+ glClearColor(0.0, 0.0, 0.5, 0.5) # Set The Clear Color To Medium Blue
268
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear The Screen And Depth Buffer
269
+ width = glutGet(GLUT_WINDOW_WIDTH)
270
+ height = glutGet(GLUT_WINDOW_HEIGHT)
271
+ glViewport(0 , 0,width,height) # Set Viewport (0,0 to widthxheight)
267
272
  end
268
273
 
269
274
  drawGLScene = lambda do # Draw The Scene
270
- glClearColor(0.0, 0.0, 0.0, 0.5) # Set The Clear Color To Black
271
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear Screen And Depth Buffer
272
- glLoadIdentity() # Reset The View
273
- renderToTexture() # Render To A Texture
274
- processHelix() # Draw Our Helix
275
- drawBlur(25,0.02) # Draw The Blur Effect
276
- glFlush() # Flush The GL Rendering Pipeline
277
- glutSwapBuffers()
278
- sleep(0.001) # don't hog all cpu time
275
+ glClearColor(0.0, 0.0, 0.0, 0.5) # Set The Clear Color To Black
276
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear Screen And Depth Buffer
277
+ glLoadIdentity() # Reset The View
278
+ renderToTexture() # Render To A Texture
279
+ processHelix() # Draw Our Helix
280
+ drawBlur(25,0.02) # Draw The Blur Effect
281
+ glFlush() # Flush The GL Rendering Pipeline
282
+ glutSwapBuffers()
283
+ sleep(0.001) # don't hog all cpu time
279
284
  end
280
285
 
281
286
  idle = lambda do
282
- now = glutGet(GLUT_ELAPSED_TIME)
283
- elapsed = now - $lasttime
284
- $angle += (elapsed * 0.03) # Update angle Based On The Clock
285
- $lasttime = now
287
+ now = glutGet(GLUT_ELAPSED_TIME)
288
+ elapsed = now - $lasttime
289
+ $angle += (elapsed * 0.03) # Update angle Based On The Clock
290
+ $lasttime = now
286
291
 
287
- glutPostRedisplay()
292
+ glutPostRedisplay()
288
293
  end
289
294
 
290
295
  # Main