danabr75-opengl 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +29 -0
- data/.gemtest +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +19 -0
- data/Gemfile +8 -0
- data/History.md +101 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +142 -0
- data/README.rdoc +105 -0
- data/Rakefile +170 -0
- data/danabr75-opengl.gemspec +32 -0
- data/examples/NeHe/NeHe.png +0 -0
- data/examples/NeHe/crate.png +0 -0
- data/examples/NeHe/glass.png +0 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +123 -0
- data/examples/NeHe/nehe_lesson04.rb +132 -0
- data/examples/NeHe/nehe_lesson05.rb +182 -0
- data/examples/NeHe/nehe_lesson06.rb +186 -0
- data/examples/NeHe/nehe_lesson07.rb +240 -0
- data/examples/NeHe/nehe_lesson08.rb +255 -0
- data/examples/NeHe/nehe_lesson09.rb +203 -0
- data/examples/NeHe/nehe_lesson11.rb +176 -0
- data/examples/NeHe/nehe_lesson12.rb +203 -0
- data/examples/NeHe/nehe_lesson16.rb +211 -0
- data/examples/NeHe/nehe_lesson19.rb +209 -0
- data/examples/NeHe/nehe_lesson36.rb +308 -0
- data/examples/NeHe/particle.png +0 -0
- data/examples/NeHe/star.png +0 -0
- data/examples/NeHe/tim.png +0 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +378 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +408 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -0
- data/examples/RedBook/aapoly.rb +143 -0
- data/examples/RedBook/aargb.rb +121 -0
- data/examples/RedBook/accanti.rb +164 -0
- data/examples/RedBook/accpersp.rb +217 -0
- data/examples/RedBook/alpha.rb +125 -0
- data/examples/RedBook/alpha3D.rb +160 -0
- data/examples/RedBook/bezcurve.rb +107 -0
- data/examples/RedBook/bezmesh.rb +139 -0
- data/examples/RedBook/checker.rb +126 -0
- data/examples/RedBook/clip.rb +97 -0
- data/examples/RedBook/colormat.rb +137 -0
- data/examples/RedBook/cube.rb +71 -0
- data/examples/RedBook/depthcue.rb +101 -0
- data/examples/RedBook/dof.rb +206 -0
- data/examples/RedBook/double.rb +107 -0
- data/examples/RedBook/drawf.rb +93 -0
- data/examples/RedBook/feedback.rb +147 -0
- data/examples/RedBook/fog.rb +168 -0
- data/examples/RedBook/font.rb +153 -0
- data/examples/RedBook/hello.rb +81 -0
- data/examples/RedBook/image.rb +139 -0
- data/examples/RedBook/jitter.rb +207 -0
- data/examples/RedBook/light.rb +157 -0
- data/examples/RedBook/lines.rb +130 -0
- data/examples/RedBook/list.rb +113 -0
- data/examples/RedBook/material.rb +276 -0
- data/examples/RedBook/mipmap.rb +158 -0
- data/examples/RedBook/model.rb +115 -0
- data/examples/RedBook/movelight.rb +134 -0
- data/examples/RedBook/pickdepth.rb +181 -0
- data/examples/RedBook/planet.rb +110 -0
- data/examples/RedBook/quadric.rb +160 -0
- data/examples/RedBook/robot.rb +117 -0
- data/examples/RedBook/select.rb +198 -0
- data/examples/RedBook/smooth.rb +97 -0
- data/examples/RedBook/stencil.rb +165 -0
- data/examples/RedBook/stroke.rb +169 -0
- data/examples/RedBook/surface.rb +168 -0
- data/examples/RedBook/teaambient.rb +134 -0
- data/examples/RedBook/teapots.rb +184 -0
- data/examples/RedBook/tess.rb +185 -0
- data/examples/RedBook/texbind.rb +149 -0
- data/examples/RedBook/texgen.rb +171 -0
- data/examples/RedBook/texturesurf.rb +130 -0
- data/examples/RedBook/varray.rb +161 -0
- data/examples/RedBook/wrap.rb +150 -0
- data/examples/misc/OGLBench.rb +338 -0
- data/examples/misc/anisotropic.rb +196 -0
- data/examples/misc/fbo_test.rb +357 -0
- data/examples/misc/font-glut.rb +47 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +66 -0
- data/examples/misc/sdltest.rb +36 -0
- data/examples/misc/trislam.rb +829 -0
- data/ext/opengl/GL/gl.h +2115 -0
- data/ext/opengl/GL/glext.h +11770 -0
- data/ext/opengl/common.h +372 -0
- data/ext/opengl/conv.h +247 -0
- data/ext/opengl/extconf.rb +19 -0
- data/ext/opengl/fptr_struct.h +912 -0
- data/ext/opengl/funcdef.h +279 -0
- data/ext/opengl/gl-1.0-1.1.c +3345 -0
- data/ext/opengl/gl-1.2.c +155 -0
- data/ext/opengl/gl-1.3.c +447 -0
- data/ext/opengl/gl-1.4.c +346 -0
- data/ext/opengl/gl-1.5.c +225 -0
- data/ext/opengl/gl-2.0.c +665 -0
- data/ext/opengl/gl-2.1.c +57 -0
- data/ext/opengl/gl-3.0.c +502 -0
- data/ext/opengl/gl-enums.c +4853 -0
- data/ext/opengl/gl-enums.h +14528 -0
- data/ext/opengl/gl-error.c +110 -0
- data/ext/opengl/gl-error.h +25 -0
- data/ext/opengl/gl-ext-3dfx.c +27 -0
- data/ext/opengl/gl-ext-arb.c +880 -0
- data/ext/opengl/gl-ext-ati.c +41 -0
- data/ext/opengl/gl-ext-ext.c +885 -0
- data/ext/opengl/gl-ext-gremedy.c +41 -0
- data/ext/opengl/gl-ext-nv.c +679 -0
- data/ext/opengl/gl.c +265 -0
- data/ext/opengl/gl_buffer.c +202 -0
- data/ext/opengl/glimpl.c +187 -0
- data/ext/opengl/glimpl.h +47 -0
- data/ext/opengl/opengl.c +9 -0
- data/lib/gl.rb +1 -0
- data/lib/opengl.rb +79 -0
- data/lib/opengl/bindings_version.rb +4 -0
- data/lib/opengl/implementation.rb +38 -0
- data/lib/opengl/test_case.rb +86 -0
- data/test/dummy.xorg.conf +140 -0
- data/test/test_gl.rb +45 -0
- data/test/test_gl_10_11.rb +1363 -0
- data/test/test_gl_12.rb +71 -0
- data/test/test_gl_13.rb +221 -0
- data/test/test_gl_14.rb +218 -0
- data/test/test_gl_15.rb +258 -0
- data/test/test_gl_20.rb +417 -0
- data/test/test_gl_21.rb +436 -0
- data/test/test_gl_ext_arb.rb +508 -0
- data/test/test_gl_ext_ati.rb +28 -0
- data/test/test_gl_ext_ext.rb +608 -0
- data/test/test_gl_ext_gremedy.rb +29 -0
- data/test/test_gl_ext_nv.rb +349 -0
- data/test/test_glimpl.rb +23 -0
- data/test/test_opengl_buffer.rb +122 -0
- data/utils/README +6 -0
- data/utils/enumgen.rb +108 -0
- data/utils/extlistgen.rb +90 -0
- metadata +326 -0
@@ -0,0 +1,196 @@
|
|
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
|
+
require 'glu'
|
22
|
+
require 'glut'
|
23
|
+
include Gl,Glu,Glut
|
24
|
+
|
25
|
+
# extend Array class with new function
|
26
|
+
class Array
|
27
|
+
def rotate!
|
28
|
+
self << self.shift
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class App
|
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
|
182
|
+
end
|
183
|
+
|
184
|
+
# main
|
185
|
+
glutInit()
|
186
|
+
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE )
|
187
|
+
glutInitWindowPosition(150,50)
|
188
|
+
glutInitWindowSize(500,500)
|
189
|
+
glutCreateWindow($0)
|
190
|
+
|
191
|
+
app = App.new
|
192
|
+
glutReshapeFunc(app.method(:reshape).to_proc)
|
193
|
+
glutDisplayFunc(app.method(:display).to_proc)
|
194
|
+
glutIdleFunc(app.method(:idle).to_proc)
|
195
|
+
glutKeyboardFunc(app.method(:keyboard).to_proc)
|
196
|
+
glutMainLoop()
|
@@ -0,0 +1,357 @@
|
|
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
|
+
require 'glu'
|
14
|
+
require 'glut'
|
15
|
+
include Gl,Glu,Glut
|
16
|
+
|
17
|
+
# Set up constants
|
18
|
+
PROGRAM = "OpenGL Benchmark - Ruby Bindings"
|
19
|
+
CYCLES = 1000
|
20
|
+
|
21
|
+
# Setup OpenGL Extensions
|
22
|
+
# (Not needed)
|
23
|
+
|
24
|
+
# Set up types
|
25
|
+
class Bench
|
26
|
+
attr_accessor :start,:secs
|
27
|
+
def initialize
|
28
|
+
@start = 0
|
29
|
+
@secs = 0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Set up globals
|
34
|
+
$appBench = Bench.new
|
35
|
+
$frameBench = Bench.new
|
36
|
+
$textureBench = Bench.new
|
37
|
+
$teapotBench = Bench.new
|
38
|
+
$now = 0
|
39
|
+
$frames = 0
|
40
|
+
|
41
|
+
$idWindow = 0
|
42
|
+
|
43
|
+
$windowWidth = 512
|
44
|
+
$windowHeight = 512
|
45
|
+
|
46
|
+
$textureWidth = 128
|
47
|
+
$textureHeight = 128
|
48
|
+
|
49
|
+
$rotTeapotX = 0
|
50
|
+
$rotTeapotY = 0
|
51
|
+
|
52
|
+
$idTexture = 0
|
53
|
+
$idFrameBuffer = 0
|
54
|
+
$idRenderBuffer = 0
|
55
|
+
$idVertexProg = 0
|
56
|
+
$idFragProg = 0
|
57
|
+
|
58
|
+
$incY = 0.5
|
59
|
+
$rotY = 0.0
|
60
|
+
|
61
|
+
# Start benchmark
|
62
|
+
def startBench(pBench)
|
63
|
+
pBench.start = Time.now
|
64
|
+
# pBench.secs = 0.0
|
65
|
+
end
|
66
|
+
|
67
|
+
# Accumulate benchmark
|
68
|
+
def endBench(pBench)
|
69
|
+
$now = Time.now
|
70
|
+
pBench.secs += $now - pBench.start
|
71
|
+
end
|
72
|
+
|
73
|
+
# Print benchmark
|
74
|
+
def printBench
|
75
|
+
if ($frames==0 || $appBench.secs==0 || $frameBench.secs==0 ||
|
76
|
+
$textureBench.secs==0 || $teapotBench.secs==0)
|
77
|
+
puts "No measurable time has elapsed"
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
puts "FBO Texture Rendering FPS: #{$frames / $textureBench.secs}"
|
82
|
+
puts "Teapot Shader FPS: #{$frames / $teapotBench.secs}"
|
83
|
+
|
84
|
+
overhead = $frameBench.secs - ($textureBench.secs + $teapotBench.secs)
|
85
|
+
puts "Frame overhead secs/frame: #{overhead / $frames}"
|
86
|
+
|
87
|
+
overhead = $appBench.secs - $frameBench.secs
|
88
|
+
puts "OS/GLUT overhead secs/frame: #{overhead / $frames}"
|
89
|
+
|
90
|
+
puts "Overall FPS: #{$frames / $appBench.secs}"
|
91
|
+
puts ""
|
92
|
+
end
|
93
|
+
|
94
|
+
# Error handling
|
95
|
+
def error(errTitle, errMsg)
|
96
|
+
puts "#{errTitle}: #{errMsg}"
|
97
|
+
exit(0)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Check OpenGL Version
|
101
|
+
def checkVersion
|
102
|
+
version = glGetString(GL_VERSION)
|
103
|
+
vendor = glGetString(GL_VENDOR)
|
104
|
+
renderer = glGetString(GL_RENDERER)
|
105
|
+
exts = glGetString(GL_EXTENSIONS)
|
106
|
+
|
107
|
+
puts PROGRAM
|
108
|
+
puts ""
|
109
|
+
puts "OpenGL: #{version}"
|
110
|
+
puts "Vendor: #{vendor}"
|
111
|
+
puts "Renderer: #{renderer}"
|
112
|
+
puts ""
|
113
|
+
|
114
|
+
if Gl.is_available?("GL_EXT_framebuffer_object") == false
|
115
|
+
error("Extension not available","EXT_framebuffer_object")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Load Extension Procs
|
120
|
+
def initExtensions
|
121
|
+
# (Not needed)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Initialize Vertex/Fragment Programs
|
125
|
+
def initProgs
|
126
|
+
# NOP Vertex shader
|
127
|
+
$vertexProg = <<-END_OF_PROGRAM
|
128
|
+
!!ARBvp1.0
|
129
|
+
TEMP vertexClip;
|
130
|
+
DP4 vertexClip.x, state.matrix.mvp.row[0], vertex.position;
|
131
|
+
DP4 vertexClip.y, state.matrix.mvp.row[1], vertex.position;
|
132
|
+
DP4 vertexClip.z, state.matrix.mvp.row[2], vertex.position;
|
133
|
+
DP4 vertexClip.w, state.matrix.mvp.row[3], vertex.position;
|
134
|
+
MOV result.position, vertexClip;
|
135
|
+
MOV result.color, vertex.color;
|
136
|
+
MOV result.texcoord[0], vertex.texcoord;
|
137
|
+
MOV result.texcoord[1], vertex.normal;
|
138
|
+
END
|
139
|
+
END_OF_PROGRAM
|
140
|
+
|
141
|
+
# Black Light Fragment shader
|
142
|
+
$fragProg = <<-END_OF_PROGRAM
|
143
|
+
!!ARBfp1.0
|
144
|
+
TEMP decal,color;
|
145
|
+
TEX decal, fragment.texcoord[0], texture[0], 2D;
|
146
|
+
MUL result.color, decal, fragment.texcoord[1];
|
147
|
+
END
|
148
|
+
END_OF_PROGRAM
|
149
|
+
|
150
|
+
$idVertexProg,$idFragProg = glGenProgramsARB(2)
|
151
|
+
|
152
|
+
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, $idVertexProg)
|
153
|
+
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, $vertexProg)
|
154
|
+
|
155
|
+
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, $idFragProg)
|
156
|
+
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, $fragProg)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Terminate Vertex/Fragment Programs
|
160
|
+
def termProgs
|
161
|
+
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0)
|
162
|
+
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0)
|
163
|
+
|
164
|
+
glDeleteProgramsARB([$idVertexProg,$idFragProg])
|
165
|
+
end
|
166
|
+
|
167
|
+
# FBO Status handler
|
168
|
+
def statusFBO
|
169
|
+
stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)
|
170
|
+
return if (stat==0 || stat == GL_FRAMEBUFFER_COMPLETE_EXT)
|
171
|
+
printf("FBO status: %04X\n", stat)
|
172
|
+
exit(0)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Initialize Framebuffers
|
176
|
+
def initFBO
|
177
|
+
$idTexture = glGenTextures(1)[0]
|
178
|
+
$idFrameBuffer = glGenFramebuffersEXT(1)[0]
|
179
|
+
$idRenderBuffer = glGenRenderbuffersEXT(1)[0]
|
180
|
+
|
181
|
+
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, $idFrameBuffer)
|
182
|
+
glBindTexture(GL_TEXTURE_2D, $idTexture)
|
183
|
+
|
184
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, $textureWidth, $textureHeight,
|
185
|
+
0, GL_RGBA, GL_UNSIGNED_BYTE, nil)
|
186
|
+
|
187
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
188
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
189
|
+
|
190
|
+
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
191
|
+
GL_TEXTURE_2D, $idTexture, 0)
|
192
|
+
|
193
|
+
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, $idRenderBuffer)
|
194
|
+
|
195
|
+
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
|
196
|
+
$textureWidth, $textureHeight)
|
197
|
+
|
198
|
+
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
|
199
|
+
GL_RENDERBUFFER_EXT, $idRenderBuffer)
|
200
|
+
|
201
|
+
statusFBO()
|
202
|
+
end
|
203
|
+
|
204
|
+
# FBO texture renderer
|
205
|
+
def renderFBO
|
206
|
+
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, $idFrameBuffer)
|
207
|
+
|
208
|
+
glLoadIdentity()
|
209
|
+
glTranslated(-0.75, -0.85, -2.5)
|
210
|
+
|
211
|
+
glRotated($rotTeapotX, 1.0, 0.0, 0.0)
|
212
|
+
$rotTeapotX += 0.5
|
213
|
+
|
214
|
+
glRotated($rotTeapotY, 0.0, 1.0, 0.0)
|
215
|
+
$rotTeapotY += 1.0
|
216
|
+
|
217
|
+
glClearColor(0, 0, 0, 0)
|
218
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
219
|
+
glColor3d(1.0, 1.0, 1.0)
|
220
|
+
|
221
|
+
glutWireTeapot(0.125)
|
222
|
+
|
223
|
+
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Terminate FBO objects
|
227
|
+
def termFBO
|
228
|
+
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)
|
229
|
+
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
|
230
|
+
glBindTexture(GL_TEXTURE_2D, 0)
|
231
|
+
|
232
|
+
glDeleteRenderbuffersEXT($idRenderBuffer)
|
233
|
+
glDeleteFramebuffersEXT($idFrameBuffer)
|
234
|
+
glDeleteTextures($idTexture)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Resize Window
|
238
|
+
def resizeScene(width,height)
|
239
|
+
if (height==0)
|
240
|
+
height = 1
|
241
|
+
end
|
242
|
+
|
243
|
+
glViewport(0, 0, width, height)
|
244
|
+
|
245
|
+
glMatrixMode(GL_PROJECTION)
|
246
|
+
glLoadIdentity()
|
247
|
+
gluPerspective(45.0,width.to_f/height.to_f,0.1,100.0)
|
248
|
+
|
249
|
+
glMatrixMode(GL_MODELVIEW)
|
250
|
+
|
251
|
+
$windowWidth = width
|
252
|
+
$windowHeight = height
|
253
|
+
end
|
254
|
+
|
255
|
+
# Initialize OpenGL Environment
|
256
|
+
def init
|
257
|
+
checkVersion
|
258
|
+
initExtensions
|
259
|
+
|
260
|
+
resizeScene($windowWidth, $windowHeight)
|
261
|
+
|
262
|
+
initFBO
|
263
|
+
initProgs
|
264
|
+
end
|
265
|
+
|
266
|
+
# Terminate OpenGL Environment
|
267
|
+
def term
|
268
|
+
# Display benchmark
|
269
|
+
endBench($appBench)
|
270
|
+
printBench()
|
271
|
+
|
272
|
+
# Disable app
|
273
|
+
glutHideWindow()
|
274
|
+
glutKeyboardFunc(nil)
|
275
|
+
glutSpecialFunc(nil)
|
276
|
+
glutIdleFunc(nil)
|
277
|
+
glutReshapeFunc(nil)
|
278
|
+
|
279
|
+
# Release Framebuffers
|
280
|
+
termProgs()
|
281
|
+
termFBO()
|
282
|
+
|
283
|
+
# Now we can destroy window
|
284
|
+
glutDestroyWindow($idWindow)
|
285
|
+
exit(0)
|
286
|
+
end
|
287
|
+
|
288
|
+
# Frame handler
|
289
|
+
display = lambda do
|
290
|
+
# Run benchmark CYCLES times
|
291
|
+
$frames += 1
|
292
|
+
term() if ($frames > CYCLES)
|
293
|
+
startBench($frameBench)
|
294
|
+
|
295
|
+
# Render animated texture
|
296
|
+
startBench($textureBench)
|
297
|
+
renderFBO()
|
298
|
+
endBench($textureBench)
|
299
|
+
|
300
|
+
# Set up ModelView
|
301
|
+
glMatrixMode(GL_MODELVIEW)
|
302
|
+
glLoadIdentity()
|
303
|
+
glTranslatef(0.0,0.0,-5.0)
|
304
|
+
glRotated(0.0,1.0,0.0,0.0)
|
305
|
+
glRotated($rotY,0.0,1.0,0.0)
|
306
|
+
$rotY += $incY
|
307
|
+
|
308
|
+
# Set attributes
|
309
|
+
glEnable(GL_TEXTURE_2D)
|
310
|
+
glEnable(GL_DEPTH_TEST)
|
311
|
+
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL)
|
312
|
+
|
313
|
+
# Clear render buffer and set teapot color
|
314
|
+
glClearColor(0.2, 0.2, 0.2, 1.0)
|
315
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
316
|
+
glColor3d(0.9, 0.45, 0.0)
|
317
|
+
|
318
|
+
# Render the teapot using our shader
|
319
|
+
startBench($teapotBench)
|
320
|
+
glEnable(GL_VERTEX_PROGRAM_ARB)
|
321
|
+
glEnable(GL_FRAGMENT_PROGRAM_ARB)
|
322
|
+
|
323
|
+
glutSolidTeapot(1.0)
|
324
|
+
|
325
|
+
glDisable(GL_FRAGMENT_PROGRAM_ARB)
|
326
|
+
glDisable(GL_VERTEX_PROGRAM_ARB)
|
327
|
+
endBench($teapotBench)
|
328
|
+
|
329
|
+
# Double-buffer and done
|
330
|
+
glutSwapBuffers()
|
331
|
+
endBench($frameBench)
|
332
|
+
end
|
333
|
+
|
334
|
+
# Keyboard handler
|
335
|
+
keyPressed = lambda do |key,x,y|
|
336
|
+
term()
|
337
|
+
end
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
# Main app
|
342
|
+
|
343
|
+
glutInit()
|
344
|
+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA)
|
345
|
+
glutInitWindowSize($windowWidth,$windowHeight)
|
346
|
+
|
347
|
+
$idWindow = glutCreateWindow(PROGRAM)
|
348
|
+
|
349
|
+
glutDisplayFunc(display)
|
350
|
+
glutIdleFunc(display)
|
351
|
+
#glutReshapeFunc(resizeScene)
|
352
|
+
glutKeyboardFunc(keyPressed)
|
353
|
+
|
354
|
+
init()
|
355
|
+
startBench($appBench)
|
356
|
+
glutMainLoop()
|
357
|
+
exit(0)
|