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,183 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson06
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
+ @fullscreen = true
16
+
17
+ glutInit
18
+
19
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
20
+ glutInitWindowSize 640, 480
21
+ glutInitWindowPosition 0, 0
22
+
23
+ @window = glutCreateWindow "NeHe Lesson 06 - ruby-opengl version"
24
+
25
+ glutDisplayFunc :draw_gl_scene
26
+ glutReshapeFunc :reshape
27
+ glutIdleFunc :idle
28
+ glutKeyboardFunc :keyboard
29
+
30
+ reshape 640, 480
31
+ load_texture
32
+ init_gl
33
+
34
+ glutMainLoop
35
+ end
36
+
37
+ def init_gl
38
+ glEnable GL_TEXTURE_2D
39
+ glShadeModel GL_SMOOTH
40
+ glClearColor 0.0, 0.0, 0.0, 0.5
41
+ glClearDepth 1.0
42
+ glEnable GL_DEPTH_TEST
43
+ glDepthFunc GL_LEQUAL
44
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
45
+ end
46
+
47
+ def reshape width, height
48
+ width = width.to_f
49
+ height = height.to_f
50
+ height = 1.0 if height.zero?
51
+
52
+ glViewport 0, 0, width, height
53
+
54
+ glMatrixMode GL_PROJECTION
55
+ glLoadIdentity
56
+
57
+ gluPerspective 45.0, width / height, 0.1, 100.0
58
+
59
+ glMatrixMode GL_MODELVIEW
60
+ glLoadIdentity
61
+ end
62
+
63
+ def draw_gl_scene
64
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
65
+ glMatrixMode GL_MODELVIEW
66
+ glLoadIdentity
67
+ glTranslatef 0.0, 0.0, -7.0
68
+
69
+ glRotatef @xrot, 1.0, 0.0, 0.0
70
+ glRotatef @yrot, 0.0, 1.0, 0.0
71
+ glRotatef @zrot, 0.0, 0.0, 1.0
72
+
73
+ glBindTexture GL_TEXTURE_2D, @textures[0]
74
+
75
+ glBegin GL_QUADS do
76
+ # front face
77
+ glTexCoord2f(0.0, 1.0)
78
+ glVertex3f(-1.0, -1.0, 1.0)
79
+ glTexCoord2f(1.0, 1.0)
80
+ glVertex3f( 1.0, -1.0, 1.0)
81
+ glTexCoord2f(1.0, 0.0)
82
+ glVertex3f( 1.0, 1.0, 1.0)
83
+ glTexCoord2f(0.0, 0.0)
84
+ glVertex3f(-1.0, 1.0, 1.0)
85
+
86
+ # back face
87
+ glTexCoord2f(0.0, 1.0)
88
+ glVertex3f(-1.0, -1.0, -1.0)
89
+ glTexCoord2f(1.0, 1.0)
90
+ glVertex3f(-1.0, 1.0, -1.0)
91
+ glTexCoord2f(1.0, 0.0)
92
+ glVertex3f( 1.0, 1.0, -1.0)
93
+ glTexCoord2f(0.0, 0.0)
94
+ glVertex3f( 1.0, -1.0, -1.0)
95
+
96
+ # top face
97
+ glTexCoord2f(0.0, 1.0)
98
+ glVertex3f(-1.0, 1.0, -1.0)
99
+ glTexCoord2f(1.0, 1.0)
100
+ glVertex3f(-1.0, 1.0, 1.0)
101
+ glTexCoord2f(1.0, 0.0)
102
+ glVertex3f( 1.0, 1.0, 1.0)
103
+ glTexCoord2f(0.0, 0.0)
104
+ glVertex3f( 1.0, 1.0, -1.0)
105
+
106
+ # bottom face
107
+ glTexCoord2f(1.0, 1.0)
108
+ glVertex3f(-1.0, -1.0, -1.0)
109
+ glTexCoord2f(1.0, 0.0)
110
+ glVertex3f( 1.0, -1.0, -1.0)
111
+ glTexCoord2f(0.0, 0.0)
112
+ glVertex3f( 1.0, -1.0, 1.0)
113
+ glTexCoord2f(0.0, 1.0)
114
+ glVertex3f(-1.0, -1.0, 1.0)
115
+
116
+ # right face
117
+ glTexCoord2f(1.0, 0.0)
118
+ glVertex3f( 1.0, -1.0, -1.0)
119
+ glTexCoord2f(0.0, 0.0)
120
+ glVertex3f( 1.0, 1.0, -1.0)
121
+ glTexCoord2f(0.0, 1.0)
122
+ glVertex3f( 1.0, 1.0, 1.0)
123
+ glTexCoord2f(1.0, 1.0)
124
+ glVertex3f( 1.0, -1.0, 1.0)
125
+
126
+ # left face
127
+ glTexCoord2f(0.0, 0.0)
128
+ glVertex3f(-1.0, -1.0, -1.0)
129
+ glTexCoord2f(0.0, 1.0)
130
+ glVertex3f(-1.0, -1.0, 1.0)
131
+ glTexCoord2f(1.0, 1.0)
132
+ glVertex3f(-1.0, 1.0, 1.0)
133
+ glTexCoord2f(1.0, 0.0)
134
+ glVertex3f(-1.0, 1.0, -1.0)
135
+ end
136
+
137
+ @xrot += 0.003
138
+ @yrot += 0.002
139
+ @zrot += 0.004
140
+
141
+ glutSwapBuffers
142
+ end
143
+
144
+ def idle
145
+ glutPostRedisplay
146
+ end
147
+
148
+ def keyboard key, x, y
149
+ case key
150
+ when ?\e
151
+ glutDestroyWindow @window
152
+ exit 0
153
+ when 'F' then
154
+ @fullscreen = !@fullscreen
155
+
156
+ if @fullscreen then
157
+ glutFullScreen
158
+ else
159
+ glutPositionWindow 0, 0
160
+ end
161
+ end
162
+
163
+ glutPostRedisplay
164
+ end
165
+
166
+ def load_texture
167
+ png = PNG.load_file File.expand_path('../NeHe.png', __FILE__)
168
+ height = png.height
169
+ width = png.width
170
+
171
+ image = png.data.flatten.map { |c| c.values }.join
172
+
173
+ @textures = glGenTextures 1
174
+ glBindTexture GL_TEXTURE_2D, @textures[0]
175
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
176
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
177
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
178
+ end
179
+
180
+ end
181
+
182
+ Lesson06.new
183
+
@@ -0,0 +1,237 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson07
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
+ @x_speed = 0.0
15
+ @y_speed = 0.0
16
+ @z = 0.0
17
+ @ambient = [0.5, 0.5, 0.5, 1.0]
18
+ @diffuse = [1.0, 1.0, 1.0, 1.0]
19
+ @light_position = [0.0, 0.0, 2.0, 1.0]
20
+ @filter = 0
21
+ @keys = []
22
+ @lighting = false
23
+ @fullscreen = false
24
+
25
+ glutInit
26
+
27
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
28
+ glutInitWindowSize 640, 480
29
+ glutInitWindowPosition 0, 0
30
+
31
+ @window = glutCreateWindow "NeHe Lesson 07 - ruby-opengl version"
32
+
33
+ glutDisplayFunc :draw_gl_scene
34
+ glutReshapeFunc :reshape
35
+ glutIdleFunc :idle
36
+ glutKeyboardFunc :keyboard
37
+
38
+ reshape 640, 480
39
+ load_texture
40
+ init_gl
41
+
42
+ glutMainLoop
43
+ end
44
+
45
+ def init_gl
46
+ glEnable GL_TEXTURE_2D
47
+ glShadeModel GL_SMOOTH
48
+ glClearColor 0.0, 0.0, 0.0, 0.5
49
+ glClearDepth 1.0
50
+ glEnable GL_DEPTH_TEST
51
+ glDepthFunc GL_LEQUAL
52
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
53
+
54
+ glLightfv GL_LIGHT1, GL_AMBIENT, @ambient
55
+ glLightfv GL_LIGHT1, GL_DIFFUSE, @diffuse
56
+ glLightfv GL_LIGHT1, GL_POSITION, @light_position
57
+
58
+ glEnable GL_LIGHT1
59
+
60
+ true
61
+ end
62
+
63
+ def reshape width, height
64
+ width = width.to_f
65
+ height = height.to_f
66
+ height = 1.0 if height.zero?
67
+
68
+ glViewport 0, 0, width, height
69
+
70
+ glMatrixMode GL_PROJECTION
71
+ glLoadIdentity
72
+
73
+ gluPerspective 45.0, width / height, 0.1, 100.0
74
+
75
+ glMatrixMode GL_MODELVIEW
76
+ glLoadIdentity
77
+
78
+ true
79
+ end
80
+
81
+ def draw_gl_scene
82
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
83
+ glLoadIdentity
84
+ glTranslatef 0.0, 0.0, @z
85
+
86
+ glRotatef @xrot, 1.0, 0.0, 0.0
87
+ glRotatef @yrot, 0.0, 1.0, 0.0
88
+
89
+ glBindTexture GL_TEXTURE_2D, @textures[@filter]
90
+
91
+ glBegin GL_QUADS do
92
+ # front face
93
+ glNormal3f( 0.0, 0.0, 1.0)
94
+ glTexCoord2f(0.0, 1.0)
95
+ glVertex3f(-1.0, -1.0, 1.0)
96
+ glTexCoord2f(1.0, 1.0)
97
+ glVertex3f( 1.0, -1.0, 1.0)
98
+ glTexCoord2f(1.0, 0.0)
99
+ glVertex3f( 1.0, 1.0, 1.0)
100
+ glTexCoord2f(0.0, 0.0)
101
+ glVertex3f(-1.0, 1.0, 1.0)
102
+
103
+ # back face
104
+ glNormal3f( 0.0, 0.0, -1.0)
105
+ glTexCoord2f(0.0, 1.0)
106
+ glVertex3f(-1.0, -1.0, -1.0)
107
+ glTexCoord2f(1.0, 1.0)
108
+ glVertex3f(-1.0, 1.0, -1.0)
109
+ glTexCoord2f(1.0, 0.0)
110
+ glVertex3f( 1.0, 1.0, -1.0)
111
+ glTexCoord2f(0.0, 0.0)
112
+ glVertex3f( 1.0, -1.0, -1.0)
113
+
114
+ # top face
115
+ glNormal3f( 0.0, 1.0, 0.0)
116
+ glTexCoord2f(0.0, 1.0)
117
+ glVertex3f(-1.0, 1.0, -1.0)
118
+ glTexCoord2f(1.0, 1.0)
119
+ glVertex3f(-1.0, 1.0, 1.0)
120
+ glTexCoord2f(1.0, 0.0)
121
+ glVertex3f( 1.0, 1.0, 1.0)
122
+ glTexCoord2f(0.0, 0.0)
123
+ glVertex3f( 1.0, 1.0, -1.0)
124
+
125
+ # bottom face
126
+ glNormal3f( 0.0, -1.0, 0.0)
127
+ glTexCoord2f(1.0, 1.0)
128
+ glVertex3f(-1.0, -1.0, -1.0)
129
+ glTexCoord2f(1.0, 0.0)
130
+ glVertex3f( 1.0, -1.0, -1.0)
131
+ glTexCoord2f(0.0, 0.0)
132
+ glVertex3f( 1.0, -1.0, 1.0)
133
+ glTexCoord2f(0.0, 1.0)
134
+ glVertex3f(-1.0, -1.0, 1.0)
135
+
136
+ # right face
137
+ glNormal3f( 1.0, 0.0, 0.0)
138
+ glTexCoord2f(1.0, 0.0)
139
+ glVertex3f( 1.0, -1.0, -1.0)
140
+ glTexCoord2f(0.0, 0.0)
141
+ glVertex3f( 1.0, 1.0, -1.0)
142
+ glTexCoord2f(0.0, 1.0)
143
+ glVertex3f( 1.0, 1.0, 1.0)
144
+ glTexCoord2f(1.0, 1.0)
145
+ glVertex3f( 1.0, -1.0, 1.0)
146
+
147
+ # left face
148
+ glNormal3f(-1.0, 0.0, 0.0)
149
+ glTexCoord2f(0.0, 0.0)
150
+ glVertex3f(-1.0, -1.0, -1.0)
151
+ glTexCoord2f(0.0, 1.0)
152
+ glVertex3f(-1.0, -1.0, 1.0)
153
+ glTexCoord2f(1.0, 1.0)
154
+ glVertex3f(-1.0, 1.0, 1.0)
155
+ glTexCoord2f(1.0, 0.0)
156
+ glVertex3f(-1.0, 1.0, -1.0)
157
+ end
158
+
159
+ @xrot += @x_speed
160
+ @yrot += @y_speed
161
+
162
+ glutSwapBuffers
163
+ end
164
+
165
+ def idle
166
+ glutPostRedisplay
167
+ end
168
+
169
+ def keyboard key, x, y
170
+ case key
171
+ when ?\e then
172
+ glutDestroyWindow @window
173
+ exit 0
174
+ when 'l' then
175
+ @lighting = !@lighting
176
+
177
+ if @lighting then
178
+ glEnable GL_LIGHTING
179
+ puts "lights on"
180
+ else
181
+ glDisable GL_LIGHTING
182
+ puts "lights off"
183
+ end
184
+ when 'f' then
185
+ @filter += 1
186
+ @filter %= 3
187
+
188
+ puts "texture #{@filter}"
189
+ when 'F' then
190
+ @fullscreen = !@fullscreen
191
+
192
+ if @fullscreen then
193
+ glutFullScreen
194
+ else
195
+ glutPositionWindow 0, 0
196
+ end
197
+ when 'X' then @x_speed += 0.01
198
+ when 'x' then @x_speed -= 0.01
199
+ when 'Y' then @y_speed += 0.01
200
+ when 'y' then @y_speed -= 0.01
201
+ when 'Z' then @z += 1.0
202
+ when 'z' then @z -= 1.0
203
+ else
204
+ puts key
205
+ end
206
+
207
+ glutPostRedisplay
208
+ end
209
+
210
+ def load_texture
211
+ png = PNG.load_file File.expand_path('../crate.png', __FILE__)
212
+ height = png.height
213
+ width = png.width
214
+
215
+ image = png.data.flatten.map { |c| c.values }.join
216
+
217
+ @textures = glGenTextures 3
218
+ glBindTexture GL_TEXTURE_2D, @textures[0]
219
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST
220
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST
221
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
222
+
223
+ glBindTexture GL_TEXTURE_2D, @textures[1]
224
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
225
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
226
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
227
+
228
+ glBindTexture GL_TEXTURE_2D, @textures[2]
229
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
230
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST
231
+ gluBuild2DMipmaps GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image
232
+ end
233
+
234
+ end
235
+
236
+ Lesson07.new
237
+
@@ -0,0 +1,252 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson08
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
+ @x_speed = 0.0
15
+ @y_speed = 0.0
16
+ @z = 0.0
17
+ @ambient = [0.5, 0.5, 0.5, 1.0]
18
+ @diffuse = [1.0, 1.0, 1.0, 1.0]
19
+ @light_position = [0.0, 0.0, 2.0, 1.0]
20
+ @filter = 0
21
+ @keys = []
22
+ @lighting = false
23
+ @blending = false
24
+ @fullscreen = false
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 08 - 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
+ glColor4f 1.0, 1.0, 1.0, 0.5
54
+ glBlendFunc GL_SRC_ALPHA, GL_ONE
55
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
56
+
57
+ glLightfv GL_LIGHT1, GL_AMBIENT, @ambient
58
+ glLightfv GL_LIGHT1, GL_DIFFUSE, @diffuse
59
+ glLightfv GL_LIGHT1, GL_POSITION, @light_position
60
+
61
+ glEnable GL_LIGHT1
62
+
63
+ true
64
+ end
65
+
66
+ def reshape width, height
67
+ width = width.to_f
68
+ height = height.to_f
69
+ height = 1.0 if height.zero?
70
+
71
+ glViewport 0, 0, width, height
72
+
73
+ glMatrixMode GL_PROJECTION
74
+ glLoadIdentity
75
+
76
+ gluPerspective 45.0, width / height, 0.1, 100.0
77
+
78
+ glMatrixMode GL_MODELVIEW
79
+ glLoadIdentity
80
+
81
+ true
82
+ end
83
+
84
+ def draw_gl_scene
85
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
86
+ glLoadIdentity
87
+ glTranslatef 0.0, 0.0, @z
88
+
89
+ glRotatef @xrot, 1.0, 0.0, 0.0
90
+ glRotatef @yrot, 0.0, 1.0, 0.0
91
+
92
+ glBindTexture GL_TEXTURE_2D, @textures[@filter]
93
+
94
+ glBegin GL_QUADS do
95
+ # front face
96
+ glNormal3f( 0.0, 0.0, 1.0)
97
+ glTexCoord2f(0.0, 1.0)
98
+ glVertex3f(-1.0, -1.0, 1.0)
99
+ glTexCoord2f(1.0, 1.0)
100
+ glVertex3f( 1.0, -1.0, 1.0)
101
+ glTexCoord2f(1.0, 0.0)
102
+ glVertex3f( 1.0, 1.0, 1.0)
103
+ glTexCoord2f(0.0, 0.0)
104
+ glVertex3f(-1.0, 1.0, 1.0)
105
+
106
+ # back face
107
+ glNormal3f( 0.0, 0.0, -1.0)
108
+ glTexCoord2f(0.0, 1.0)
109
+ glVertex3f(-1.0, -1.0, -1.0)
110
+ glTexCoord2f(1.0, 1.0)
111
+ glVertex3f(-1.0, 1.0, -1.0)
112
+ glTexCoord2f(1.0, 0.0)
113
+ glVertex3f( 1.0, 1.0, -1.0)
114
+ glTexCoord2f(0.0, 0.0)
115
+ glVertex3f( 1.0, -1.0, -1.0)
116
+
117
+ # top face
118
+ glNormal3f( 0.0, 1.0, 0.0)
119
+ glTexCoord2f(0.0, 1.0)
120
+ glVertex3f(-1.0, 1.0, -1.0)
121
+ glTexCoord2f(1.0, 1.0)
122
+ glVertex3f(-1.0, 1.0, 1.0)
123
+ glTexCoord2f(1.0, 0.0)
124
+ glVertex3f( 1.0, 1.0, 1.0)
125
+ glTexCoord2f(0.0, 0.0)
126
+ glVertex3f( 1.0, 1.0, -1.0)
127
+
128
+ # bottom face
129
+ glNormal3f( 0.0, -1.0, 0.0)
130
+ glTexCoord2f(1.0, 1.0)
131
+ glVertex3f(-1.0, -1.0, -1.0)
132
+ glTexCoord2f(1.0, 0.0)
133
+ glVertex3f( 1.0, -1.0, -1.0)
134
+ glTexCoord2f(0.0, 0.0)
135
+ glVertex3f( 1.0, -1.0, 1.0)
136
+ glTexCoord2f(0.0, 1.0)
137
+ glVertex3f(-1.0, -1.0, 1.0)
138
+
139
+ # right face
140
+ glNormal3f( 1.0, 0.0, 0.0)
141
+ glTexCoord2f(1.0, 0.0)
142
+ glVertex3f( 1.0, -1.0, -1.0)
143
+ glTexCoord2f(0.0, 0.0)
144
+ glVertex3f( 1.0, 1.0, -1.0)
145
+ glTexCoord2f(0.0, 1.0)
146
+ glVertex3f( 1.0, 1.0, 1.0)
147
+ glTexCoord2f(1.0, 1.0)
148
+ glVertex3f( 1.0, -1.0, 1.0)
149
+
150
+ # left face
151
+ glNormal3f(-1.0, 0.0, 0.0)
152
+ glTexCoord2f(0.0, 0.0)
153
+ glVertex3f(-1.0, -1.0, -1.0)
154
+ glTexCoord2f(0.0, 1.0)
155
+ glVertex3f(-1.0, -1.0, 1.0)
156
+ glTexCoord2f(1.0, 1.0)
157
+ glVertex3f(-1.0, 1.0, 1.0)
158
+ glTexCoord2f(1.0, 0.0)
159
+ glVertex3f(-1.0, 1.0, -1.0)
160
+ end
161
+
162
+ @xrot += @x_speed
163
+ @yrot += @y_speed
164
+
165
+ glutSwapBuffers
166
+ end
167
+
168
+ def idle
169
+ glutPostRedisplay
170
+ end
171
+
172
+ def keyboard key, x, y
173
+ case key
174
+ when ?\e then
175
+ glutDestroyWindow @window
176
+ exit 0
177
+ when 'l' then
178
+ @lighting = !@lighting
179
+
180
+ if @lighting then
181
+ glEnable GL_LIGHTING
182
+ puts "lights on"
183
+ else
184
+ glDisable GL_LIGHTING
185
+ puts "lights off"
186
+ end
187
+ when 'f' then
188
+ @filter += 1
189
+ @filter %= 3
190
+
191
+ puts "texture #{@filter}"
192
+ when 'F' then
193
+ @fullscreen = !@fullscreen
194
+
195
+ if @fullscreen then
196
+ glutFullScreen
197
+ else
198
+ glutPositionWindow 0, 0
199
+ end
200
+ when 'B' then
201
+ @blending = !@blending
202
+
203
+ if @blending then
204
+ glDisable GL_DEPTH_TEST
205
+ glEnable GL_BLEND
206
+ puts "blending on"
207
+ else
208
+ glDisable GL_BLEND
209
+ glEnable GL_DEPTH_TEST
210
+ puts "blending off"
211
+ end
212
+ when 'X' then @x_speed += 0.01
213
+ when 'x' then @x_speed -= 0.01
214
+ when 'Y' then @y_speed += 0.01
215
+ when 'y' then @y_speed -= 0.01
216
+ when 'Z' then @z += 1.0
217
+ when 'z' then @z -= 1.0
218
+ else
219
+ puts key
220
+ end
221
+
222
+ glutPostRedisplay
223
+ end
224
+
225
+ def load_texture
226
+ png = PNG.load_file File.expand_path('../glass.png', __FILE__)
227
+ height = png.height
228
+ width = png.width
229
+
230
+ image = png.data.flatten.map { |c| c.values }.join
231
+
232
+ @textures = glGenTextures 3
233
+ glBindTexture GL_TEXTURE_2D, @textures[0]
234
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST
235
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST
236
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
237
+
238
+ glBindTexture GL_TEXTURE_2D, @textures[1]
239
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
240
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
241
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
242
+
243
+ glBindTexture GL_TEXTURE_2D, @textures[2]
244
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
245
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST
246
+ gluBuild2DMipmaps GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image
247
+ end
248
+
249
+ end
250
+
251
+ Lesson08.new
252
+