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
@@ -14,6 +14,8 @@
14
14
  module OGLBench
15
15
 
16
16
  require 'opengl'
17
+ require 'glu'
18
+ require 'glut'
17
19
  include Gl,Glu,Glut
18
20
 
19
21
  require 'getoptlong'
@@ -132,39 +134,39 @@ $KNOWN_RES = {
132
134
  'whuxga' => [ 7680, 4800, 'Wide Hexadecatuple Ultra XGA' ],
133
135
  }
134
136
 
135
- def OGLBench.w_h_from_geometry(geom)
136
- geometry = geom.downcase
137
+ def OGLBench.w_h_from_geometry(geom)
138
+ geometry = geom.downcase
137
139
 
138
- return $~[1,2] if geometry =~ /^(\d+)x(\d+)$/
140
+ return $~[1,2] if geometry =~ /^(\d+)x(\d+)$/
139
141
 
140
142
  dims = $KNOWN_RES[geometry] || [0, 0]
141
- dims[0,2]
143
+ dims[0,2]
142
144
  end
143
145
 
144
- def OGLBench.show_known_geometries
145
- puts "Known geometries:"
146
+ def OGLBench.show_known_geometries
147
+ puts "Known geometries:"
146
148
 
147
- # convert the hash to array, sort by resolution and iterate
148
- $KNOWN_RES.sort {|a,b| a[1][0,2] <=> b[1][0,2] }.each do |row|
149
- name, res = row
150
- x,y,fullname = res
151
- printf "%-10s %4d x %4d %s\n", name, x, y, fullname
152
- end
149
+ # convert the hash to array, sort by resolution and iterate
150
+ $KNOWN_RES.sort {|a,b| a[1][0,2] <=> b[1][0,2] }.each do |row|
151
+ name, res = row
152
+ x,y,fullname = res
153
+ printf "%-10s %4d x %4d %s\n", name, x, y, fullname
154
+ end
153
155
  end
154
156
 
155
157
  def OGLBench.show_usage(conf = $CACHED[:conf])
156
- usage = conf[:usage]
158
+ usage = conf[:usage]
157
159
 
158
- if (not conf[:extra_usage].empty?)
159
- conf[:_USAGE_LABEL_GENERAL] = "\nGENERAL OPTIONS:"
160
- usage = "#{conf[:usage]}\nOTHER OPTIONS:\n#{conf[:extra_usage]}"
161
- else
162
- conf[:_USAGE_LABEL_GENERAL] = ''
163
- end
160
+ if (not conf[:extra_usage].empty?)
161
+ conf[:_USAGE_LABEL_GENERAL] = "\nGENERAL OPTIONS:"
162
+ usage = "#{conf[:usage]}\nOTHER OPTIONS:\n#{conf[:extra_usage]}"
163
+ else
164
+ conf[:_USAGE_LABEL_GENERAL] = ''
165
+ end
164
166
 
165
- usage.gsub!(/\$(\w+)/) do conf[$1.to_sym] end
167
+ usage.gsub!(/\$(\w+)/) do conf[$1.to_sym] end
166
168
 
167
- print usage
169
+ print usage
168
170
  end
169
171
 
170
172
  def OGLBench.show_basic_config(conf,gl_info,version)
@@ -181,11 +183,11 @@ CONFIG
181
183
  end
182
184
 
183
185
  def OGLBench.friendly_booleans(conf)
184
- booleans = conf[:booleans].update(conf[:extra_booleans])
186
+ booleans = conf[:booleans].update(conf[:extra_booleans])
185
187
 
186
- booleans.each_pair do |logical,readable|
187
- conf[readable] = (conf[logical] ? 'yes' : 'no')
188
- end
188
+ booleans.each_pair do |logical,readable|
189
+ conf[readable] = (conf[logical] ? 'yes' : 'no')
190
+ end
189
191
  end
190
192
 
191
193
  def OGLBench.basic_init(extra_conf = nil,extra_options = nil)
@@ -207,131 +209,130 @@ USAGE
207
209
  # show_usage(conf)
208
210
  # FIXME: $0 ?
209
211
 
