ruby-opengl2 0.60.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +80 -0
- data/examples/NeHe/nehe_lesson02.rb +117 -0
- data/examples/NeHe/nehe_lesson03.rb +122 -0
- data/examples/NeHe/nehe_lesson04.rb +133 -0
- data/examples/NeHe/nehe_lesson05.rb +186 -0
- data/examples/NeHe/nehe_lesson36.rb +303 -0
- data/examples/OrangeBook/3Dlabs-License.txt +33 -0
- data/examples/OrangeBook/brick.frag +36 -0
- data/examples/OrangeBook/brick.rb +376 -0
- data/examples/OrangeBook/brick.vert +41 -0
- data/examples/OrangeBook/particle.frag +17 -0
- data/examples/OrangeBook/particle.rb +406 -0
- data/examples/OrangeBook/particle.vert +38 -0
- data/examples/README +16 -0
- data/examples/RedBook/aapoly.rb +142 -0
- data/examples/RedBook/aargb.rb +119 -0
- data/examples/RedBook/accanti.rb +162 -0
- data/examples/RedBook/accpersp.rb +215 -0
- data/examples/RedBook/alpha.rb +123 -0
- data/examples/RedBook/alpha3D.rb +158 -0
- data/examples/RedBook/bezcurve.rb +105 -0
- data/examples/RedBook/bezmesh.rb +137 -0
- data/examples/RedBook/checker.rb +124 -0
- data/examples/RedBook/clip.rb +95 -0
- data/examples/RedBook/colormat.rb +135 -0
- data/examples/RedBook/cube.rb +69 -0
- data/examples/RedBook/depthcue.rb +99 -0
- data/examples/RedBook/dof.rb +205 -0
- data/examples/RedBook/double.rb +105 -0
- data/examples/RedBook/drawf.rb +91 -0
- data/examples/RedBook/feedback.rb +145 -0
- data/examples/RedBook/fog.rb +167 -0
- data/examples/RedBook/font.rb +151 -0
- data/examples/RedBook/hello.rb +79 -0
- data/examples/RedBook/image.rb +137 -0
- data/examples/RedBook/jitter.rb +207 -0
- data/examples/RedBook/lines.rb +128 -0
- data/examples/RedBook/list.rb +111 -0
- data/examples/RedBook/material.rb +275 -0
- data/examples/RedBook/mipmap.rb +156 -0
- data/examples/RedBook/model.rb +113 -0
- data/examples/RedBook/movelight.rb +132 -0
- data/examples/RedBook/pickdepth.rb +179 -0
- data/examples/RedBook/planet.rb +108 -0
- data/examples/RedBook/quadric.rb +158 -0
- data/examples/RedBook/robot.rb +115 -0
- data/examples/RedBook/select.rb +196 -0
- data/examples/RedBook/smooth.rb +95 -0
- data/examples/RedBook/stencil.rb +163 -0
- data/examples/RedBook/stroke.rb +167 -0
- data/examples/RedBook/surface.rb +166 -0
- data/examples/RedBook/teaambient.rb +132 -0
- data/examples/RedBook/teapots.rb +182 -0
- data/examples/RedBook/tess.rb +183 -0
- data/examples/RedBook/texbind.rb +147 -0
- data/examples/RedBook/texgen.rb +169 -0
- data/examples/RedBook/texturesurf.rb +128 -0
- data/examples/RedBook/varray.rb +159 -0
- data/examples/RedBook/wrap.rb +148 -0
- data/examples/misc/OGLBench.rb +337 -0
- data/examples/misc/anisotropic.rb +194 -0
- data/examples/misc/fbo_test.rb +356 -0
- data/examples/misc/font-glut.rb +46 -0
- data/examples/misc/glfwtest.rb +30 -0
- data/examples/misc/plane.rb +161 -0
- data/examples/misc/readpixel.rb +65 -0
- data/examples/misc/sdltest.rb +34 -0
- data/examples/misc/trislam.rb +828 -0
- data/ext/common/common.h +423 -0
- data/ext/common/conv.h +243 -0
- data/ext/common/funcdef.h +280 -0
- data/ext/common/gl-enums.h +10031 -0
- data/ext/common/gl-error.h +23 -0
- data/ext/common/gl-types.h +63 -0
- data/ext/common/glu-enums.h +463 -0
- data/ext/gl/gl-1.0-1.1.c +2811 -0
- data/ext/gl/gl-1.2.c +814 -0
- data/ext/gl/gl-1.3.c +443 -0
- data/ext/gl/gl-1.4.c +348 -0
- data/ext/gl/gl-1.5.c +225 -0
- data/ext/gl/gl-2.0.c +657 -0
- data/ext/gl/gl-2.1.c +57 -0
- data/ext/gl/gl-enums.c +3354 -0
- data/ext/gl/gl-error.c +104 -0
- data/ext/gl/gl-ext-3dfx.c +27 -0
- data/ext/gl/gl-ext-arb.c +866 -0
- data/ext/gl/gl-ext-ati.c +41 -0
- data/ext/gl/gl-ext-ext.c +889 -0
- data/ext/gl/gl-ext-gremedy.c +41 -0
- data/ext/gl/gl-ext-nv.c +679 -0
- data/ext/gl/gl.c +214 -0
- data/ext/gl/mkrf_conf.rb +37 -0
- data/ext/glu/glu-enums.c +164 -0
- data/ext/glu/glu.c +1530 -0
- data/ext/glu/mkrf_conf.rb +39 -0
- data/ext/glut/glut.c +1627 -0
- data/ext/glut/mkrf_conf.rb +37 -0
- data/lib/opengl.rb +84 -0
- data/test/README +10 -0
- data/test/tc_common.rb +98 -0
- data/test/tc_ext_arb.rb +467 -0
- data/test/tc_ext_ati.rb +33 -0
- data/test/tc_ext_ext.rb +551 -0
- data/test/tc_ext_gremedy.rb +36 -0
- data/test/tc_ext_nv.rb +357 -0
- data/test/tc_func_10_11.rb +1281 -0
- data/test/tc_func_12.rb +186 -0
- data/test/tc_func_13.rb +229 -0
- data/test/tc_func_14.rb +197 -0
- data/test/tc_func_15.rb +270 -0
- data/test/tc_func_20.rb +346 -0
- data/test/tc_func_21.rb +541 -0
- data/test/tc_glu.rb +310 -0
- data/test/tc_include_gl.rb +35 -0
- data/test/tc_misc.rb +54 -0
- data/test/tc_require_gl.rb +34 -0
- metadata +164 -0
data/Rakefile
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#-*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
|
4
|
+
#
|
5
|
+
# This program is distributed under the terms of the MIT license.
|
6
|
+
# See the included MIT-LICENSE file for the terms of this license.
|
7
|
+
#
|
8
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
9
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
10
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
11
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
12
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
14
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
|
16
|
+
require 'rake'
|
17
|
+
require 'rake/clean'
|
18
|
+
require 'rubygems/package_task'
|
19
|
+
require 'rake/testtask'
|
20
|
+
require 'mkrf/rakehelper'
|
21
|
+
|
22
|
+
|
23
|
+
CLEAN.include("ext/gl*/Rakefile", "ext/*/mkrf.log", "ext/*/*.so",
|
24
|
+
"ext/**/*.bundle", "lib/*.so", "lib/*.bundle", "ext/*/*.o{,bj}",
|
25
|
+
"ext/*/*.lib", "ext/*/*.exp", "ext/*/*.pdb",
|
26
|
+
"pkg")
|
27
|
+
|
28
|
+
setup_extension('gl', 'gl')
|
29
|
+
setup_extension('glu', 'glu')
|
30
|
+
setup_extension('glut', 'glut')
|
31
|
+
|
32
|
+
desc 'Does a full compile'
|
33
|
+
task :default => [:gl, :glu, :glut, :fixpermissions]
|
34
|
+
|
35
|
+
task :fixpermissions do
|
36
|
+
# fix wrong lib permissions (mkrf bug ?)
|
37
|
+
Dir["lib/*.so","lib/*.bundle"].each do |fname|
|
38
|
+
File.chmod(0755,fname)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :extension => :default
|
43
|
+
|
44
|
+
|
45
|
+
desc 'Runs unit tests.'
|
46
|
+
Rake::TestTask.new do |t|
|
47
|
+
t.libs << "test"
|
48
|
+
t.test_files = FileList['test/tc_*.rb']
|
49
|
+
t.verbose = true
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Runs unit tests.'
|
53
|
+
task :test_all => [:test]
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
############# gems #############
|
59
|
+
|
60
|
+
# common specification for source and binary gems
|
61
|
+
spec = Gem::Specification.new do |s|
|
62
|
+
s.name = "ruby-opengl2"
|
63
|
+
s.version = "0.60.2"
|
64
|
+
s.authors = [ "Alain Hoang", "Jan Dvorak", "Minh Thu Vo", "James Adam" ]
|
65
|
+
s.homepage = "http://ruby-opengl.rubyforge.org"
|
66
|
+
s.email = "ruby-opengl-devel@rubyforge.org"
|
67
|
+
s.rubyforge_project = 'ruby-opengl2'
|
68
|
+
s.platform = Gem::Platform::RUBY
|
69
|
+
s.summary = "OpenGL Interface for Ruby"
|
70
|
+
s.description = "OpenGL Interface for Ruby"
|
71
|
+
s.require_path = "lib"
|
72
|
+
s.has_rdoc = false
|
73
|
+
s.files = FileList["{lib,ext,doc,examples,test}/**/*"]
|
74
|
+
s.extensions = ['Rakefile']
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create a task for creating a ruby source gem
|
78
|
+
Gem::PackageTask.new(spec) do |pkg|
|
79
|
+
pkg.need_tar = true
|
80
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
# Name: nehe_lesson02.rb
|
3
|
+
# Purpose: An implementation of NeHe's OpenGL Lesson #02
|
4
|
+
# using ruby-opengl (http://nehe.gamedev.net/)
|
5
|
+
#
|
6
|
+
|
7
|
+
require "gl"
|
8
|
+
require "glu"
|
9
|
+
require "glut"
|
10
|
+
require "mathn"
|
11
|
+
|
12
|
+
# Add GL and GLUT namespaces in to make porting easier
|
13
|
+
include Gl
|
14
|
+
include Glu
|
15
|
+
include Glut
|
16
|
+
|
17
|
+
# Placeholder for the window object
|
18
|
+
window = ""
|
19
|
+
|
20
|
+
def init_gl_window(width = 640, height = 480)
|
21
|
+
# Background color to black
|
22
|
+
glClearColor(0.0, 0.0, 0.0, 0)
|
23
|
+
# Enables clearing of depth buffer
|
24
|
+
glClearDepth(1.0)
|
25
|
+
# Set type of depth test
|
26
|
+
glDepthFunc(GL_LEQUAL)
|
27
|
+
# Enable depth testing
|
28
|
+
glEnable(GL_DEPTH_TEST)
|
29
|
+
# Enable smooth color shading
|
30
|
+
glShadeModel(GL_SMOOTH)
|
31
|
+
|
32
|
+
glMatrixMode(GL_PROJECTION)
|
33
|
+
glLoadIdentity
|
34
|
+
# Calculate aspect ratio of the window
|
35
|
+
gluPerspective(45.0, width / height, 0.1, 100.0)
|
36
|
+
|
37
|
+
glMatrixMode(GL_MODELVIEW)
|
38
|
+
|
39
|
+
draw_gl_scene
|
40
|
+
end
|
41
|
+
|
42
|
+
#reshape = Proc.new do |width, height|
|
43
|
+
def reshape(width, height)
|
44
|
+
height = 1 if height == 0
|
45
|
+
|
46
|
+
# Reset current viewpoint and perspective transformation
|
47
|
+
glViewport(0, 0, width, height)
|
48
|
+
|
49
|
+
glMatrixMode(GL_PROJECTION)
|
50
|
+
glLoadIdentity
|
51
|
+
|
52
|
+
gluPerspective(45.0, width / height, 0.1, 100.0)
|
53
|
+
end
|
54
|
+
|
55
|
+
#draw_gl_scene = Proc.new do
|
56
|
+
def draw_gl_scene
|
57
|
+
# Clear the screen and depth buffer
|
58
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
59
|
+
|
60
|
+
# Reset the view
|
61
|
+
glMatrixMode(GL_MODELVIEW)
|
62
|
+
glLoadIdentity
|
63
|
+
|
64
|
+
# Move left 1.5 units and into the screen 6.0 units
|
65
|
+
glTranslatef(-1.5, 0.0, -6.0)
|
66
|
+
|
67
|
+
# Draw a triangle
|
68
|
+
glBegin(GL_POLYGON)
|
69
|
+
glVertex3f( 0.0, 1.0, 0.0)
|
70
|
+
glVertex3f( 1.0, -1.0, 0.0)
|
71
|
+
glVertex3f(-1.0, -1.0, 0.0)
|
72
|
+
glEnd
|
73
|
+
|
74
|
+
# Move right 3 units
|
75
|
+
glTranslatef(3.0, 0.0, 0.0)
|
76
|
+
|
77
|
+
# Draw a rectangle
|
78
|
+
glBegin(GL_QUADS)
|
79
|
+
glVertex3f(-1.0, 1.0, 0.0)
|
80
|
+
glVertex3f( 1.0, 1.0, 0.0)
|
81
|
+
glVertex3f( 1.0, -1.0, 0.0)
|
82
|
+
glVertex3f(-1.0, -1.0, 0.0)
|
83
|
+
glEnd
|
84
|
+
|
85
|
+
# Swap buffers for display
|
86
|
+
glutSwapBuffers
|
87
|
+
end
|
88
|
+
|
89
|
+
# The idle function to handle
|
90
|
+
def idle
|
91
|
+
glutPostRedisplay
|
92
|
+
end
|
93
|
+
|
94
|
+
# Keyboard handler to exit when ESC is typed
|
95
|
+
keyboard = lambda do |key, x, y|
|
96
|
+
case(key)
|
97
|
+
when ?\e
|
98
|
+
glutDestroyWindow(window)
|
99
|
+
exit(0)
|
100
|
+
end
|
101
|
+
glutPostRedisplay
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
# Initliaze our GLUT code
|
106
|
+
glutInit;
|
107
|
+
# Setup a double buffer, RGBA color, alpha components and depth buffer
|
108
|
+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
|
109
|
+
glutInitWindowSize(640, 480);
|
110
|
+
glutInitWindowPosition(0, 0);
|
111
|
+
window = glutCreateWindow("NeHe Lesson 02 - ruby-opengl version");
|
112
|
+
glutDisplayFunc(method(:draw_gl_scene).to_proc);
|
113
|
+
glutReshapeFunc(method(:reshape).to_proc);
|
114
|
+
glutIdleFunc(method(:idle).to_proc);
|
115
|
+
glutKeyboardFunc(keyboard);
|
116
|
+
init_gl_window(640, 480)
|
117
|
+
glutMainLoop();
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
# Name: nehe_lesson03.rb
|
3
|
+
# Purpose: An implementation of NeHe's OpenGL Lesson #03
|
4
|
+
# using ruby-opengl (http://nehe.gamedev.net/)
|
5
|
+
#
|
6
|
+
|
7
|
+
require "gl"
|
8
|
+
require "glu"
|
9
|
+
require "glut"
|
10
|
+
require "mathn"
|
11
|
+
|
12
|
+
# Add GL and GLUT namespaces in to make porting easier
|
13
|
+
include Gl
|
14
|
+
include Glu
|
15
|
+
include Glut
|
16
|
+
|
17
|
+
# Placeholder for the window object
|
18
|
+
window = ""
|
19
|
+
|
20
|
+
def init_gl_window(width = 640, height = 480)
|
21
|
+
# Background color to black
|
22
|
+
glClearColor(0.0, 0.0, 0.0, 0)
|
23
|
+
# Enables clearing of depth buffer
|
24
|
+
glClearDepth(1.0)
|
25
|
+
# Set type of depth test
|
26
|
+
glDepthFunc(GL_LEQUAL)
|
27
|
+
# Enable depth testing
|
28
|
+
glEnable(GL_DEPTH_TEST)
|
29
|
+
# Enable smooth color shading
|
30
|
+
glShadeModel(GL_SMOOTH)
|
31
|
+
|
32
|
+
glMatrixMode(GL_PROJECTION)
|
33
|
+
glLoadIdentity
|
34
|
+
# Calculate aspect ratio of the window
|
35
|
+
gluPerspective(45.0, width / height, 0.1, 100.0)
|
36
|
+
|
37
|
+
glMatrixMode(GL_MODELVIEW)
|
38
|
+
|
39
|
+
draw_gl_scene
|
40
|
+
end
|
41
|
+
|
42
|
+
#reshape = Proc.new do |width, height|
|
43
|
+
def reshape(width, height)
|
44
|
+
height = 1 if height == 0
|
45
|
+
|
46
|
+
# Reset current viewpoint and perspective transformation
|
47
|
+
glViewport(0, 0, width, height)
|
48
|
+
|
49
|
+
glMatrixMode(GL_PROJECTION)
|
50
|
+
glLoadIdentity
|
51
|
+
|
52
|
+
gluPerspective(45.0, width / height, 0.1, 100.0)
|
53
|
+
end
|
54
|
+
|
55
|
+
#draw_gl_scene = Proc.new do
|
56
|
+
def draw_gl_scene
|
57
|
+
# Clear the screen and depth buffer
|
58
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
59
|
+
|
60
|
+
# Reset the view
|
61
|
+
glMatrixMode(GL_MODELVIEW)
|
62
|
+
glLoadIdentity
|
63
|
+
|
64
|
+
# Move left 1.5 units and into the screen 6.0 units
|
65
|
+
glTranslatef(-1.5, 0.0, -6.0)
|
66
|
+
|
67
|
+
# Draw a triangle
|
68
|
+
glBegin(GL_POLYGON)
|
69
|
+
glColor3f(1.0, 0.0, 0.0)
|
70
|
+
glVertex3f( 0.0, 1.0, 0.0)
|
71
|
+
glColor3f(0.0, 1.0, 0.0)
|
72
|
+
glVertex3f( 1.0, -1.0, 0.0)
|
73
|
+
glColor3f(0.0, 0.0, 1.0)
|
74
|
+
glVertex3f(-1.0, -1.0, 0.0)
|
75
|
+
glEnd
|
76
|
+
|
77
|
+
# Move right 3 units
|
78
|
+
glTranslatef(3.0, 0.0, 0.0)
|
79
|
+
|
80
|
+
# Draw a rectangle
|
81
|
+
# Set it to a blue color one time only
|
82
|
+
glColor3f(0.5, 0.5, 1.0)
|
83
|
+
glBegin(GL_QUADS)
|
84
|
+
glVertex3f(-1.0, 1.0, 0.0)
|
85
|
+
glVertex3f( 1.0, 1.0, 0.0)
|
86
|
+
glVertex3f( 1.0, -1.0, 0.0)
|
87
|
+
glVertex3f(-1.0, -1.0, 0.0)
|
88
|
+
glEnd
|
89
|
+
|
90
|
+
# Swap buffers for display
|
91
|
+
glutSwapBuffers
|
92
|
+
end
|
93
|
+
|
94
|
+
# The idle function to handle
|
95
|
+
def idle
|
96
|
+
glutPostRedisplay
|
97
|
+
end
|
98
|
+
|
99
|
+
# Keyboard handler to exit when ESC is typed
|
100
|
+
keyboard = lambda do |key, x, y|
|
101
|
+
case(key)
|
102
|
+
when ?\e
|
103
|
+
glutDestroyWindow(window)
|
104
|
+
exit(0)
|
105
|
+
end
|
106
|
+
glutPostRedisplay
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# Initliaze our GLUT code
|
111
|
+
glutInit;
|
112
|
+
# Setup a double buffer, RGBA color, alpha components and depth buffer
|
113
|
+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
|
114
|
+
glutInitWindowSize(640, 480);
|
115
|
+
glutInitWindowPosition(0, 0);
|
116
|
+
window = glutCreateWindow("NeHe Lesson 03 - ruby-opengl version");
|
117
|
+
glutDisplayFunc(method(:draw_gl_scene).to_proc);
|
118
|
+
glutReshapeFunc(method(:reshape).to_proc);
|
119
|
+
glutIdleFunc(method(:idle).to_proc);
|
120
|
+
glutKeyboardFunc(keyboard);
|
121
|
+
init_gl_window(640, 480)
|
122
|
+
glutMainLoop();
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
# Name: nehe_lesson04.rb
|
3
|
+
# Purpose: An implementation of NeHe's OpenGL Lesson #04
|
4
|
+
# using ruby-opengl (http://nehe.gamedev.net/)
|
5
|
+
#
|
6
|
+
|
7
|
+
require "gl"
|
8
|
+
require "glu"
|
9
|
+
require "glut"
|
10
|
+
require "mathn"
|
11
|
+
|
12
|
+
# Add GL and GLUT namespaces in to make porting easier
|
13
|
+
include Gl
|
14
|
+
include Glu
|
15
|
+
include Glut
|
16
|
+
|
17
|
+
# Placeholder for the window object
|
18
|
+
$window = ""
|
19
|
+
# Angle for the triangle (Global)
|
20
|
+
$triangle_angle = 0
|
21
|
+
# Angle for the quadrilateral (Global)
|
22
|
+
$quad_angle = 0
|
23
|
+
|
24
|
+
def init_gl_window(width = 640, height = 480)
|
25
|
+
# Background color to black
|
26
|
+
glClearColor(0.0, 0.0, 0.0, 0)
|
27
|
+
# Enables clearing of depth buffer
|
28
|
+
glClearDepth(1.0)
|
29
|
+
# Set type of depth test
|
30
|
+
glDepthFunc(GL_LEQUAL)
|
31
|
+
# Enable depth testing
|
32
|
+
glEnable(GL_DEPTH_TEST)
|
33
|
+
# Enable smooth color shading
|
34
|
+
glShadeModel(GL_SMOOTH)
|
35
|
+
|
36
|
+
glMatrixMode(GL_PROJECTION)
|
37
|
+
glLoadIdentity
|
38
|
+
# Calculate aspect ratio of the window
|
39
|
+
gluPerspective(45.0, width / height, 0.1, 100.0)
|
40
|
+
|
41
|
+
glMatrixMode(GL_MODELVIEW)
|
42
|
+
|
43
|
+
draw_gl_scene
|
44
|
+
end
|
45
|
+
|
46
|
+
#reshape = Proc.new do |width, height|
|
47
|
+
def reshape(width, height)
|
48
|
+
height = 1 if height == 0
|
49
|
+
|
50
|
+
# Reset current viewpoint and perspective transformation
|
51
|
+
glViewport(0, 0, width, height)
|
52
|
+
|
53
|
+
glMatrixMode(GL_PROJECTION)
|
54
|
+
glLoadIdentity
|
55
|
+
|
56
|
+
gluPerspective(45.0, width / height, 0.1, 100.0)
|
57
|
+
end
|
58
|
+
|
59
|
+
#draw_gl_scene = Proc.new do
|
60
|
+
def draw_gl_scene
|
61
|
+
# Clear the screen and depth buffer
|
62
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
63
|
+
|
64
|
+
# Reset the view
|
65
|
+
glMatrixMode(GL_MODELVIEW)
|
66
|
+
glLoadIdentity
|
67
|
+
|
68
|
+
# Move left 1.5 units and into the screen 6.0 units
|
69
|
+
glTranslatef(-1.5, 0.0, -6.0)
|
70
|
+
|
71
|
+
# Rotate the triangle on the Y-axis
|
72
|
+
glRotatef($triangle_angle, 0.0, 1.0, 0.0)
|
73
|
+
# Draw a triangle
|
74
|
+
glBegin(GL_POLYGON)
|
75
|
+
glColor3f(1.0, 0.0, 0.0)
|
76
|
+
glVertex3f( 0.0, 1.0, 0.0)
|
77
|
+
glColor3f(0.0, 1.0, 0.0)
|
78
|
+
glVertex3f( 1.0, -1.0, 0.0)
|
79
|
+
glColor3f(0.0, 0.0, 1.0)
|
80
|
+
glVertex3f(-1.0, -1.0, 0.0)
|
81
|
+
glEnd
|
82
|
+
|
83
|
+
# Move right 3 units
|
84
|
+
glLoadIdentity
|
85
|
+
glTranslatef(1.5, 0.0, -6.0)
|
86
|
+
|
87
|
+
# Draw a quadrilateral
|
88
|
+
# Rotate the quad on the X-axis
|
89
|
+
glRotatef($quad_angle, 1.0, 0.0, 0.0)
|
90
|
+
# Set it to a blue color one time only
|
91
|
+
glColor3f(0.5, 0.5, 1.0)
|
92
|
+
glBegin(GL_QUADS)
|
93
|
+
glVertex3f(-1.0, 1.0, 0.0)
|
94
|
+
glVertex3f( 1.0, 1.0, 0.0)
|
95
|
+
glVertex3f( 1.0, -1.0, 0.0)
|
96
|
+
glVertex3f(-1.0, -1.0, 0.0)
|
97
|
+
glEnd
|
98
|
+
|
99
|
+
$triangle_angle += 0.2
|
100
|
+
$quad_angle -= 0.15
|
101
|
+
# Swap buffers for display
|
102
|
+
glutSwapBuffers
|
103
|
+
end
|
104
|
+
|
105
|
+
# The idle function to handle
|
106
|
+
def idle
|
107
|
+
glutPostRedisplay
|
108
|
+
end
|
109
|
+
|
110
|
+
# Keyboard handler to exit when ESC is typed
|
111
|
+
keyboard = lambda do |key, x, y|
|
112
|
+
case(key)
|
113
|
+
when ?\e
|
114
|
+
glutDestroyWindow($window)
|
115
|
+
exit(0)
|
116
|
+
end
|
117
|
+
glutPostRedisplay
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# Initliaze our GLUT code
|
122
|
+
glutInit;
|
123
|
+
# Setup a double buffer, RGBA color, alpha components and depth buffer
|
124
|
+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
|
125
|
+
glutInitWindowSize(640, 480);
|
126
|
+
glutInitWindowPosition(0, 0);
|
127
|
+
$window = glutCreateWindow("NeHe Lesson 04 - ruby-opengl version");
|
128
|
+
glutDisplayFunc(method(:draw_gl_scene).to_proc);
|
129
|
+
glutReshapeFunc(method(:reshape).to_proc);
|
130
|
+
glutIdleFunc(method(:idle).to_proc);
|
131
|
+
glutKeyboardFunc(keyboard);
|
132
|
+
init_gl_window(640, 480)
|
133
|
+
glutMainLoop();
|