opengl 0.7.0.pre1-x86-mingw32 → 0.7.0.pre2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/.autotest +29 -0
  2. data/.gitignore +5 -8
  3. data/History.rdoc +33 -0
  4. data/Manifest.txt +72 -57
  5. data/README.rdoc +72 -25
  6. data/Rakefile +60 -72
  7. data/Rakefile.cross +5 -2
  8. data/{doc → docs}/build_install.txt +0 -0
  9. data/{doc → docs}/extensions.txt.in +0 -0
  10. data/{doc → docs}/history.txt +0 -0
  11. data/{doc → docs}/requirements_and_design.txt +0 -0
  12. data/{doc → docs}/roadmap.txt +0 -0
  13. data/{doc → docs}/scientific_use.txt +0 -0
  14. data/{doc → docs}/supplies/page_template.html +0 -0
  15. data/{doc → docs}/thanks.txt +0 -0
  16. data/{doc → docs}/tutorial.txt +0 -0
  17. data/examples/NeHe/NeHe.png +0 -0
  18. data/examples/NeHe/crate.png +0 -0
  19. data/examples/NeHe/glass.png +0 -0
  20. data/examples/NeHe/nehe_lesson02.rb +82 -83
  21. data/examples/NeHe/nehe_lesson03.rb +88 -88
  22. data/examples/NeHe/nehe_lesson04.rb +93 -96
  23. data/examples/NeHe/nehe_lesson05.rb +137 -144
  24. data/examples/NeHe/nehe_lesson06.rb +183 -0
  25. data/examples/NeHe/nehe_lesson07.rb +237 -0
  26. data/examples/NeHe/nehe_lesson08.rb +252 -0
  27. data/examples/NeHe/nehe_lesson09.rb +199 -0
  28. data/examples/NeHe/nehe_lesson11.rb +173 -0
  29. data/examples/NeHe/nehe_lesson12.rb +200 -0
  30. data/examples/NeHe/nehe_lesson16.rb +208 -0
  31. data/examples/NeHe/nehe_lesson19.rb +206 -0
  32. data/examples/NeHe/particle.png +0 -0
  33. data/examples/NeHe/star.png +0 -0
  34. data/examples/NeHe/tim.png +0 -0
  35. data/examples/RedBook/light.rb +154 -0
  36. data/examples/misc/OGLBench.rb +2 -2
  37. data/examples/misc/trislam.rb +2 -2
  38. data/ext/{common → opengl}/common.h +2 -11
  39. data/ext/{common → opengl}/conv.h +43 -31
  40. data/ext/{glut → opengl}/extconf.rb +14 -7
  41. data/ext/{common → opengl}/funcdef.h +155 -125
  42. data/ext/{gl → opengl}/gl-1.0-1.1.c +426 -162
  43. data/ext/{gl → opengl}/gl-1.2.c +70 -66
  44. data/ext/{gl → opengl}/gl-1.3.c +19 -19
  45. data/ext/{gl → opengl}/gl-1.4.c +23 -23
  46. data/ext/{gl → opengl}/gl-1.5.c +46 -47
  47. data/ext/{gl → opengl}/gl-2.0.c +66 -60
  48. data/ext/{gl → opengl}/gl-2.1.c +4 -4
  49. data/ext/{gl → opengl}/gl-enums.c +2 -1
  50. data/ext/{common → opengl}/gl-enums.h +0 -0
  51. data/ext/{gl → opengl}/gl-error.c +12 -4
  52. data/ext/{common → opengl}/gl-error.h +7 -2
  53. data/ext/{gl → opengl}/gl-ext-3dfx.c +1 -1
  54. data/ext/{gl → opengl}/gl-ext-arb.c +75 -70
  55. data/ext/{gl → opengl}/gl-ext-ati.c +3 -3
  56. data/ext/{gl → opengl}/gl-ext-ext.c +54 -54
  57. data/ext/{gl → opengl}/gl-ext-gremedy.c +3 -3
  58. data/ext/{gl → opengl}/gl-ext-nv.c +49 -48
  59. data/ext/{common → opengl}/gl-types.h +0 -0
  60. data/ext/{gl → opengl}/gl.c +8 -10
  61. data/ext/{glu → opengl}/glu-enums.c +1 -1
  62. data/ext/{common → opengl}/glu-enums.h +0 -0
  63. data/ext/{glu → opengl}/glu.c +7 -3
  64. data/ext/{glut → opengl}/glut.c +98 -48
  65. data/ext/opengl/opengl.c +11 -0
  66. data/lib/gl.rb +1 -0
  67. data/lib/glu.rb +1 -0
  68. data/lib/glut.rb +1 -0
  69. data/lib/opengl.rb +13 -14
  70. data/lib/opengl/opengl.so +0 -0
  71. data/lib/opengl/test_case.rb +87 -0
  72. data/test/{tc_misc.rb → test_gl.rb} +2 -14
  73. data/test/test_gl_10_11.rb +1363 -0
  74. data/test/test_gl_12.rb +182 -0
  75. data/test/{tc_func_13.rb → test_gl_13.rb} +14 -14
  76. data/test/test_gl_14.rb +221 -0
  77. data/test/test_gl_15.rb +260 -0
  78. data/test/test_gl_20.rb +430 -0
  79. data/test/test_gl_21.rb +553 -0
  80. data/test/test_gl_ext_arb.rb +526 -0
  81. data/test/{tc_ext_ati.rb → test_gl_ext_ati.rb} +11 -14
  82. data/test/test_gl_ext_ext.rb +608 -0
  83. data/test/{tc_ext_gremedy.rb → test_gl_ext_gremedy.rb} +6 -6
  84. data/test/test_gl_ext_nv.rb +352 -0
  85. data/test/test_glu.rb +309 -0
  86. metadata +159 -102
  87. data/History.txt +0 -36
  88. data/ext/gl/extconf.rb +0 -43
  89. data/ext/glu/extconf.rb +0 -51
  90. data/test/README +0 -10
  91. data/test/tc_common.rb +0 -98
  92. data/test/tc_ext_arb.rb +0 -467
  93. data/test/tc_ext_ext.rb +0 -551
  94. data/test/tc_ext_nv.rb +0 -357
  95. data/test/tc_func_10_11.rb +0 -1281
  96. data/test/tc_func_12.rb +0 -186
  97. data/test/tc_func_14.rb +0 -197
  98. data/test/tc_func_15.rb +0 -270
  99. data/test/tc_func_20.rb +0 -346
  100. data/test/tc_func_21.rb +0 -541
  101. data/test/tc_glu.rb +0 -310
  102. data/test/tc_include_gl.rb +0 -35
  103. data/test/tc_require_gl.rb +0 -34