210
- conf = {
211
- :title => 'Ruby-OpenGL Benchmark',
212
- :usage => usage,
213
- :extra_usage => '',
214
- "0".to_sym => $0,
215
-
216
- :frames => 100,
217
- :seconds => 10,
218
- :geometry => '300x300',
219
-
220
- :fullscreen => false,
221
- :known => false,
222
- :help => false,
223
-
224
- :booleans => {
225
- :fullscreen => :fs,
226
- :known => :show_known,
227
- :help => :show_help,
228
- },
229
- :extra_booleans => {},
230
- }
231
-
232
- conf.update(extra_conf) if extra_conf
233
-
234
- opts = GetoptLong.new(
235
- [ "--frames", "-f", GetoptLong::REQUIRED_ARGUMENT ],
236
- [ "--seconds", "-s", GetoptLong::REQUIRED_ARGUMENT ],
237
- [ "--geometry", "-g", GetoptLong::REQUIRED_ARGUMENT ],
238
- [ "--fullscreen", "--fs", GetoptLong::NO_ARGUMENT ],
239
- [ "--known", "-k","--known-geometries", GetoptLong::NO_ARGUMENT ],
240
- [ "--help", "-h", "-?", GetoptLong::NO_ARGUMENT ]
241
- )
242
-
243
- opts.each do |opt, arg|
244
- name = opt.tr('-','')
245
- if arg.empty?
246
- conf[name.to_sym] = true
247
- else
248
- conf[name.to_sym] = arg
249
- end
250
- end
251
-
252
- friendly_booleans(conf)
212
+ conf = {
213
+ :title => 'Ruby-OpenGL Benchmark',
214
+ :usage => usage,
215
+ :extra_usage => '',
216
+ "0".to_sym => $0,
217
+
218
+ :frames => 100,
219
+ :seconds => 10,
220
+ :geometry => '300x300',
221
+
222
+ :fullscreen => false,
223
+ :known => false,
224
+ :help => false,
225
+
226
+ :booleans => {
227
+ :fullscreen => :fs,
228
+ :known => :show_known,
229
+ :help => :show_help,
230
+ },
231
+ :extra_booleans => {},
232
+ }
233
+
234
+ conf.update(extra_conf) if extra_conf
235
+
236
+ opts = GetoptLong.new(
237
+ [ "--frames", "-f", GetoptLong::REQUIRED_ARGUMENT ],
238
+ [ "--seconds", "-s", GetoptLong::REQUIRED_ARGUMENT ],
239
+ [ "--geometry", "-g", GetoptLong::REQUIRED_ARGUMENT ],
240
+ [ "--fullscreen", "--fs", GetoptLong::NO_ARGUMENT ],
241
+ [ "--known", "-k","--known-geometries", GetoptLong::NO_ARGUMENT ],
242
+ [ "--help", "-h", "-?", GetoptLong::NO_ARGUMENT ]
243
+ )
244
+
245
+ opts.each do |opt, arg|
246
+ name = opt.tr('-','')
247
+ if arg.empty?
248
+ conf[name.to_sym] = true
249
+ else
250
+ conf[name.to_sym] = arg
251
+ end
252
+ end
253
+
254
+ friendly_booleans(conf)
253
255
 
254
256
 
255
257
  geometry = conf[:geometry]
256
258
  w,h = w_h_from_geometry(geometry)
257
- conf[:width] = w.to_i
258
- conf[:height] = h.to_i
259
+ conf[:width] = w.to_i
260
+ conf[:height] = h.to_i
259
261
 
260
- $stdout.sync = true
262
+ $stdout.sync = true
261
263
 
262
- if (conf[:help])
263
- show_usage(conf)
264
- exit(0)
265
- end
264
+ if (conf[:help])
265
+ show_usage(conf)
266
+ exit(0)
267
+ end
266
268
 
267
- if (conf[:known])
268
- show_known_geometries()
269
- exit(0)
270
- end
269
+ if (conf[:known])
270
+ show_known_geometries()
271
+ exit(0)
272
+ end
271
273
 
272
274
 
273
- app = init_opengl(conf)
274
- gl_info = get_gl_info(app)
275
+ app = init_opengl(conf)
276
+ gl_info = get_gl_info(app)
275
277
 
276
- [conf, app, gl_info]
278
+ [conf, app, gl_info]
277
279
  end
278
280
 
279
281
 
280
282
  def OGLBench.init_opengl(conf)
281
- w,h = conf[:width], conf[:height]
283
+ w,h = conf[:width], conf[:height]
282
284
 
283
- raise "Could not determine sane width and height from '#{conf[:geometry]}'.\n" unless w > 0 && h > 0;
285
+ raise "Could not determine sane width and height from '#{conf[:geometry]}'.\n" unless w > 0 && h > 0;
284
286
 
