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,208 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson16
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
+ @filter = 0
17
+
18
+ @fog_mode = [
19
+ GL_EXP,
20
+ GL_EXP2,
21
+ GL_LINEAR
22
+ ]
23
+
24
+ @fog_filter = 0
25
+ @fog_color = [0.5, 0.5, 0.5, 1.0]
26
+
27
+ glutInit
28
+
29
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
30
+ glutInitWindowSize 640, 480
31
+ glutInitWindowPosition 0, 0
32
+
33
+ @window = glutCreateWindow "NeHe Lesson 16 - ruby-opengl version"
34
+
35
+ glutDisplayFunc :draw_gl_scene
36
+ glutReshapeFunc :reshape
37
+ glutIdleFunc :idle
38
+ glutKeyboardFunc :keyboard
39
+
40
+ reshape 640, 480
41
+ load_texture
42
+ init_gl
43
+
44
+ glutMainLoop
45
+ end
46
+
47
+ def init_gl
48
+ glEnable GL_TEXTURE_2D
49
+ glShadeModel GL_SMOOTH
50
+ glClearColor 0.5, 0.5, 0.5, 1.0
51
+
52
+ glFogi GL_FOG_MODE, @fog_mode[@fog_filter]
53
+ glFogfv GL_FOG_COLOR, @fog_color
54
+ glFogf GL_FOG_DENSITY, 0.35
55
+ glHint GL_FOG_HINT, GL_DONT_CARE
56
+ glFogf GL_FOG_START, 2.0
57
+ glFogf GL_FOG_END, 8.0
58
+ glEnable GL_FOG
59
+
60
+ glClearDepth 1.0
61
+ glEnable GL_DEPTH_TEST
62
+ glDepthFunc GL_LEQUAL
63
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
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
+ end
81
+
82
+ def draw_gl_scene
83
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
84
+ glMatrixMode GL_MODELVIEW
85
+ glLoadIdentity
86
+ glTranslatef 0.0, 0.0, -7.0
87
+
88
+ glRotatef @xrot, 1.0, 0.0, 0.0
89
+ glRotatef @yrot, 0.0, 1.0, 0.0
90
+ glRotatef @zrot, 0.0, 0.0, 1.0
91
+
92
+ glBindTexture GL_TEXTURE_2D, @textures[0]
93
+
94
+ glBegin GL_QUADS do
95
+ # front face
96
+ glTexCoord2f(0.0, 1.0)
97
+ glVertex3f(-1.0, -1.0, 1.0)
98
+ glTexCoord2f(1.0, 1.0)
99
+ glVertex3f( 1.0, -1.0, 1.0)
100
+ glTexCoord2f(1.0, 0.0)
101
+ glVertex3f( 1.0, 1.0, 1.0)
102
+ glTexCoord2f(0.0, 0.0)
103
+ glVertex3f(-1.0, 1.0, 1.0)
104
+
105
+ # back face
106
+ glTexCoord2f(0.0, 1.0)
107
+ glVertex3f(-1.0, -1.0, -1.0)
108
+ glTexCoord2f(1.0, 1.0)
109
+ glVertex3f(-1.0, 1.0, -1.0)
110
+ glTexCoord2f(1.0, 0.0)
111
+ glVertex3f( 1.0, 1.0, -1.0)
112
+ glTexCoord2f(0.0, 0.0)
113
+ glVertex3f( 1.0, -1.0, -1.0)
114
+
115
+ # top face
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
+ glTexCoord2f(1.0, 1.0)
127
+ glVertex3f(-1.0, -1.0, -1.0)
128
+ glTexCoord2f(1.0, 0.0)
129
+ glVertex3f( 1.0, -1.0, -1.0)
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
+
135
+ # right face
136
+ glTexCoord2f(1.0, 0.0)
137
+ glVertex3f( 1.0, -1.0, -1.0)
138
+ glTexCoord2f(0.0, 0.0)
139
+ glVertex3f( 1.0, 1.0, -1.0)
140
+ glTexCoord2f(0.0, 1.0)
141
+ glVertex3f( 1.0, 1.0, 1.0)
142
+ glTexCoord2f(1.0, 1.0)
143
+ glVertex3f( 1.0, -1.0, 1.0)
144
+
145
+ # left face
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
+ glTexCoord2f(1.0, 0.0)
153
+ glVertex3f(-1.0, 1.0, -1.0)
154
+ end
155
+
156
+ @xrot += 0.03
157
+ @yrot += 0.02
158
+ @zrot += 0.04
159
+
160
+ glutSwapBuffers
161
+ end
162
+
163
+ def idle
164
+ glutPostRedisplay
165
+ end
166
+
167
+ def keyboard key, x, y
168
+ case key
169
+ when ?\e
170
+ glutDestroyWindow @window
171
+ exit 0
172
+ when 'F' then
173
+ @fullscreen = !@fullscreen
174
+
175
+ if @fullscreen then
176
+ glutFullScreen
177
+ else
178
+ glutPositionWindow 0, 0
179
+ end
180
+ when 'f' then
181
+ @fog_filter += 1
182
+ @fog_filter %= 3
183
+
184
+ glFogi GL_FOG_MODE, @fog_mode[@fog_filter]
185
+ puts "fog #{@fog_filter}"
186
+ end
187
+
188
+ glutPostRedisplay
189
+ end
190
+
191
+ def load_texture
192
+ png = PNG.load_file File.expand_path('../crate.png', __FILE__)
193
+ height = png.height
194
+ width = png.width
195
+
196
+ image = png.data.flatten.map { |c| c.values }.join
197
+
198
+ @textures = glGenTextures 1
199
+ glBindTexture GL_TEXTURE_2D, @textures[0]
200
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
201
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
202
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
203
+ end
204
+
205
+ end
206
+
207
+ Lesson16.new
208
+
@@ -0,0 +1,206 @@
1
+ require 'opengl'
2
+ require 'png'
3
+ require 'png/reader'
4
+
5
+ class Lesson19
6
+ include Gl
7
+ include Glu
8
+ include Glut
9
+
10
+ Particle = Struct.new(:active, :life, :fade,
11
+ :r, :g, :b,
12
+ :x, :y, :z,
13
+ :xi, :yi, :zi,
14
+ :xg, :yg, :zg)
15
+
16
+ def initialize
17
+ @fullscreen = true
18
+ @rainbow = true
19
+ @slowdown = 2.0
20
+ @x_speed = 2.0
21
+ @y_speed = 5.0
22
+ @zoom = -100.0
23
+ @textures = nil
24
+ @colors = [
25
+ [1.0, 0.5, 0.5],
26
+ [1.0, 0.75, 0.5],
27
+ [1.0, 1.0, 0.5],
28
+ [0.75, 1.0, 0.5],
29
+ [0.5, 1.0, 0.5],
30
+ [0.5, 1.0, 0.75],
31
+ [0.5, 1.0, 1.0],
32
+ [0.5, 0.75, 1.0],
33
+ [0.5, 0.5, 1.0],
34
+ [0.75, 0.5, 1.0],
35
+ [1.0, 0.5, 1.0],
36
+ [1.0, 0.5, 0.75],
37
+ ]
38
+ @color = 0
39
+
40
+ @max_particles = 1_000
41
+ @particles = (0...@max_particles).map do |i|
42
+ Particle.new(true, # active
43
+ 1.0, # life
44
+ rand(100) / 1000.0 + 0.003, # fade
45
+ @colors[i % 12][0], # red
46
+ @colors[i % 12][1], # green
47
+ @colors[i % 12][2], # blue
48
+ 0.0, 0.0, 0.0, # x, y, z
49
+ (rand * 2 - 1), # x speed
50
+ (rand * 2 - 1), # y speed
51
+ (rand * 2 - 1), # z speed
52
+ 0.0, # x gravity
53
+ -0.8, # y gravity
54
+ 0.0) # z gravity
55
+ end
56
+
57
+ glutInit
58
+
59
+ glutInitDisplayMode GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
60
+ glutInitWindowSize 640, 480
61
+ glutInitWindowPosition 0, 0
62
+
63
+ @window = glutCreateWindow "NeHe Lesson 19 - ruby-opengl version"
64
+
65
+ glutDisplayFunc :draw_gl_scene
66
+ glutReshapeFunc :reshape
67
+ glutIdleFunc :idle
68
+ glutKeyboardFunc :keyboard
69
+
70
+ reshape 640, 480
71
+ load_texture
72
+ init_gl
73
+
74
+ glutMainLoop
75
+ end
76
+
77
+ def init_gl
78
+ glShadeModel GL_SMOOTH
79
+ glClearColor 0, 0, 0, 0
80
+
81
+ glClearDepth 1.0
82
+ glDisable GL_DEPTH_TEST
83
+ glEnable GL_BLEND
84
+ glBlendFunc GL_SRC_ALPHA, GL_ONE
85
+ glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
86
+ glHint GL_POINT_SMOOTH_HINT, GL_NICEST
87
+ glEnable GL_TEXTURE_2D
88
+ glBindTexture GL_TEXTURE_2D, @textures[0]
89
+ end
90
+
91
+ def reshape width, height
92
+ width = width.to_f
93
+ height = height.to_f
94
+ height = 1.0 if height.zero?
95
+
96
+ glViewport 0, 0, width, height
97
+
98
+ glMatrixMode GL_PROJECTION
99
+ glLoadIdentity
100
+
101
+ gluPerspective 45, width / height, 0.1, 200
102
+
103
+ glMatrixMode GL_MODELVIEW
104
+ glLoadIdentity
105
+ end
106
+
107
+ def draw_gl_scene
108
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
109
+ glLoadIdentity
110
+
111
+ @particles.each do |particle|
112
+ next unless particle.active
113
+
114
+ x = particle.x
115
+ y = particle.y
116
+ z = particle.z + @zoom
117
+
118
+ glColor4f particle.r, particle.g, particle.b, particle.life
119
+
120
+ glBegin GL_TRIANGLE_STRIP do
121
+ glTexCoord2d 1, 1; glVertex3f x + 0.5, y + 0.5, z
122
+ glTexCoord2d 0, 1; glVertex3f x - 0.5, y + 0.5, z
123
+ glTexCoord2d 1, 0; glVertex3f x + 0.5, y - 0.5, z
124
+ glTexCoord2d 0, 0; glVertex3f x - 0.5, y - 0.5, z
125
+ end
126
+
127
+ particle.x += particle.xi / @slowdown
128
+ particle.y += particle.yi / @slowdown
129
+ particle.z += particle.zi / @slowdown
130
+
131
+ particle.xi += particle.xg
132
+ particle.yi += particle.yg
133
+ particle.zi += particle.zg
134
+
135
+ particle.life -= particle.fade
136
+
137
+ if particle.life < 0 then
138
+ particle.life = 1.0
139
+ particle.fade = rand(100) / 1000.0 + 0.003
140
+
141
+ particle.x = 0.0
142
+ particle.y = 0.0
143
+ particle.z = 0.0
144
+
145
+ particle.xi = @x_speed + rand * 2 - 1
146
+ particle.yi = @y_speed + rand * 2 - 1
147
+ particle.zi = rand * 2 - 1
148
+
149
+ particle.r = @colors[@color][0]
150
+ particle.g = @colors[@color][1]
151
+ particle.b = @colors[@color][2]
152
+
153
+ @color += 1
154
+ @color %= @colors.length - 1
155
+ end
156
+ end
157
+
158
+ glutSwapBuffers
159
+ end
160
+
161
+ def idle
162
+ glutPostRedisplay
163
+ end
164
+
165
+ def keyboard key, x, y
166
+ case key
167
+ when ?\e
168
+ glutDestroyWindow @window
169
+ exit 0
170
+ when 'F' then
171
+ @fullscreen = !@fullscreen
172
+
173
+ if @fullscreen then
174
+ glutFullScreen
175
+ else
176
+ glutPositionWindow 0, 0
177
+ end
178
+ when 'f' then
179
+ @fog_filter += 1
180
+ @fog_filter %= 3
181
+
182
+ glFogi GL_FOG_MODE, @fog_mode[@fog_filter]
183
+ puts "fog #{@fog_filter}"
184
+ end
185
+
186
+ glutPostRedisplay
187
+ end
188
+
189
+ def load_texture
190
+ png = PNG.load_file File.expand_path('../particle.png', __FILE__)
191
+ height = png.height
192
+ width = png.width
193
+
194
+ image = png.data.flatten.map { |c| c.values }.join
195
+
196
+ @textures = glGenTextures 1
197
+ glBindTexture GL_TEXTURE_2D, @textures[0]
198
+ glTexImage2D GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image
199
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
200
+ glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
201
+ end
202
+
203
+ end
204
+
205
+ Lesson19.new
206
+
Binary file
Binary file
@@ -0,0 +1,154 @@
1
+ # This example comes from the Red Book chapter 5, example 5-1 light.c
2
+
3
+ require 'opengl'
4
+ require 'mathn'
5
+
6
+ def init
7
+ @fullscreen = false
8
+ @xrot = 0
9
+ @yrot = 0
10
+ @zrot = 0
11
+
12
+ glClearColor 0, 0, 0, 0
13
+ glShadeModel GL_SMOOTH
14
+
15
+ glMaterialfv GL_FRONT, GL_DIFFUSE, [1, 0, 0, 1]
16
+ glMaterialfv GL_FRONT, GL_SPECULAR, [0, 1, 0, 1]
17
+ glMaterialfv GL_FRONT, GL_AMBIENT, [0, 0, 0.75, 1]
18
+ glMaterialfv GL_FRONT, GL_SHININESS, [40]
19
+ glLightfv GL_LIGHT0, GL_POSITION, [0, 1, -0.25]
20
+
21
+ glEnable GL_LIGHTING
22
+ glEnable GL_LIGHT0
23
+ glEnable GL_DEPTH_TEST
24
+ glEnable GL_NORMALIZE
25
+ end
26
+
27
+ def cross_product a, b
28
+ Vector[a[1] * b[2] - a[2] * b[1],
29
+ a[2] * b[0] - a[0] * b[2],
30
+ a[0] * b[1] - a[1] * b[0]]
31
+ end
32
+
33
+ def normal v1, v2, v3
34
+ cross_product v1 - v2, v2 - v3
35
+ end
36
+
37
+ def normals_for_triangle_fan vertexes
38
+ center = vertexes.first
39
+
40
+ vertex_normals = vertexes[1..-1].each_cons(2).map do |a, b|
41
+ normal center, a, b
42
+ end
43
+
44
+ normals = vertex_normals.each_cons(2).map do |a, b|
45
+ a + b
46
+ end
47
+
48
+ normals.unshift vertex_normals.first(3).inject :+
49
+ normals.push vertex_normals.first + vertex_normals.last
50
+ normals.push normals[1]
51
+
52
+ normals
53
+ end
54
+
55
+ def display
56
+ glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
57
+ glLoadIdentity
58
+ #glutSolidSphere 1.0, 50, 50
59
+ glRotate @xrot, 1, 0, 0
60
+ glRotate @yrot, 0, 1, 0
61
+ glRotate @zrot, 0, 0, 1
62
+
63
+ #glBegin GL_POLYGON do
64
+ # glVertex2f -1, 1
65
+ # glVertex2f 1, 1
66
+ # glVertex2f 1, -1
67
+ # glVertex2f -1, -1
68
+ #end
69
+
70
+ glMaterialfv GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 1, 1, 1]
71
+ glMaterialfv GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 1]
72
+ glMaterialfv GL_FRONT_AND_BACK, GL_AMBIENT, [1, 1, 1, 1]
73
+ glMaterialfv GL_FRONT, GL_SHININESS, [40]
74
+ glBegin GL_LINES do
75
+ glVertex3f 0, 0, 0
76
+ glVertex3f 0, 0, 1
77
+ end
78
+
79
+ glMaterialfv GL_FRONT, GL_DIFFUSE, [1, 0, 0, 1]
80
+ glMaterialfv GL_FRONT, GL_SPECULAR, [0, 1, 0, 1]
81
+ glMaterialfv GL_FRONT, GL_AMBIENT, [0, 0, 0.75, 1]
82
+ glMaterialfv GL_FRONT, GL_SHININESS, [40]
83
+
84
+ vertices = [
85
+ Vector[ 0.00, -0.4, 0.1],
86
+ Vector[ 0.00, 0.5, 0.0],
87
+ Vector[ 0.24, -0.5, 0.0],
88
+ Vector[-0.24, -0.5, 0.0],
89
+ Vector[ 0.00, 0.5, 0.0],
90
+ ]
91
+
92
+ normals = normals_for_triangle_fan vertices
93
+
94
+ glBegin GL_TRIANGLE_FAN do
95
+ normals.zip(vertices).each do |normal, vertex|
96
+ glNormal3fv normal
97
+ glVertex3fv vertex
98
+ end
99
+ end
100
+ glFlush
101
+ end
102
+
103
+ def reshape w, h
104
+ glViewport 0, 0, w, h
105
+ glMatrixMode GL_PROJECTION
106
+ glLoadIdentity
107
+
108
+ if w <= h then
109
+ glOrtho -1.5, 1.5, -1.5 * h / w, 1.5 * h / w, -10.0, 10.0
110
+ else
111
+ glOrtho -1.5 * w / h, 1.5 * w / h, -1.5, 1.5, -10.0, 10.0
112
+ end
113
+
114
+ glMatrixMode GL_MODELVIEW
115
+ glLoadIdentity
116
+ end
117
+
118
+ def keyboard key, x, y
119
+ case key
120
+ when ?\e
121
+ glutDestroyWindow $window
122
+ exit 0
123
+ when 'X' then @xrot += 1
124
+ when 'x' then @xrot -= 1
125
+ when 'Y' then @yrot += 1
126
+ when 'y' then @yrot -= 1
127
+ when 'Z' then @zrot += 1
128
+ when 'z' then @zrot -= 1
129
+ when 'F' then
130
+ @fullscreen = !@fullscreen
131
+
132
+ if @fullscreen then
133
+ glutFullScreen
134
+ else
135
+ glutPositionWindow 0, 0
136
+ end
137
+ end
138
+
139
+ p key => [@xrot, @yrot, @zrot]
140
+
141
+ glutPostRedisplay
142
+ end
143
+
144
+ glutInit
145
+ glutInitDisplayMode GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH
146
+ glutInitWindowSize 500, 500
147
+ glutInitWindowPosition 100, 100
148
+ $window = glutCreateWindow 'example 5-1: light'
149
+ init
150
+ glutDisplayFunc :display
151
+ glutReshapeFunc :reshape
152
+ glutKeyboardFunc :keyboard
153
+ glutMainLoop
154
+