danabr75-opengl 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +29 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +6 -0
  5. data/.travis.yml +19 -0
  6. data/Gemfile +8 -0
  7. data/History.md +101 -0
  8. data/MIT-LICENSE +18 -0
  9. data/Manifest.txt +142 -0
  10. data/README.rdoc +105 -0
  11. data/Rakefile +170 -0
  12. data/danabr75-opengl.gemspec +32 -0
  13. data/examples/NeHe/NeHe.png +0 -0
  14. data/examples/NeHe/crate.png +0 -0
  15. data/examples/NeHe/glass.png +0 -0
  16. data/examples/NeHe/nehe_lesson02.rb +117 -0
  17. data/examples/NeHe/nehe_lesson03.rb +123 -0
  18. data/examples/NeHe/nehe_lesson04.rb +132 -0
  19. data/examples/NeHe/nehe_lesson05.rb +182 -0
  20. data/examples/NeHe/nehe_lesson06.rb +186 -0
  21. data/examples/NeHe/nehe_lesson07.rb +240 -0
  22. data/examples/NeHe/nehe_lesson08.rb +255 -0
  23. data/examples/NeHe/nehe_lesson09.rb +203 -0
  24. data/examples/NeHe/nehe_lesson11.rb +176 -0
  25. data/examples/NeHe/nehe_lesson12.rb +203 -0
  26. data/examples/NeHe/nehe_lesson16.rb +211 -0
  27. data/examples/NeHe/nehe_lesson19.rb +209 -0
  28. data/examples/NeHe/nehe_lesson36.rb +308 -0
  29. data/examples/NeHe/particle.png +0 -0
  30. data/examples/NeHe/star.png +0 -0
  31. data/examples/NeHe/tim.png +0 -0
  32. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  33. data/examples/OrangeBook/brick.frag +36 -0
  34. data/examples/OrangeBook/brick.rb +378 -0
  35. data/examples/OrangeBook/brick.vert +41 -0
  36. data/examples/OrangeBook/particle.frag +17 -0
  37. data/examples/OrangeBook/particle.rb +408 -0
  38. data/examples/OrangeBook/particle.vert +38 -0
  39. data/examples/README +16 -0
  40. data/examples/RedBook/aapoly.rb +143 -0
  41. data/examples/RedBook/aargb.rb +121 -0
  42. data/examples/RedBook/accanti.rb +164 -0
  43. data/examples/RedBook/accpersp.rb +217 -0
  44. data/examples/RedBook/alpha.rb +125 -0
  45. data/examples/RedBook/alpha3D.rb +160 -0
  46. data/examples/RedBook/bezcurve.rb +107 -0
  47. data/examples/RedBook/bezmesh.rb +139 -0
  48. data/examples/RedBook/checker.rb +126 -0
  49. data/examples/RedBook/clip.rb +97 -0
  50. data/examples/RedBook/colormat.rb +137 -0
  51. data/examples/RedBook/cube.rb +71 -0
  52. data/examples/RedBook/depthcue.rb +101 -0
  53. data/examples/RedBook/dof.rb +206 -0
  54. data/examples/RedBook/double.rb +107 -0
  55. data/examples/RedBook/drawf.rb +93 -0
  56. data/examples/RedBook/feedback.rb +147 -0
  57. data/examples/RedBook/fog.rb +168 -0
  58. data/examples/RedBook/font.rb +153 -0
  59. data/examples/RedBook/hello.rb +81 -0
  60. data/examples/RedBook/image.rb +139 -0
  61. data/examples/RedBook/jitter.rb +207 -0
  62. data/examples/RedBook/light.rb +157 -0
  63. data/examples/RedBook/lines.rb +130 -0
  64. data/examples/RedBook/list.rb +113 -0
  65. data/examples/RedBook/material.rb +276 -0
  66. data/examples/RedBook/mipmap.rb +158 -0
  67. data/examples/RedBook/model.rb +115 -0
  68. data/examples/RedBook/movelight.rb +134 -0
  69. data/examples/RedBook/pickdepth.rb +181 -0
  70. data/examples/RedBook/planet.rb +110 -0
  71. data/examples/RedBook/quadric.rb +160 -0
  72. data/examples/RedBook/robot.rb +117 -0
  73. data/examples/RedBook/select.rb +198 -0
  74. data/examples/RedBook/smooth.rb +97 -0
  75. data/examples/RedBook/stencil.rb +165 -0
  76. data/examples/RedBook/stroke.rb +169 -0
  77. data/examples/RedBook/surface.rb +168 -0
  78. data/examples/RedBook/teaambient.rb +134 -0
  79. data/examples/RedBook/teapots.rb +184 -0
  80. data/examples/RedBook/tess.rb +185 -0
  81. data/examples/RedBook/texbind.rb +149 -0
  82. data/examples/RedBook/texgen.rb +171 -0
  83. data/examples/RedBook/texturesurf.rb +130 -0
  84. data/examples/RedBook/varray.rb +161 -0
  85. data/examples/RedBook/wrap.rb +150 -0
  86. data/examples/misc/OGLBench.rb +338 -0
  87. data/examples/misc/anisotropic.rb +196 -0
  88. data/examples/misc/fbo_test.rb +357 -0
  89. data/examples/misc/font-glut.rb +47 -0
  90. data/examples/misc/glfwtest.rb +30 -0
  91. data/examples/misc/plane.rb +161 -0
  92. data/examples/misc/readpixel.rb +66 -0
  93. data/examples/misc/sdltest.rb +36 -0
  94. data/examples/misc/trislam.rb +829 -0
  95. data/ext/opengl/GL/gl.h +2115 -0
  96. data/ext/opengl/GL/glext.h +11770 -0
  97. data/ext/opengl/common.h +372 -0
  98. data/ext/opengl/conv.h +247 -0
  99. data/ext/opengl/extconf.rb +19 -0
  100. data/ext/opengl/fptr_struct.h +912 -0
  101. data/ext/opengl/funcdef.h +279 -0
  102. data/ext/opengl/gl-1.0-1.1.c +3345 -0
  103. data/ext/opengl/gl-1.2.c +155 -0
  104. data/ext/opengl/gl-1.3.c +447 -0
  105. data/ext/opengl/gl-1.4.c +346 -0
  106. data/ext/opengl/gl-1.5.c +225 -0
  107. data/ext/opengl/gl-2.0.c +665 -0
  108. data/ext/opengl/gl-2.1.c +57 -0
  109. data/ext/opengl/gl-3.0.c +502 -0
  110. data/ext/opengl/gl-enums.c +4853 -0
  111. data/ext/opengl/gl-enums.h +14528 -0
  112. data/ext/opengl/gl-error.c +110 -0
  113. data/ext/opengl/gl-error.h +25 -0
  114. data/ext/opengl/gl-ext-3dfx.c +27 -0
  115. data/ext/opengl/gl-ext-arb.c +880 -0
  116. data/ext/opengl/gl-ext-ati.c +41 -0
  117. data/ext/opengl/gl-ext-ext.c +885 -0
  118. data/ext/opengl/gl-ext-gremedy.c +41 -0
  119. data/ext/opengl/gl-ext-nv.c +679 -0
  120. data/ext/opengl/gl.c +265 -0
  121. data/ext/opengl/gl_buffer.c +202 -0
  122. data/ext/opengl/glimpl.c +187 -0
  123. data/ext/opengl/glimpl.h +47 -0
  124. data/ext/opengl/opengl.c +9 -0
  125. data/lib/gl.rb +1 -0
  126. data/lib/opengl.rb +79 -0
  127. data/lib/opengl/bindings_version.rb +4 -0
  128. data/lib/opengl/implementation.rb +38 -0
  129. data/lib/opengl/test_case.rb +86 -0
  130. data/test/dummy.xorg.conf +140 -0
  131. data/test/test_gl.rb +45 -0
  132. data/test/test_gl_10_11.rb +1363 -0
  133. data/test/test_gl_12.rb +71 -0
  134. data/test/test_gl_13.rb +221 -0
  135. data/test/test_gl_14.rb +218 -0
  136. data/test/test_gl_15.rb +258 -0
  137. data/test/test_gl_20.rb +417 -0
  138. data/test/test_gl_21.rb +436 -0
  139. data/test/test_gl_ext_arb.rb +508 -0
  140. data/test/test_gl_ext_ati.rb +28 -0
  141. data/test/test_gl_ext_ext.rb +608 -0
  142. data/test/test_gl_ext_gremedy.rb +29 -0
  143. data/test/test_gl_ext_nv.rb +349 -0
  144. data/test/test_glimpl.rb +23 -0
  145. data/test/test_opengl_buffer.rb +122 -0
  146. data/utils/README +6 -0
  147. data/utils/enumgen.rb +108 -0
  148. data/utils/extlistgen.rb +90 -0
  149. metadata +326 -0
@@ -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