285
- glutInit()
286
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH)
287
- glutInitWindowSize(w,h)
288
- app = glutCreateWindow(conf[:title])
289
- glViewport(0, 0, w, h)
287
+ glutInit()
288
+ glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH)
289
+ glutInitWindowSize(w,h)
290
+ app = glutCreateWindow(conf[:title])
291
+ glViewport(0, 0, w, h)
290
292
 
291
- glMatrixMode(GL_PROJECTION)
292
- glLoadIdentity
293
+ glMatrixMode(GL_PROJECTION)
294
+ glLoadIdentity
293
295
 
294
- glMatrixMode(GL_MODELVIEW)
295
- glLoadIdentity
296
+ glMatrixMode(GL_MODELVIEW)
297
+ glLoadIdentity
296
298
 
297
- $CACHED[:conf] = conf
298
- $CACHED[:app] = app
299
+ $CACHED[:conf] = conf
300
+ $CACHED[:app] = app
299
301
 
300
- app
302
+ app
301
303
  end
302
304
 
303
305
  def OGLBench.get_gl_info(app = $CACHED[:app])
304
- gl_info = {}
306
+ gl_info = {}
305
307
 
306
- # These values are faked
307
- conf = $CACHED[:conf]
308
- gl_info[:r] = 8
309
- gl_info[:g] = 8
310
- gl_info[:b] = 8
311
- gl_info[:a] = 0
312
- gl_info[:d] = 24
308
+ # These values are faked
309
+ conf = $CACHED[:conf]
310
+ gl_info[:r] = 8
311
+ gl_info[:g] = 8
312
+ gl_info[:b] = 8
313
+ gl_info[:a] = 0
314
+ gl_info[:d] = 24
313
315
 
314
- $CACHED[:gl_info] = gl_info
316
+ $CACHED[:gl_info] = gl_info
315
317
 
316
- gl_info
318
+ gl_info
317
319
  end
318
320
 
319
321
  def OGLBench.fade_to_white(frac)
320
- glColor4f(frac, frac, frac, 1)
321
- glClearColor(frac, frac, frac, 1)
322
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
323
- glFinish
322
+ glColor4f(frac, frac, frac, 1)
323
+ glClearColor(frac, frac, frac, 1)
324
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
325
+ glFinish
324
326
  end
325
327
 
326
328
  def OGLBench.draw_string(font_style,str,x,y)
327
329
  glRasterPos2i(x,y)
328
- str.each_byte do |char|
330
+ str.each_byte do |char|
329
331
  glutBitmapCharacter(font_style, char)
330
- end
332
+ end
331
333
  end
332
334
 
333
335
  # def init_bitmap_font
334
336
  # def texture_from_texels
335
337
 
336
338
  end # end module
337
-
@@ -18,165 +18,167 @@
18
18
  #
19
19
 
20
20
  require 'opengl'
21
+ require 'glu'
22
+ require 'glut'
21
23
  include Gl,Glu,Glut
22
24
 
23
25
  # extend Array class with new function
24
26
  class Array
25
- def rotate!
26
- self << self.shift
27
- end
27
+ def rotate!
28
+ self << self.shift
29
+ end
28
30
  end
29
31
 
30
32
  class App
