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