ruby-opengl 0.60.0-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/MIT-LICENSE +18 -0
  2. data/README.txt +47 -0
  3. data/doc/build_install.txt +122 -0
  4. data/doc/history.txt +66 -0
  5. data/doc/requirements_and_design.txt +117 -0
  6. data/doc/roadmap.txt +28 -0
  7. data/doc/scientific_use.txt +35 -0
  8. data/doc/thanks.txt +29 -0
  9. data/doc/tutorial.txt +469 -0
  10. data/examples/NeHe/nehe_lesson02.rb +117 -0
  11. data/examples/NeHe/nehe_lesson03.rb +122 -0
  12. data/examples/NeHe/nehe_lesson04.rb +133 -0
  13. data/examples/NeHe/nehe_lesson05.rb +186 -0
  14. data/examples/NeHe/nehe_lesson36.rb +303 -0
  15. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  16. data/examples/OrangeBook/brick.frag +36 -0
  17. data/examples/OrangeBook/brick.rb +376 -0
  18. data/examples/OrangeBook/brick.vert +41 -0
  19. data/examples/OrangeBook/particle.frag +17 -0
  20. data/examples/OrangeBook/particle.rb +406 -0
  21. data/examples/OrangeBook/particle.vert +38 -0
  22. data/examples/README +16 -0
  23. data/examples/RedBook/aapoly.rb +142 -0
  24. data/examples/RedBook/aargb.rb +119 -0
  25. data/examples/RedBook/accanti.rb +162 -0
  26. data/examples/RedBook/accpersp.rb +215 -0
  27. data/examples/RedBook/alpha.rb +123 -0
  28. data/examples/RedBook/alpha3D.rb +158 -0
  29. data/examples/RedBook/bezcurve.rb +105 -0
  30. data/examples/RedBook/bezmesh.rb +137 -0
  31. data/examples/RedBook/checker.rb +124 -0
  32. data/examples/RedBook/clip.rb +95 -0
  33. data/examples/RedBook/colormat.rb +135 -0
  34. data/examples/RedBook/cube.rb +69 -0
  35. data/examples/RedBook/depthcue.rb +99 -0
  36. data/examples/RedBook/dof.rb +205 -0
  37. data/examples/RedBook/double.rb +105 -0
  38. data/examples/RedBook/drawf.rb +91 -0
  39. data/examples/RedBook/feedback.rb +145 -0
  40. data/examples/RedBook/fog.rb +167 -0
  41. data/examples/RedBook/font.rb +151 -0
  42. data/examples/RedBook/hello.rb +79 -0
  43. data/examples/RedBook/image.rb +137 -0
  44. data/examples/RedBook/jitter.rb +207 -0
  45. data/examples/RedBook/lines.rb +128 -0
  46. data/examples/RedBook/list.rb +111 -0
  47. data/examples/RedBook/material.rb +275 -0
  48. data/examples/RedBook/mipmap.rb +156 -0
  49. data/examples/RedBook/model.rb +113 -0
  50. data/examples/RedBook/movelight.rb +132 -0
  51. data/examples/RedBook/pickdepth.rb +179 -0
  52. data/examples/RedBook/planet.rb +108 -0
  53. data/examples/RedBook/quadric.rb +158 -0
  54. data/examples/RedBook/robot.rb +115 -0
  55. data/examples/RedBook/select.rb +196 -0
  56. data/examples/RedBook/smooth.rb +95 -0
  57. data/examples/RedBook/stencil.rb +163 -0
  58. data/examples/RedBook/stroke.rb +167 -0
  59. data/examples/RedBook/surface.rb +166 -0
  60. data/examples/RedBook/teaambient.rb +132 -0
  61. data/examples/RedBook/teapots.rb +182 -0
  62. data/examples/RedBook/tess.rb +183 -0
  63. data/examples/RedBook/texbind.rb +147 -0
  64. data/examples/RedBook/texgen.rb +169 -0
  65. data/examples/RedBook/texturesurf.rb +128 -0
  66. data/examples/RedBook/varray.rb +159 -0
  67. data/examples/RedBook/wrap.rb +148 -0
  68. data/examples/misc/OGLBench.rb +337 -0
  69. data/examples/misc/anisotropic.rb +194 -0
  70. data/examples/misc/fbo_test.rb +356 -0
  71. data/examples/misc/font-glut.rb +46 -0
  72. data/examples/misc/glfwtest.rb +30 -0
  73. data/examples/misc/plane.rb +161 -0
  74. data/examples/misc/readpixel.rb +65 -0
  75. data/examples/misc/sdltest.rb +34 -0
  76. data/examples/misc/trislam.rb +828 -0
  77. data/lib/gl.so +0 -0
  78. data/lib/glu.so +0 -0
  79. data/lib/glut.so +0 -0
  80. data/lib/opengl.rb +84 -0
  81. metadata +132 -0
