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
data/Rakefile
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
#-*-ruby-*-
|
3
|
+
#
|
4
|
+
# Copyright (C) 2006 John M. Gabriele <jmg3000@gmail.com>
|
5
|
+
# Copyright (C) Eric Hodel <drbrain@segment7.net>
|
6
|
+
#
|
7
|
+
# This program is distributed under the terms of the MIT license.
|
8
|
+
# See the included MIT-LICENSE file for the terms of this license.
|
9
|
+
#
|
10
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
11
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
12
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
13
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
14
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
15
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
16
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
17
|
+
|
18
|
+
require 'bundler'
|
19
|
+
require 'bundler/gem_helper'
|
20
|
+
require 'rake/extensiontask'
|
21
|
+
|
22
|
+
class OpenglGemHelper < Bundler::GemHelper
|
23
|
+
attr_accessor :cross_platforms
|
24
|
+
|
25
|
+
def install
|
26
|
+
super
|
27
|
+
|
28
|
+
task "release:guard_clean" => ["release:update_history"]
|
29
|
+
|
30
|
+
task "release:update_history" do
|
31
|
+
update_history
|
32
|
+
end
|
33
|
+
|
34
|
+
task "release:rubygem_push" => ["gem:windows"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def hfile
|
38
|
+
"History.md"
|
39
|
+
end
|
40
|
+
|
41
|
+
def headline
|
42
|
+
'([^\w]*)(\d+\.\d+\.\d+(?:\.\w+)?)([^\w]+)([2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D])([^\w]*|$)'
|
43
|
+
end
|
44
|
+
|
45
|
+
def reldate
|
46
|
+
Time.now.strftime("%Y-%m-%d")
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_history
|
50
|
+
hin = File.read(hfile)
|
51
|
+
hout = hin.sub(/#{headline}/) do
|
52
|
+
raise "#{hfile} isn't up-to-date for version #{version}" unless $2==version.to_s
|
53
|
+
$1 + $2 + $3 + reldate + $5
|
54
|
+
end
|
55
|
+
if hout != hin
|
56
|
+
Bundler.ui.confirm "Updating #{hfile} for release."
|
57
|
+
File.write(hfile, hout)
|
58
|
+
Rake::FileUtilsExt.sh "git", "commit", hfile, "-m", "Update release date in #{hfile}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def tag_version
|
63
|
+
Bundler.ui.confirm "Tag release with annotation:"
|
64
|
+
m = File.read(hfile).match(/(?<annotation>#{headline}.*?)#{headline}/m) || raise("Unable to find release notes in #{hfile}")
|
65
|
+
Bundler.ui.info(m[:annotation].gsub(/^/, " "))
|
66
|
+
IO.popen(["git", "tag", "--file=-", version_tag], "w") do |fd|
|
67
|
+
fd.write m[:annotation]
|
68
|
+
end
|
69
|
+
yield if block_given?
|
70
|
+
rescue
|
71
|
+
Bundler.ui.error "Untagging #{version_tag} due to error."
|
72
|
+
sh_with_code "git tag -d #{version_tag}"
|
73
|
+
raise
|
74
|
+
end
|
75
|
+
|
76
|
+
def rubygem_push(path)
|
77
|
+
cross_platforms.each do |ruby_platform|
|
78
|
+
super(path.gsub(/\.gem\z/, "-#{ruby_platform}.gem"))
|
79
|
+
end
|
80
|
+
super(path)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# spec = Gem::Specification.load('opengl.gemspec')
|
85
|
+
spec = Gem::Specification.load('danabr75-opengl')
|
86
|
+
|
87
|
+
Rake::ExtensionTask.new 'opengl', spec do |ext|
|
88
|
+
ext.lib_dir = 'lib/opengl'
|
89
|
+
|
90
|
+
ext.cross_compile = true
|
91
|
+
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
|
92
|
+
|
93
|
+
OpenglGemHelper.install_tasks
|
94
|
+
Bundler::GemHelper.instance.cross_platforms = ext.cross_platform
|
95
|
+
end
|
96
|
+
|
97
|
+
task :gem => :build
|
98
|
+
task :test => :compile do
|
99
|
+
sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# defines columns in the HTML extension list
|
104
|
+
GLEXT_VERSIONS = %w[svn 0.60 0.50]
|
105
|
+
|
106
|
+
desc 'Generate supported extension list.'
|
107
|
+
task :gen_glext_list do
|
108
|
+
sh "./utils/extlistgen.rb", "doc/extensions.txt.in", "doc/extensions.txt", *GLEXT_VERSIONS
|
109
|
+
end
|
110
|
+
|
111
|
+
cfiles = Dir["ext/opengl/*.c"].sort
|
112
|
+
fptrfiles = cfiles.map{|cf| [cf, "#{cf}.fptr"] }
|
113
|
+
fptrfiles.each do |cfile, fptrfile|
|
114
|
+
file fptrfile => [cfile, "ext/opengl/funcdef.h"] do |t|
|
115
|
+
args = RbConfig::CONFIG['CC'], "-E", cfile,
|
116
|
+
"-DGLFUNC_MAGIC_START=glfunc-", "-DGLFUNC_MAGIC_END=-glfunc",
|
117
|
+
"-DGLFUNC_MAGIC_APIENTRY=-glfunc-apientry-",
|
118
|
+
"-I#{RbConfig::CONFIG['rubyhdrdir']}", "-I#{RbConfig::CONFIG['rubyarchhdrdir']}",
|
119
|
+
"-Iext/opengl"
|
120
|
+
|
121
|
+
puts args.join(" ")
|
122
|
+
|
123
|
+
func = IO.popen(args) do |i|
|
124
|
+
i.read.scan(/glfunc- (.*?) -glfunc/).map{|m| "#{m[0].gsub("-glfunc-apientry-", "APIENTRY")};\n" }.join
|
125
|
+
end
|
126
|
+
File.write(t.name, func)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
CLEAN.include *fptrfiles.map(&:last)
|
130
|
+
|
131
|
+
multitask "ext/opengl/fptr_struct.h" => fptrfiles.map(&:last) do |t|
|
132
|
+
out = <<-EOT
|
133
|
+
#ifndef _FPTR_STRUCT_H_
|
134
|
+
#define _FPTR_STRUCT_H_
|
135
|
+
struct glfunc_ptrs {
|
136
|
+
EOT
|
137
|
+
t.prerequisites.map do |f|
|
138
|
+
File.readlines(f)
|
139
|
+
end.flatten.uniq.each do |func|
|
140
|
+
out << func
|
141
|
+
end
|
142
|
+
out << <<-EOT
|
143
|
+
};
|
144
|
+
#endif
|
145
|
+
EOT
|
146
|
+
|
147
|
+
File.write(t.name, out) unless File.exist?(t.name) && File.read(t.name) == out
|
148
|
+
end
|
149
|
+
|
150
|
+
task "ext/opengl/extconf.rb" => "ext/opengl/fptr_struct.h"
|
151
|
+
task :build => "ext/opengl/extconf.rb"
|
152
|
+
|
153
|
+
CLEAN.include "ext/opengl/fptr_struct.h"
|
154
|
+
|
155
|
+
# To reduce the gem file size strip mingw32 dlls before packaging
|
156
|
+
ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
|
157
|
+
task "tmp/x86-mingw32/stage/lib/opengl/#{ruby_version[/^\d+\.\d+/]}/opengl.so" do |t|
|
158
|
+
sh "i686-w64-mingw32-strip -S tmp/x86-mingw32/stage/lib/opengl/#{ruby_version[/^\d+\.\d+/]}/opengl.so"
|
159
|
+
end
|
160
|
+
|
161
|
+
task "tmp/x64-mingw32/stage/lib/opengl/#{ruby_version[/^\d+\.\d+/]}/opengl.so" do |t|
|
162
|
+
sh "x86_64-w64-mingw32-strip -S tmp/x64-mingw32/stage/lib/opengl/#{ruby_version[/^\d+\.\d+/]}/opengl.so"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
desc "Build windows binary gems per rake-compiler-dock."
|
167
|
+
task "gem:windows" do
|
168
|
+
require "rake_compiler_dock"
|
169
|
+
RakeCompilerDock.sh "rake cross native gem MAKE='nice make -j`nproc`'"
|
170
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opengl/bindings_version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "danabr75-opengl"
|
8
|
+
spec.version = Gl::BINDINGS_VERSION
|
9
|
+
spec.authors = ["Eric Hodel", "Lars Kanis", "Bla\u{17e} Hrastnik", "Alain Hoang", "Jan Dvorak", "Minh Thu Vo", "James Adam"]
|
10
|
+
spec.email = ["drbrain@segment7.net", "lars@greiz-reinsdorf.de", "blaz@mxxn.io", "", "", "", ""]
|
11
|
+
spec.summary = "An OpenGL wrapper for Ruby"
|
12
|
+
spec.description = "PATCHED FOR WINDOWS: An OpenGL wrapper for Ruby. opengl contains bindings for OpenGL.\n\nBe sure to check out\n{GLU}[https://github.com/larskanis/glu] and\n{GLUT}[https://github.com/larskanis/glut]\ngems."
|
13
|
+
spec.homepage = "https://github.com/larskanis/opengl"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0") +
|
17
|
+
["ext/opengl/fptr_struct.h"]
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.extensions = ["ext/opengl/extconf.rb"]
|
22
|
+
spec.rdoc_options = ["--main", "README.rdoc"]
|
23
|
+
|
24
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.3'
|
28
|
+
spec.add_development_dependency 'rake-compiler', '~> 1.0'
|
29
|
+
spec.add_development_dependency 'rake-compiler-dock', '~> 0.6.0'
|
30
|
+
spec.add_development_dependency 'glu', '~> 8.1'
|
31
|
+
spec.add_development_dependency 'glut', '~> 8.1'
|
32
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
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 'opengl'
|
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 = nil
|
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 do
|
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
|
+
end
|
73
|
+
|
74
|
+
# Move right 3 units
|
75
|
+
glTranslatef 3.0, 0.0, 0.0
|
76
|
+
|
77
|
+
# Draw a rectangle
|
78
|
+
glBegin GL_QUADS do
|
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
|
+
end
|
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
|
+
glutIdleFunc :idle
|
113
|
+
glutDisplayFunc :draw_gl_scene
|
114
|
+
glutReshapeFunc :reshape
|
115
|
+
glutKeyboardFunc keyboard
|
116
|
+
init_gl_window 640, 480
|
117
|
+
glutMainLoop
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
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 'opengl'
|
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 = nil
|
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 setting the color to red, green, blue for each respective
|
68
|
+
# vertex
|
69
|
+
glBegin GL_POLYGON do
|
70
|
+
glColor3f 1.0, 0.0, 0.0
|
71
|
+
glVertex3f 0.0, 1.0, 0.0
|
72
|
+
glColor3f 0.0, 1.0, 0.0
|
73
|
+
glVertex3f 1.0, -1.0, 0.0
|
74
|
+
glColor3f 0.0, 0.0, 1.0
|
75
|
+
glVertex3f -1.0, -1.0, 0.0
|
76
|
+
end
|
77
|
+
|
78
|
+
# Move right 3 units
|
79
|
+
glTranslatef 3.0, 0.0, 0.0
|
80
|
+
|
81
|
+
# Set the color to medium blue for all vertexes
|
82
|
+
glColor3f 0.5, 0.5, 1.0
|
83
|
+
# Draw a rectangle
|
84
|
+
glBegin GL_QUADS do
|
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
|
+
glVertex3f -1.0, -1.0, 0.0
|
89
|
+
end
|
90
|
+
|
91
|
+
# Swap buffers for display
|
92
|
+
glutSwapBuffers
|
93
|
+
end
|
94
|
+
|
95
|
+
# The idle function to handle
|
96
|
+
def idle
|
97
|
+
glutPostRedisplay
|
98
|
+
end
|
99
|
+
|
100
|
+
# Keyboard handler to exit when ESC is typed
|
101
|
+
keyboard = lambda do |key, x, y|
|
102
|
+
case key
|
103
|
+
when ?\e
|
104
|
+
glutDestroyWindow window
|
105
|
+
exit(0)
|
106
|
+
end
|
107
|
+
glutPostRedisplay
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Initliaze our GLUT code
|
112
|
+
glutInit
|
113
|
+
# Setup a double buffer, RGBA color, alpha components and depth buffer
|
114
|
+
glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
|
115
|
+
glutInitWindowSize 640, 480
|
116
|
+
glutInitWindowPosition 0, 0
|
117
|
+
window = glutCreateWindow "NeHe Lesson 03 - ruby-opengl version"
|
118
|
+
glutIdleFunc :idle
|
119
|
+
glutDisplayFunc :draw_gl_scene
|
120
|
+
glutReshapeFunc :reshape
|
121
|
+
glutKeyboardFunc keyboard
|
122
|
+
init_gl_window 640, 480
|
123
|
+
glutMainLoop
|