@@ -0,0 +1,199 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson09
6
+ include Gl
7
+ include Glu
8
+ include Glut
9
+
10
+ Star = Struct.new :r, :g, :b, :distance, :angle
11
+
12
+ def initialize
13
+ @textures = nil
14
+ @filter = 0
15
+ @twinkle = false
16
+ @zoom = -15.0
17
+ @tilt = 90.0
18
+ @spin = 0.0
19
+ @fullscreen = false
20
+ @last_draw = Time.now
21
+
22
+ @star_count = 50
23
+ @stars = (0...@star_count).map do |i|
24
+ distance = i.to_f / @star_count * 5.0
25
+ angle = 0.0
26
+
27
+ Star.new rand(256), rand(256), rand(256), distance, angle
28
+ end
29
+
30
+ glutInit
31
+
32
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
33
+ glutInitWindowSize 640, 480
34
+ glutInitWindowPosition 0, 0
35
+
36
+ @window = glutCreateWindow "NeHe Lesson 09 - ruby-opengl version"
37
+
38
+ glutDisplayFunc :draw_gl_scene
39
+ glutReshapeFunc :reshape
40
+ glutIdleFunc :idle
41
+ glutKeyboardFunc :keyboard
42
+
43
+ reshape 640, 480
44
+ load_texture
45
+ init_gl
46
+
47
+ glutMainLoop
48
+ end
49
+
50
+ def init_gl
51
+ glEnable GL_TEXTURE_2D
52
+ glShadeModel GL_SMOOTH
53
+ glClearColor 0.0, 0.0, 0.0, 0.5
54
+ glClearDepth 1.0
55
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
56
+ glBlendFunc GL_SRC_ALPHA, GL_ONE
57
+ glEnable GL_BLEND
58
+
59
+ true
60
+ end
61
+
62
+ def reshape width, height
63
+ width = width.to_f
64
+ height = height.to_f
65
+ height = 1.0 if height.zero?
66
+
67
+ glViewport 0, 0, width, height
68
+
69
+ glMatrixMode GL_PROJECTION
70
+ glLoadIdentity
71
+
72
+ gluPerspective 45.0, width / height, 0.1, 100.0
73
+
74
+ glMatrixMode GL_MODELVIEW
75
+ glLoadIdentity
76
+
77
+ true
78
+ end
79
+
80
+ def draw_gl_scene
81
+ return if 0.01 > Time.now - @last_draw
82
+ @last_draw = Time.now
83
+
84
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
85
+ glBindTexture GL_TEXTURE_2D, @textures[@filter]
86
+
87
+ @stars.each_with_index do |star, i|
88
+ glLoadIdentity
89
+ glTranslatef 0.0, 0.0, @zoom
90
+ glRotatef @tilt, 1.0, 0.0, 0.0
91
+ glRotatef star.angle, 0.0, 1.0, 0.0
92
+
93
+ glTranslatef star.distance, 0.0, 0.0
94
+
95
+ glRotatef star.angle, 0.0, -1.0, 0.0
96
+ glRotatef @tilt, -1.0, 0.0, 0.0
97
+
98
+ if @twinkle then
99
+ prev = @stars[i - 1]
100
+ glColor4ub prev.r, prev.g, prev.b, 255
101
+
102
+ glBegin GL_QUADS do
103
+ glTexCoord2f 0.0, 0.0; glVertex3f -1.0, -1.0, 0.0
104
+ glTexCoord2f 1.0, 0.0; glVertex3f 1.0, -1.0, 0.0
105
+ glTexCoord2f 1.0, 1.0; glVertex3f 1.0, 1.0, 0.0
106
+ glTexCoord2f 0.0, 1.0; glVertex3f -1.0, 1.0, 0.0
107
+ end
108
+ end
109
+
110
+ glRotatef @spin, 0.0, 0.0, 1.0
111
+ glColor4ub star.r, star.g, star.b, 255
112
+
113
+ glBegin GL_QUADS do
114
+ glTexCoord2f 0.0, 0.0; glVertex3f -1.0, -1.0, 0.0
115
+ glTexCoord2f 1.0, 0.0; glVertex3f 1.0, -1.0, 0.0
116
+ glTexCoord2f 1.0, 1.0; glVertex3f 1.0, 1.0, 0.0
117
+ glTexCoord2f 0.0, 1.0; glVertex3f -1.0, 1.0, 0.0
118
+ end
119
+
120
+ @spin += 0.01
121
+ star.angle += i.to_f / @star_count
122
+ star.distance -= 0.01
123
+
124
+ if star.distance < 0 then
125
+ star.distance += 5.0
126
+ star.r = rand 256
127
+ star.g = rand 256
128
+ star.b = rand 256
129
+ end
130
+ end
131
+
132
+ glutSwapBuffers
133
+ end
134
+
135
+ def idle
136
+ glutPostRedisplay
137
+ end
138
+
139
+ def keyboard key, x, y
140
+ case key
141
+ when ?\e then
142
+ glutDestroyWindow @window
143
+ exit 0
144
+ when 'F' then
145
+ @fullscreen = !@fullscreen
146
+
147
+ if @fullscreen then
148
+ glutFullScreen
149
+ else
150
+ glutPositionWindow 0, 0
151
+ end
152
+ when 'f' then
153
+ @filter += 1
154
+ @filter %= 3
155
+
156
+ puts "texture #{@filter}"
157
+ when 'W' then
158
+ @twinkle = !@twinkle
159
+
160
+ puts "twinkle #{@twinkle ? 'on' : 'off'}"
161
+ when 'T' then @tilt += 0.5
162
+ when 't' then @tilt -= 0.5
163
+ when 'Z' then @zoom += 0.2
164
+ when 'z' then @zoom -= 0.2
165
+ else
166
+ puts key
167
+ end
168
+
169
+ glutPostRedisplay
170
+ end
171
+
172
+ def load_texture
173
+ png = PNG.load_file File.expand_path('../star.png', __FILE__)
174
+ height = png.height
175
+ width = png.width
176
+
177
+ image = png.data.flatten.map { |c| c.values }.join
178
+
179
+ @textures = glGenTextures 3
180
+ glBindTexture GL_TEXTURE_2D, @textures[0]
181
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST
182
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST
183
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
184
+
185
+ glBindTexture GL_TEXTURE_2D, @textures[1]
186
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
187
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
188
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
189
+
190
+ glBindTexture GL_TEXTURE_2D, @textures[2]
191
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
192
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST
193
+ gluBuild2DMipmaps GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image
194
+ end
195
+
196
+ end
197
+
198
+ Lesson09.new
199
+
@@ -0,0 +1,173 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson11
6
+ include Gl
7
+ include Glu
8
+ include Glut
9
+
10
+ def initialize
11
+ @textures = nil
12
+ @xrot = 0.0
13
+ @yrot = 0.0
14
+ @zrot = 0.0
15
+
16
+ factor = 10.0 / 9 * Math::PI
17
+ @points = Array.new 45 do |x|
18
+ Array.new 45 do |y|
19
+ [x / 5.0 - 4.5, y / 5.0 - 4.5,
20
+ Math.sin(x / factor)]
21
+ end
22
+ end
23
+
24
+ @wiggle_count = 0
25
+
26
+ glutInit
27
+
28
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
29
+ glutInitWindowSize 640, 480
30
+ glutInitWindowPosition 0, 0
31
+
32
+ @window = glutCreateWindow "NeHe Lesson 11 - ruby-opengl version"
33
+
34
+ glutDisplayFunc :draw_gl_scene
35
+ glutReshapeFunc :reshape
36
+ glutIdleFunc :idle
37
+ glutKeyboardFunc :keyboard
38
+
39
+ reshape 640, 480
40
+ load_texture
41
+ init_gl
42
+
43
+ glutMainLoop
44
+ end
45
+
46
+ def init_gl
47
+ glEnable GL_TEXTURE_2D
48
+ glShadeModel GL_SMOOTH
49
+ glClearColor 0.0, 0.0, 0.0, 0.5
50
+ glClearDepth 1.0
51
+ glEnable GL_DEPTH_TEST
52
+ glDepthFunc GL_LEQUAL
53
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
54
+
55
+ glPolygonMode GL_BACK, GL_FILL
56
+ glPolygonMode GL_FRONT, GL_LINE
57
+
58
+ true
59
+ end
60
+
61
+ def reshape width, height
62
+ width = width.to_f
63
+ height = height.to_f
64
+ height = 1.0 if height.zero?
65
+
66
+ glViewport 0, 0, width, height
67
+
68
+ glMatrixMode GL_PROJECTION
69
+ glLoadIdentity
70
+
71
+ gluPerspective 45.0, width / height, 0.1, 100.0
72
+
73
+ glMatrixMode GL_MODELVIEW
74
+ glLoadIdentity
75
+
76
+ true
77
+ end
78
+
79
+ def draw_gl_scene
80
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
81
+ glLoadIdentity
82
+
83
+ glTranslatef 0.0, 0.0, -12.0
84
+ glRotatef @xrot, 1.0, 0.0, 0.0
85
+ glRotatef @yrot, 0.0, 1.0, 0.0
86
+ glRotatef @zrot, 0.0, 0.0, 1.0
87
+
88
+ glBindTexture GL_TEXTURE_2D, @textures[0]
89
+
90
+ glBegin GL_QUADS do
91
+ (0...44).each do |x|
92
+ (0...44).each do |y|
93
+ tex_x = x / 44.0
94
+ tex_y = y / 44.0
95
+ tex_xb = (x + 1) / 44.0
96
+ tex_yb = (y + 1) / 44.0
97
+
98
+ glTexCoord2f tex_x, tex_y
99
+ glVertex3f @points[x][y][0], @points[x][y][1], @points[x][y][2]
100
+
101
+ glTexCoord2f tex_x, tex_yb
102
+ glVertex3f @points[x][y+1][0], @points[x][y+1][1], @points[x][y+1][2]
103
+
104
+ glTexCoord2f tex_xb, tex_yb
105
+ glVertex3f @points[x+1][y+1][0], @points[x+1][y+1][1], @points[x+1][y+1][2]
106
+
107
+ glTexCoord2f tex_xb, tex_y
108
+ glVertex3f @points[x+1][y][0], @points[x+1][y][1], @points[x+1][y][2]
109
+ end
110
+ end
111
+ end
112
+
113
+ if @wiggle_count == 4 then
114
+ (0...45).each do |y|
115
+ tmp = @points[0][y][2]
116
+ (0...44).each do |x|
117
+ @points[x][y][2] = @points[x+1][y][2]
118
+ end
119
+ @points[44][y][2] = tmp
120
+ end
121
+
122
+ @wiggle_count = 0
123
+ end
124
+
125
+ @wiggle_count += 1
126
+
127
+ @xrot += 0.03
128
+ @yrot += 0.02
129
+ @zrot += 0.04
130
+
131
+ glutSwapBuffers
132
+ end
133
+
134
+ def idle
135
+ glutPostRedisplay
136
+ end
137
+
138
+ def keyboard key, x, y
139
+ case key
140
+ when ?\e
141
+ glutDestroyWindow @window
142
+ exit 0
143
+ when 'F' then
144
+ @fullscreen = !@fullscreen
145
+
146
+ if @fullscreen then
147
+ glutFullScreen
148
+ else
149
+ glutPositionWindow 0, 0
150
+ end
151
+ end
152
+
153
+ glutPostRedisplay
154
+ end
155
+
156
+ def load_texture
157
+ png = PNG.load_file File.expand_path('../tim.png', __FILE__)
158
+ height = png.height
159
+ width = png.width
160
+
161
+ image = png.data.flatten.map { |c| c.values }.join
162
+
163
+ @textures = glGenTextures 1
164
+ glBindTexture GL_TEXTURE_2D, @textures[0]
165
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
166
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
167
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
168
+ end
169
+
170
+ end
171
+
172
+ Lesson11.new
173
+
@@ -0,0 +1,200 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson12
6
+ include Gl
7
+ include Glu
8
+ include Glut
9
+
10
+ def initialize
11
+ @textures = nil
12
+ @box = nil
13
+ @top = nil
14
+ @xrot = 0
15
+ @yrot = 0
16
+
17
+ @box_color = [
18
+ [1.0, 0.0, 0.0],
19
+ [1.0, 0.5, 0.0],
20
+ [1.0, 1.0, 0.0],
21
+ [0.0, 1.0, 0.0],
22
+ [0.0, 1.0, 1.0],
23
+ ]
24
+
25
+ @top_color = [
26
+ [0.5, 0.0, 0.0],
27
+ [0.5, 0.25, 0.0],
28
+ [0.5, 0.5, 0.0],
29
+ [0.0, 0.5, 0.0],
30
+ [0.0, 0.5, 0.5],
31
+ ]
32
+
33
+ glutInit
34
+
35
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
36
+ glutInitWindowSize 640, 480
37
+ glutInitWindowPosition 0, 0
38
+
39
+ @window = glutCreateWindow "NeHe Lesson 12 - ruby-opengl version"
40
+
41
+ glutDisplayFunc :draw_gl_scene
42
+ glutReshapeFunc :reshape
43
+ glutIdleFunc :idle
44
+ glutKeyboardFunc :keyboard
45
+
46
+ reshape 640, 480
47
+ load_texture
48
+ init_gl
49
+
50
+ glutMainLoop
51
+ end
52
+
53
+ def init_gl
54
+ build_lists
55
+
56
+ glEnable GL_TEXTURE_2D
57
+ glShadeModel GL_SMOOTH
58
+ glClearColor 0.0, 0.0, 0.0, 0.5
59
+ glClearDepth 1.0
60
+ glEnable GL_DEPTH_TEST
61
+ glDepthFunc GL_LEQUAL
62
+
63
+ glEnable GL_LIGHT0
64
+ glEnable GL_LIGHTING
65
+ glEnable GL_COLOR_MATERIAL
66
+
67
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
68
+ end
69
+
70
+ def reshape width, height
71
+ width = width.to_f
72
+ height = height.to_f
73
+ height = 1.0 if height.zero?
74
+
75
+ glViewport 0, 0, width, height
76
+
77
+ glMatrixMode GL_PROJECTION
78
+ glLoadIdentity
79
+
80
+ gluPerspective 45.0, width / height, 0.1, 100.0
81
+
82
+ glMatrixMode GL_MODELVIEW
83
+ glLoadIdentity
84
+
85
+ true
86
+ end
87
+
88
+ def build_lists
89
+ @box = glGenLists 2
90
+ @top = @box + 1
91
+
92
+ glNewList @box, GL_COMPILE do
93
+ glBegin GL_QUADS do
94
+ # Bottom Face
95
+ glTexCoord2f(1, 1); glVertex3f(-1, -1, -1)
96
+ glTexCoord2f(0, 1); glVertex3f( 1, -1, -1)
97
+ glTexCoord2f(0, 0); glVertex3f( 1, -1, 1)
98
+ glTexCoord2f(1, 0); glVertex3f(-1, -1, 1)
99
+ # Front Face
100
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, 1)
101
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, 1)
102
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1)
103
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1)
104
+ # Back Face
105
+ glTexCoord2f(1, 0); glVertex3f(-1, -1, -1)
106
+ glTexCoord2f(1, 1); glVertex3f(-1, 1, -1)
107
+ glTexCoord2f(0, 1); glVertex3f( 1, 1, -1)
108
+ glTexCoord2f(0, 0); glVertex3f( 1, -1, -1)
109
+ # Right face
110
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1)
111
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, -1)
112
+ glTexCoord2f(0, 1); glVertex3f( 1, 1, 1)
113
+ glTexCoord2f(0, 0); glVertex3f( 1, -1, 1)
114
+ # Left Face
115
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1)
116
+ glTexCoord2f(1, 0); glVertex3f(-1, -1, 1)
117
+ glTexCoord2f(1, 1); glVertex3f(-1, 1, 1)
118
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, -1)
119
+ end
120
+ end
121
+
122
+ glNewList @top, GL_COMPILE do
123
+ glBegin GL_QUADS do
124
+ # Top Face
125
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, -1)
126
+ glTexCoord2f(0, 0); glVertex3f(-1, 1, 1)
127
+ glTexCoord2f(1, 0); glVertex3f( 1, 1, 1)
128
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, -1)
129
+ end
130
+ end
131
+ end
132
+
133
+ def draw_gl_scene
134
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
135
+
136
+ glBindTexture GL_TEXTURE_2D, @textures[0]
137
+
138
+ (1..5).each do |y|
139
+ (0..y).each do |x|
140
+ glLoadIdentity
141
+ glTranslate 1.4 + x * 2.8 - y * 1.4, (6 - y) * 2.4 - 7, -20
142
+
143
+ glRotatef (45 - 2.0 * y) + @xrot, 1, 0, 0
144
+ glRotatef 45 + @yrot, 0, 1, 0
145
+
146
+ glColor3fv @box_color[y - 1]
147
+ glCallList @box
148
+
149
+ glColor3fv @top_color[y - 1]
150
+ glCallList @top
151
+ end
152
+ end
153
+
154
+ glutSwapBuffers
155
+ end
156
+
157
+ def idle
158
+ glutPostRedisplay
159
+ end
160
+
161
+ def keyboard key, x, y
162
+ case key
163
+ when ?\e
164
+ glutDestroyWindow @window
165
+ exit 0
166
+ when 'F' then
167
+ @fullscreen = !@fullscreen
168
+
169
+ if @fullscreen then
170
+ glutFullScreen
171
+ else
172
+ glutPositionWindow 0, 0
173
+ end
174
+ when 'X' then @xrot += 0.5
175
+ when 'x' then @xrot -= 0.5
176
+ when 'Y' then @yrot += 0.5
177
+ when 'y' then @yrot -= 0.5
178
+ end
179
+
180
+ glutPostRedisplay
181
+ end
182
+
183
+ def load_texture
184
+ png = PNG.load_file File.expand_path('../crate.png', __FILE__)
185
+ height = png.height
186
+ width = png.width
187
+
188
+ image = png.data.flatten.map { |c| c.values }.join
189
+
190
+ @textures = glGenTextures 1
191
+ glBindTexture GL_TEXTURE_2D, @textures[0]
192
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
193
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
194
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
195
+ end
196
+
197
+ end
198
+
199
+ Lesson12.new
200
+