opengl 0.9.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.autotest +29 -0
- data/.gemtest +0 -0
- data/.gitignore +6 -0
- data/.travis.yml +19 -0
- data/History.rdoc +77 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +138 -0
- data/README.rdoc +102 -0
- data/Rakefile +60 -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 +155 -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/common.h +428 -0
- data/ext/opengl/conv.h +244 -0
- data/ext/opengl/extconf.rb +47 -0
- data/ext/opengl/funcdef.h +313 -0
- data/ext/opengl/gl-1.0-1.1.c +3075 -0
- data/ext/opengl/gl-1.2.c +155 -0
- data/ext/opengl/gl-1.3.c +443 -0
- data/ext/opengl/gl-1.4.c +348 -0
- data/ext/opengl/gl-1.5.c +224 -0
- data/ext/opengl/gl-2.0.c +667 -0
- data/ext/opengl/gl-2.1.c +57 -0
- data/ext/opengl/gl-3.0.c +493 -0
- data/ext/opengl/gl-enums.c +4873 -0
- data/ext/opengl/gl-enums.h +14588 -0
- data/ext/opengl/gl-error.c +112 -0
- data/ext/opengl/gl-error.h +28 -0
- data/ext/opengl/gl-ext-3dfx.c +27 -0
- data/ext/opengl/gl-ext-arb.c +875 -0
- data/ext/opengl/gl-ext-ati.c +41 -0
- data/ext/opengl/gl-ext-ext.c +889 -0
- data/ext/opengl/gl-ext-gremedy.c +41 -0
- data/ext/opengl/gl-ext-nv.c +680 -0
- data/ext/opengl/gl-types.h +67 -0
- data/ext/opengl/gl.c +220 -0
- data/ext/opengl/gl_buffer.c +177 -0
- data/ext/opengl/opengl.c +7 -0
- data/lib/gl.rb +1 -0
- data/lib/opengl.rb +53 -0
- data/lib/opengl/2.0/opengl.so +0 -0
- data/lib/opengl/2.1/opengl.so +0 -0
- data/lib/opengl/test_case.rb +86 -0
- data/test/dummy.xorg.conf +140 -0
- data/test/test_gl.rb +38 -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_opengl_buffer.rb +120 -0
- data/utils/README +6 -0
- data/utils/enumgen.rb +108 -0
- data/utils/extlistgen.rb +90 -0
- metadata +319 -0
- metadata.gz.sig +1 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'opengl'
|
4
|
+
require 'glu'
|
5
|
+
require 'glut'
|
6
|
+
require 'chunky_png'
|
7
|
+
|
8
|
+
class Lesson06
|
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
|
+
@zrot = 0.0
|
18
|
+
@fullscreen = true
|
19
|
+
|
20
|
+
glutInit
|
21
|
+
|
22
|
+
glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
|
23
|
+
glutInitWindowSize 640, 480
|
24
|
+
glutInitWindowPosition 0, 0
|
25
|
+
|
26
|
+
@window = glutCreateWindow "NeHe Lesson 06 - ruby-opengl version"
|
27
|
+
|
28
|
+
glutDisplayFunc :draw_gl_scene
|
29
|
+
glutReshapeFunc :reshape
|
30
|
+
glutIdleFunc :idle
|
31
|
+
glutKeyboardFunc :keyboard
|
32
|
+
|
33
|
+
reshape 640, 480
|
34
|
+
load_texture
|
35
|
+
init_gl
|
36
|
+
|
37
|
+
glutMainLoop
|
38
|
+
end
|
39
|
+
|
40
|
+
def init_gl
|
41
|
+
glEnable GL_TEXTURE_2D
|
42
|
+
glShadeModel GL_SMOOTH
|
43
|
+
glClearColor 0.0, 0.0, 0.0, 0.5
|
44
|
+
glClearDepth 1.0
|
45
|
+
glEnable GL_DEPTH_TEST
|
46
|
+
glDepthFunc GL_LEQUAL
|
47
|
+
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
|
48
|
+
end
|
49
|
+
|
50
|
+
def reshape width, height
|
51
|
+
width = width.to_f
|
52
|
+
height = height.to_f
|
53
|
+
height = 1.0 if height.zero?
|
54
|
+
|
55
|
+
glViewport 0, 0, width, height
|
56
|
+
|
57
|
+
glMatrixMode GL_PROJECTION
|
58
|
+
glLoadIdentity
|
59
|
+
|
60
|
+
gluPerspective 45.0, width / height, 0.1, 100.0
|
61
|
+
|
62
|
+
glMatrixMode GL_MODELVIEW
|
63
|
+
glLoadIdentity
|
64
|
+
end
|
65
|
+
|
66
|
+
def draw_gl_scene
|
67
|
+
glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
|
68
|
+
glMatrixMode GL_MODELVIEW
|
69
|
+
glLoadIdentity
|
70
|
+
glTranslatef 0.0, 0.0, -7.0
|
71
|
+
|
72
|
+
glRotatef @xrot, 1.0, 0.0, 0.0
|
73
|
+
glRotatef @yrot, 0.0, 1.0, 0.0
|
74
|
+
glRotatef @zrot, 0.0, 0.0, 1.0
|
75
|
+
|
76
|
+
glBindTexture GL_TEXTURE_2D, @textures[0]
|
77
|
+
|
78
|
+
glBegin GL_QUADS do
|
79
|
+
# front face
|
80
|
+
glTexCoord2f(0.0, 1.0)
|
81
|
+
glVertex3f(-1.0, -1.0, 1.0)
|
82
|
+
glTexCoord2f(1.0, 1.0)
|
83
|
+
glVertex3f( 1.0, -1.0, 1.0)
|
84
|
+
glTexCoord2f(1.0, 0.0)
|
85
|
+
glVertex3f( 1.0, 1.0, 1.0)
|
86
|
+
glTexCoord2f(0.0, 0.0)
|
87
|
+
glVertex3f(-1.0, 1.0, 1.0)
|
88
|
+
|
89
|
+
# back face
|
90
|
+
glTexCoord2f(0.0, 1.0)
|
91
|
+
glVertex3f(-1.0, -1.0, -1.0)
|
92
|
+
glTexCoord2f(1.0, 1.0)
|
93
|
+
glVertex3f(-1.0, 1.0, -1.0)
|
94
|
+
glTexCoord2f(1.0, 0.0)
|
95
|
+
glVertex3f( 1.0, 1.0, -1.0)
|
96
|
+
glTexCoord2f(0.0, 0.0)
|
97
|
+
glVertex3f( 1.0, -1.0, -1.0)
|
98
|
+
|
99
|
+
# top face
|
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
|
+
# bottom face
|
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
|
+
glTexCoord2f(0.0, 1.0)
|
117
|
+
glVertex3f(-1.0, -1.0, 1.0)
|
118
|
+
|
119
|
+
# right face
|
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
|
+
glTexCoord2f(0.0, 1.0)
|
125
|
+
glVertex3f( 1.0, 1.0, 1.0)
|
126
|
+
glTexCoord2f(1.0, 1.0)
|
127
|
+
glVertex3f( 1.0, -1.0, 1.0)
|
128
|
+
|
129
|
+
# left face
|
130
|
+
glTexCoord2f(0.0, 0.0)
|
131
|
+
glVertex3f(-1.0, -1.0, -1.0)
|
132
|
+
glTexCoord2f(0.0, 1.0)
|
133
|
+
glVertex3f(-1.0, -1.0, 1.0)
|
134
|
+
glTexCoord2f(1.0, 1.0)
|
135
|
+
glVertex3f(-1.0, 1.0, 1.0)
|
136
|
+
glTexCoord2f(1.0, 0.0)
|
137
|
+
glVertex3f(-1.0, 1.0, -1.0)
|
138
|
+
end
|
139
|
+
|
140
|
+
@xrot += 0.003
|
141
|
+
@yrot += 0.002
|
142
|
+
@zrot += 0.004
|
143
|
+
|
144
|
+
glutSwapBuffers
|
145
|
+
end
|
146
|
+
|
147
|
+
def idle
|
148
|
+
glutPostRedisplay
|
149
|
+
end
|
150
|
+
|
151
|
+
def keyboard key, x, y
|
152
|
+
case key
|
153
|
+
when ?\e
|
154
|
+
glutDestroyWindow @window
|
155
|
+
exit 0
|
156
|
+
when 'F' then
|
157
|
+
@fullscreen = !@fullscreen
|
158
|
+
|
159
|
+
if @fullscreen then
|
160
|
+
glutFullScreen
|
161
|
+
else
|
162
|
+
glutPositionWindow 0, 0
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
glutPostRedisplay
|
167
|
+
end
|
168
|
+
|
169
|
+
def load_texture
|
170
|
+
png = ChunkyPNG::Image.from_file(File.expand_path('../NeHe.png', __FILE__))
|
171
|
+
|
172
|
+
height = png.height
|
173
|
+
width = png.width
|
174
|
+
|
175
|
+
image = png.to_rgba_stream.each_byte.to_a
|
176
|
+
|
177
|
+
@textures = glGenTextures 1
|
178
|
+
glBindTexture GL_TEXTURE_2D, @textures[0]
|
179
|
+
glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
|
180
|
+
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
|
181
|
+
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
Lesson06.new
|
@@ -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
|