@@ -0,0 +1,194 @@
1
+ #
2
+ # Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
3
+ #
4
+ # This program is distributed under the terms of the MIT license.
5
+ # See the included MIT-LICENSE file for the terms of this license.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
8
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
10
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
11
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
12
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
13
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ #
15
+
16
+ #
17
+ # Showcase for anisotropic texture filtering
18
+ #
19
+
20
+ require 'opengl'
21
+ include Gl,Glu,Glut
22
+
23
+ # extend Array class with new function
24
+ class Array
25
+ def rotate!
26
+ self << self.shift
27
+ end
28
+ end
29
+
30
+ 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
180
+ end
181
+
182
+ # main
183
+ glutInit()
184
+ glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE )
185
+ glutInitWindowPosition(150,50)
186
+ glutInitWindowSize(500,500)
187
+ glutCreateWindow($0)
188
+
189
+ app = App.new
190
+ glutReshapeFunc(app.method(:reshape).to_proc)
191
+ glutDisplayFunc(app.method(:display).to_proc)
192
+ glutIdleFunc(app.method(:idle).to_proc)
193
+ glutKeyboardFunc(app.method(:keyboard).to_proc)
194
+ glutMainLoop()
@@ -0,0 +1,356 @@
1
+ # ogl_bench v1.0 - Copyright 2007 - Graphcomp
2
+ # Bob Free bfree@graphcomp.com
3
+ # http://graphcomp.com/opengl
4
+
5
+ # This program is freely distributable without licensing fees
6
+ # and is provided without guarantee or warrantee expressed or
7
+ # implied. This program is -not- in the public domain.
8
+ #
9
+ # Conversion to ruby by Jan Dvorak <jan.dvorak@kraxnet.cz>
10
+
11
+ # Set up standard libs
12
+ require 'opengl'
13
+ include Gl,Glut
14
+
15
+ # Set up constants
16
+ PROGRAM = "OpenGL Benchmark - Ruby Bindings"
17
+ CYCLES = 1000
18
+
19
+ # Setup OpenGL Extensions
20
+ # (Not needed)
21
+
22
+ # Set up types
23
+ class Bench
24
+ attr_accessor :start,:secs
25
+ def initialize
26
+ @start = 0
27
+ @secs = 0
28
+ end
29
+ end
30
+
31
+ # Set up globals
32
+ $appBench = Bench.new
33
+ $frameBench = Bench.new
34
+ $textureBench = Bench.new
35
+ $teapotBench = Bench.new
36
+ $now = 0
37
+ $frames = 0
38
+
39
+ $idWindow = 0
40
+
41
+ $windowWidth = 512
42
+ $windowHeight = 512
43
+
44
+ $textureWidth = 128
45
+ $textureHeight = 128
46
+
47
+ $rotTeapotX = 0
48
+ $rotTeapotY = 0
49
+
50
+ $idTexture = 0
51
+ $idFrameBuffer = 0
52
+ $idRenderBuffer = 0
53
+ $idVertexProg = 0
54
+ $idFragProg = 0
55
+
56
+ $incY = 0.5
57
+ $rotY = 0.0
58
+
59
+ # Start benchmark
60
+ def startBench(pBench)
61
+ pBench.start = Time.now
62
+ # pBench.secs = 0.0
63
+ end
64
+
65
+ # Accumulate benchmark
66
+ def endBench(pBench)
67
+ $now = Time.now
68
+ pBench.secs += $now - pBench.start
69
+ end
70
+
71
+ # Print benchmark
72
+ def printBench
73
+ if ($frames==0 || $appBench.secs==0 || $frameBench.secs==0 ||
74
+ $textureBench.secs==0 || $teapotBench.secs==0)
75
+ puts "No measurable time has elapsed"
76
+ return
77
+ end
78
+
79
+ puts "FBO Texture Rendering FPS: #{$frames / $textureBench.secs}"
80
+ puts "Teapot Shader FPS: #{$frames / $teapotBench.secs}"
81
+
82
+ overhead = $frameBench.secs - ($textureBench.secs + $teapotBench.secs)
83
+ puts "Frame overhead secs/frame: #{overhead / $frames}"
84
+
85
+ overhead = $appBench.secs - $frameBench.secs
86
+ puts "OS/GLUT overhead secs/frame: #{overhead / $frames}"
87
+
88
+ puts "Overall FPS: #{$frames / $appBench.secs}"
89
+ puts ""
90
+ end
91
+
92
+ # Error handling
93
+ def error(errTitle, errMsg)
94
+ puts "#{errTitle}: #{errMsg}"
95
+ exit(0)
96
+ end
97
+
98
+ # Check OpenGL Version
99
+ def checkVersion
100
+ version = glGetString(GL_VERSION)
101
+ vendor = glGetString(GL_VENDOR)
102
+ renderer = glGetString(GL_RENDERER)
103
+ exts = glGetString(GL_EXTENSIONS)
104
+
105
+ puts PROGRAM
106
+ puts ""
107
+ puts "OpenGL: #{version}"
108
+ puts "Vendor: #{vendor}"
109
+ puts "Renderer: #{renderer}"
110
+ puts ""
111
+
112
+ if Gl.is_available?("GL_EXT_framebuffer_object") == false
113
+ error("Extension not available","EXT_framebuffer_object")
114
+ end
115
+ end
116
+
117
+ # Load Extension Procs
118
+ def initExtensions
119
+ # (Not needed)
120
+ end
121
+
122
+ # Initialize Vertex/Fragment Programs
123
+ def initProgs
124
+ # NOP Vertex shader
125
+ $vertexProg = <<-END_OF_PROGRAM
126
+ !!ARBvp1.0
127
+ TEMP vertexClip;
128
+ DP4 vertexClip.x, state.matrix.mvp.row[0], vertex.position;
129
+ DP4 vertexClip.y, state.matrix.mvp.row[1], vertex.position;
130
+ DP4 vertexClip.z, state.matrix.mvp.row[2], vertex.position;
131
+ DP4 vertexClip.w, state.matrix.mvp.row[3], vertex.position;
132
+ MOV result.position, vertexClip;
133
+ MOV result.color, vertex.color;
134
+ MOV result.texcoord[0], vertex.texcoord;
135
+ MOV result.texcoord[1], vertex.normal;
136
+ END
137
+ END_OF_PROGRAM
138
+
139
+ # Black Light Fragment shader
140
+ $fragProg = <<-END_OF_PROGRAM
141
+ !!ARBfp1.0
142
+ TEMP decal,color;
143
+ TEX decal, fragment.texcoord[0], texture[0], 2D;
144
+ MUL result.color, decal, fragment.texcoord[1];
145
+ END
146
+ END_OF_PROGRAM
147
+
148
+ $idVertexProg,$idFragProg = glGenProgramsARB(2)
149
+
150
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, $idVertexProg)
151
+ glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, $vertexProg)
152
+
153
+ glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, $idFragProg)
154
+ glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, $fragProg)
155
+ end
156
+
157
+ # Terminate Vertex/Fragment Programs
158
+ def termProgs
159
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0)
160
+ glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0)
161
+
162
+ glDeleteProgramsARB([$idVertexProg,$idFragProg])
163
+ end
164
+
165
+ # FBO Status handler
166
+ def statusFBO
167
+ stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)
168
+ return if (stat==0 || stat == GL_FRAMEBUFFER_COMPLETE_EXT)
169
+ printf("FBO status: %04X\n", stat)
170
+ exit(0)
171
+ end
172
+
173
+ # Initialize Framebuffers
174
+ def initFBO
175
+ $idTexture = glGenTextures(1)[0]
176
+ $idFrameBuffer = glGenFramebuffersEXT(1)[0]
177
+ $idRenderBuffer = glGenRenderbuffersEXT(1)[0]
178
+
179
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, $idFrameBuffer)
180
+ glBindTexture(GL_TEXTURE_2D, $idTexture)
181
+
182
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, $textureWidth, $textureHeight,
183
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, nil)
184
+
185
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
186
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
187
+
188
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
189
+ GL_TEXTURE_2D, $idTexture, 0)
190
+
191
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, $idRenderBuffer)
192
+
193
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
194
+ $textureWidth, $textureHeight)
195
+
196
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
197
+ GL_RENDERBUFFER_EXT, $idRenderBuffer)
198
+
199
+ statusFBO()
200
+ end
201
+
202
+ # FBO texture renderer
203
+ def renderFBO
204
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, $idFrameBuffer)
205
+
206
+ glLoadIdentity()
207
+ glTranslated(-0.75, -0.85, -2.5)
208
+
209
+ glRotated($rotTeapotX, 1.0, 0.0, 0.0)
210
+ $rotTeapotX += 0.5
211
+
212
+ glRotated($rotTeapotY, 0.0, 1.0, 0.0)
213
+ $rotTeapotY += 1.0
214
+
215
+ glClearColor(0, 0, 0, 0)
216
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
217
+ glColor3d(1.0, 1.0, 1.0)
218
+
219
+ glutWireTeapot(0.125)
220
+
221
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
222
+ end
223
+
224
+ # Terminate FBO objects
225
+ def termFBO
226
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)
227
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
228
+ glBindTexture(GL_TEXTURE_2D, 0)
229
+
230
+ glDeleteRenderbuffersEXT($idRenderBuffer)
231
+ glDeleteFramebuffersEXT($idFrameBuffer)
232
+ glDeleteTextures($idTexture)
233
+ end
234
+
235
+ # Resize Window
236
+ def resizeScene(width,height)
237
+ if (height==0)
238
+ height = 1
239
+ end
240
+
241
+ glViewport(0, 0, width, height)
242
+
243
+ glMatrixMode(GL_PROJECTION)
244
+ glLoadIdentity()
245
+ gluPerspective(45.0,width.to_f/height.to_f,0.1,100.0)
246
+
247
+ glMatrixMode(GL_MODELVIEW)
248
+
249
+ $windowWidth = width
250
+ $windowHeight = height
251
+ end
252
+
253
+ # Initialize OpenGL Environment
254
+ def init
255
+ checkVersion
256
+ initExtensions
257
+
258
+ resizeScene($windowWidth, $windowHeight)
259
+
260
+ initFBO
261
+ initProgs
262
+ end
263
+
264
+ # Terminate OpenGL Environment
265
+ def term
266
+ # Display benchmark
267
+ endBench($appBench)
268
+ printBench()
269
+
270
+ # Disable app
271
+ glutHideWindow()
272
+ glutKeyboardFunc(nil)
273
+ glutSpecialFunc(nil)
274
+ glutIdleFunc(nil)
275
+ glutReshapeFunc(nil)
276
+
277
+ # Release Framebuffers
278
+ termProgs()
279
+ termFBO()
280
+
281
+ # Now we can destroy window
282
+ glutDestroyWindow($idWindow)
283
+ exit(0)
284
+ end
285
+
286
+ # Frame handler
287
+ display = lambda do
288
+ # Run benchmark CYCLES times
289
+ $frames += 1
290
+ term() if ($frames > CYCLES)
291
+ startBench($frameBench)
292
+
293
+ # Render animated texture
294
+ startBench($textureBench)
295
+ renderFBO()
296
+ endBench($textureBench)
297
+
298
+ # Set up ModelView
299
+ glMatrixMode(GL_MODELVIEW)
300
+ glLoadIdentity()
301
+ glTranslatef(0.0,0.0,-5.0)
302
+ glRotated(0.0,1.0,0.0,0.0)
303
+ glRotated($rotY,0.0,1.0,0.0)
304
+ $rotY += $incY
305
+
306
+ # Set attributes
307
+ glEnable(GL_TEXTURE_2D)
308
+ glEnable(GL_DEPTH_TEST)
309
+ glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL)
310
+
311
+ # Clear render buffer and set teapot color
312
+ glClearColor(0.2, 0.2, 0.2, 1.0)
313
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
314
+ glColor3d(0.9, 0.45, 0.0)
315
+
316
+ # Render the teapot using our shader
317
+ startBench($teapotBench)
318
+ glEnable(GL_VERTEX_PROGRAM_ARB)
319
+ glEnable(GL_FRAGMENT_PROGRAM_ARB)
320
+
321
+ glutSolidTeapot(1.0)
322
+
323
+ glDisable(GL_FRAGMENT_PROGRAM_ARB)
324
+ glDisable(GL_VERTEX_PROGRAM_ARB)
325
+ endBench($teapotBench)
326
+
327
+ # Double-buffer and done
328
+ glutSwapBuffers()
329
+ endBench($frameBench)
330
+ end
331
+
332
+ # Keyboard handler
333
+ keyPressed = lambda do |key,x,y|
334
+ term()
335
+ end
336
+
337
+
338
+
339
+ # Main app
340
+
341
+ glutInit()
342
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA)
343
+ glutInitWindowSize($windowWidth,$windowHeight)
344
+
345
+ $idWindow = glutCreateWindow(PROGRAM)
346
+
347
+ glutDisplayFunc(display)
348
+ glutIdleFunc(display)
349
+ #glutReshapeFunc(resizeScene)
350
+ glutKeyboardFunc(keyPressed)
351
+
352
+ init()
353
+ startBench($appBench)
354
+ glutMainLoop()
355
+ exit(0)
356
+