31
- @@filters = [[GL_NEAREST,"None"],[GL_LINEAR_MIPMAP_NEAREST,"Bilinear"],[GL_LINEAR_MIPMAP_LINEAR,"Trilinear"]]
32
- @@anisotropy = [1,2,4,8,16,32]
33
- @@color_tint = ["Off","On"]
34
-
35
- def checker_texture(size,divide,color_a,color_b)
36
- strip_a = color_a * (size/divide)
37
- strip_b = color_b * (size/divide)
38
- line_strip_a = (strip_a + strip_b) * (size/2)
39
- line_strip_b = (strip_b + strip_a) * (size/2)
40
- (line_strip_a + line_strip_b) * (divide/2)
41
- end
42
-
43
- def printGlutBitmapFont(string, font, x,y, r,g,b)
44
- glDisable(GL_TEXTURE_2D)
45
- glColor3f(r, g, b)
46
- glRasterPos2i(x, y)
47
- string.each_byte do |x|
48
- glutBitmapCharacter(font, x)
49
- end
50
- end
51
-
52
- def ortho(w,h)
53
- glMatrixMode(GL_PROJECTION)
54
- glLoadIdentity()
55
- gluOrtho2D(0,w,0,h)
56
- glScalef(1,-1,1)
57
- glTranslatef(0,-h,0)
58
-
59
- glMatrixMode(GL_MODELVIEW)
60
- glLoadIdentity()
61
- end
62
-
63
- def persp(w,h)
64
- glMatrixMode(GL_PROJECTION)
65
- glLoadIdentity
66
- gluPerspective(90,w.to_f/h.to_f,1,100)
67
-
68
- glMatrixMode(GL_MODELVIEW)
69
- glLoadIdentity
70
- end
71
-
72
- def reshape(w,h)
73
- @@w,@@h = w,h
74
- glViewport(0, 0, w, h)
75
- persp(w,h)
76
- end
77
-
78
- def initialize
79
- if (not Gl.is_available?("GL_EXT_texture_filter_anisotropic"))
80
- puts "This program needs GL_EXT_texture_filter_anisotropic extension"
81
- exit
82
- end
83
- @@w,@@h = glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT)
84
-
85
- @t = glGenTextures(2)
86
-
87
- # default checkerboard texture
88
- glBindTexture(GL_TEXTURE_2D,@t[0])
89
- data = checker_texture(64,4,[1,1,1],[0,0,0])
90
- gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,64,64,GL_RGB,GL_FLOAT,data.pack("f*"))
91
-
92
- # second texture with color tinted mipmaps
93
- glBindTexture(GL_TEXTURE_2D,@t[1])
94
- data = checker_texture(64,4,[1,1,1],[0,0,0])
95
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,64,64,0,GL_RGB,GL_FLOAT,data.pack("f*"))
96
- data = checker_texture(32,4,[1,0,0],[0,0,0])
97
- glTexImage2D(GL_TEXTURE_2D,1,GL_RGBA,32,32,0,GL_RGB,GL_FLOAT,data.pack("f*"))
98
- data = checker_texture(16,4,[0,1,0],[0,0,0])
99
- glTexImage2D(GL_TEXTURE_2D,2,GL_RGBA,16,16,0,GL_RGB,GL_FLOAT,data.pack("f*"))
100
- data = checker_texture(8,4,[0,0,1],[0,0,0])
101
- glTexImage2D(GL_TEXTURE_2D,3,GL_RGBA,8,8,0,GL_RGB,GL_FLOAT,data.pack("f*"))
102
- data = checker_texture(4,4,[1,1,0],[0,0,0])
103
- glTexImage2D(GL_TEXTURE_2D,4,GL_RGBA,4,4,0,GL_RGB,GL_FLOAT,data.pack("f*"))
104
- data = checker_texture(2,2,[1,0,1],[0,0,0])
105
- glTexImage2D(GL_TEXTURE_2D,5,GL_RGBA,2,2,0,GL_RGB,GL_FLOAT,data.pack("f*"))
106
- data = [0.5,0.5,0.5] # single pixel texture, just average it
107
- glTexImage2D(GL_TEXTURE_2D,6,GL_RGBA,1,1,0,GL_RGB,GL_FLOAT,data.pack("f*"))
108
- end
109
-
110
- def display_text
111
- ortho(@@w,@@h)
112
- printGlutBitmapFont("Texture Filtering ('f'): #{@@filters[0][1]}", GLUT_BITMAP_9_BY_15, 20, 20, 1.0, 1.0, 1.0)
113
- printGlutBitmapFont("Anisotropy factor ('a'): #{@@anisotropy[0]}x", GLUT_BITMAP_9_BY_15, 20, 40, 1.0, 1.0, 1.0)
114
- printGlutBitmapFont("Colored Mipmaps ('c'): #{@@color_tint[0]}", GLUT_BITMAP_9_BY_15, 20, 60, 1.0, 1.0, 1.0)
115
- persp(@@w,@@h)
116
- end
117
-
118
- def display_plane()
119
- glEnable(GL_TEXTURE_2D)
120
- t_repeat = 16
121
- # x,y,z,u,v
122
- quad = [[-4,-1,1, 0,t_repeat],[4,-1,1, t_repeat,t_repeat],[4,1,-8, t_repeat,0],[-4,1,-8, 0,0]]
123
- glBegin(GL_QUADS)
124
- quad.each do |v|
125
- glTexCoord2f(v[3],v[4])
126
- glVertex3f(v[0],v[1],v[2])
127
- end
128
- glEnd()
129
- glDisable(GL_TEXTURE_2D)
130
- end
131
-
132
- def display
133
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
134
-
135
- persp(@@w,@@h)
136
-
137
- # move back from scene
138
- glTranslatef(0,0,-2)
139
-
140
- # set anisotropy
141
- glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,@@anisotropy[0])
142
-
143
- # set color tint
144
- if (@@color_tint[0] == "On")
145
- glBindTexture(GL_TEXTURE_2D,@t[1])
146
- else
147
- glBindTexture(GL_TEXTURE_2D,@t[0])
148
- end
149
-
150
- # set filters
151
- f = @@filters[0][0]
152
- glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,f)
153
-
154
- # draw scene
155
- display_plane()
156
- display_text()
157
-
158
- sleep(0.001) # microsleep to avoid consuming all CPU time
159
- glutSwapBuffers()
160
- end
161
-
162
- def idle
163
- glutPostRedisplay()
164
- end
165
-
166
- def keyboard(key,x,y)
167
- case (key)
168
- when ?f
169
- @@filters.rotate!
170
- when ?a
171
- max_anisotropy = glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)
172
- begin @@anisotropy.rotate! end until @@anisotropy[0]<=max_anisotropy
173
- when ?c
174
- @@color_tint.rotate!
175
- when ?\e # Escape
176
- exit(0)
177
- end
178
- glutPostRedisplay()
179
- end
33
+ @@filters = [[GL_NEAREST,"None"],[GL_LINEAR_MIPMAP_NEAREST,"Bilinear"],[GL_LINEAR_MIPMAP_LINEAR,"Trilinear"]]
34
+ @@anisotropy = [1,2,4,8,16,32]
35
+ @@color_tint = ["Off","On"]
36
+
37
+ def checker_texture(size,divide,color_a,color_b)
38
+ strip_a = color_a * (size/divide)
39
+ strip_b = color_b * (size/divide)
40
+ line_strip_a = (strip_a + strip_b) * (size/2)
41
+ line_strip_b = (strip_b + strip_a) * (size/2)
42
+ (line_strip_a + line_strip_b) * (divide/2)
43
+ end
44
+
45
+ def printGlutBitmapFont(string, font, x,y, r,g,b)
46
+ glDisable(GL_TEXTURE_2D)
47
+ glColor3f(r, g, b)
48
+ glRasterPos2i(x, y)
49
+ string.each_byte do |x|
50
+ glutBitmapCharacter(font, x)
51
+ end
52
+ end
53
+
54
+ def ortho(w,h)
55
+ glMatrixMode(GL_PROJECTION)
56
+ glLoadIdentity()
57
+ gluOrtho2D(0,w,0,h)
58
+ glScalef(1,-1,1)
59
+ glTranslatef(0,-h,0)
60
+
61
+ glMatrixMode(GL_MODELVIEW)
62
+ glLoadIdentity()
63
+ end
64
+
65
+ def persp(w,h)
66
+ glMatrixMode(GL_PROJECTION)
67
+ glLoadIdentity
68
+ gluPerspective(90,w.to_f/h.to_f,1,100)
69
+
70
+ glMatrixMode(GL_MODELVIEW)
71
+ glLoadIdentity
72
+ end
73
+
74
+ def reshape(w,h)
75
+ @@w,@@h = w,h
76
+ glViewport(0, 0, w, h)
77
+ persp(w,h)
78
+ end
79
+
80
+ def initialize
81
+ if (not Gl.is_available?("GL_EXT_texture_filter_anisotropic"))
82
+ puts "This program needs GL_EXT_texture_filter_anisotropic extension"
83
+ exit
84
+ end
85
+ @@w,@@h = glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT)
86
+
87
+ @t = glGenTextures(2)
88
+
89
+ # default checkerboard texture
90
+ glBindTexture(GL_TEXTURE_2D,@t[0])
91
+ data = checker_texture(64,4,[1,1,1],[0,0,0])
92
+ gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,64,64,GL_RGB,GL_FLOAT,data.pack("f*"))
93
+
94
+ # second texture with color tinted mipmaps
95
+ glBindTexture(GL_TEXTURE_2D,@t[1])
96
+ data = checker_texture(64,4,[1,1,1],[0,0,0])
97
+ glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,64,64,0,GL_RGB,GL_FLOAT,data.pack("f*"))
98
+ data = checker_texture(32,4,[1,0,0],[0,0,0])
99
+ glTexImage2D(GL_TEXTURE_2D,1,GL_RGBA,32,32,0,GL_RGB,GL_FLOAT,data.pack("f*"))
100
+ data = checker_texture(16,4,[0,1,0],[0,0,0])
101
+ glTexImage2D(GL_TEXTURE_2D,2,GL_RGBA,16,16,0,GL_RGB,GL_FLOAT,data.pack("f*"))
102
+ data = checker_texture(8,4,[0,0,1],[0,0,0])
103
+ glTexImage2D(GL_TEXTURE_2D,3,GL_RGBA,8,8,0,GL_RGB,GL_FLOAT,data.pack("f*"))
104
+ data = checker_texture(4,4,[1,1,0],[0,0,0])
105
+ glTexImage2D(GL_TEXTURE_2D,4,GL_RGBA,4,4,0,GL_RGB,GL_FLOAT,data.pack("f*"))
106
+ data = checker_texture(2,2,[1,0,1],[0,0,0])
107
+ glTexImage2D(GL_TEXTURE_2D,5,GL_RGBA,2,2,0,GL_RGB,GL_FLOAT,data.pack("f*"))
108
+ data = [0.5,0.5,0.5] # single pixel texture, just average it
109
+ glTexImage2D(GL_TEXTURE_2D,6,GL_RGBA,1,1,0,GL_RGB,GL_FLOAT,data.pack("f*"))
110
+ end
111
+
112
+ def display_text
113
+ ortho(@@w,@@h)
114
+ printGlutBitmapFont("Texture Filtering ('f'): #{@@filters[0][1]}", GLUT_BITMAP_9_BY_15, 20, 20, 1.0, 1.0, 1.0)
115
+ printGlutBitmapFont("Anisotropy factor ('a'): #{@@anisotropy[0]}x", GLUT_BITMAP_9_BY_15, 20, 40, 1.0, 1.0, 1.0)
116
+ printGlutBitmapFont("Colored Mipmaps ('c'): #{@@color_tint[0]}", GLUT_BITMAP_9_BY_15, 20, 60, 1.0, 1.0, 1.0)
117
+ persp(@@w,@@h)
118
+ end
119
+
120
+ def display_plane()
121
+ glEnable(GL_TEXTURE_2D)
122
+ t_repeat = 16
123
+ # x,y,z,u,v
124
+ quad = [[-4,-1,1, 0,t_repeat],[4,-1,1, t_repeat,t_repeat],[4,1,-8, t_repeat,0],[-4,1,-8, 0,0]]
125
+ glBegin(GL_QUADS)
126
+ quad.each do |v|
127
+ glTexCoord2f(v[3],v[4])
128
+ glVertex3f(v[0],v[1],v[2])
129
+ end
130
+ glEnd()
131
+ glDisable(GL_TEXTURE_2D)
132
+ end
133
+
134
+ def display
135
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
136
+
137
+ persp(@@w,@@h)
138
+
139
+ # move back from scene
140
+ glTranslatef(0,0,-2)
141
+
142
+ # set anisotropy
143
+ glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,@@anisotropy[0])
144
+
145
+ # set color tint
146
+ if (@@color_tint[0] == "On")
147
+ glBindTexture(GL_TEXTURE_2D,@t[1])
148
+ else
149
+ glBindTexture(GL_TEXTURE_2D,@t[0])
150
+ end
151
+
152
+ # set filters
153
+ f = @@filters[0][0]
154
+ glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,f)
155
+
156
+ # draw scene
157
+ display_plane()
158
+ display_text()
159
+
160
+ sleep(0.001) # microsleep to avoid consuming all CPU time
161
+ glutSwapBuffers()
162
+ end
163
+
164
+ def idle
165
+ glutPostRedisplay()
166
+ end
167
+
168
+ def keyboard(key,x,y)
169
+ case (key)
170
+ when ?f
171
+ @@filters.rotate!
172
+ when ?a
173
+ max_anisotropy = glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)
174
+ begin @@anisotropy.rotate! end until @@anisotropy[0]<=max_anisotropy
175
+ when ?c
176
+ @@color_tint.rotate!
177
+ when ?\e # Escape
178
+ exit(0)
179
+ end
180
+ glutPostRedisplay()
181
+ end
180
182
  end
181
183
 
182
184
  # main