sgl 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +254 -234
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/Rakefile +27 -7
- data/examples/cocoa1-basic.rb +14 -14
- data/examples/cocoa10-transparent.rb +26 -26
- data/examples/cocoa11-application.rb +13 -13
- data/examples/cocoa2-draw.rb +23 -23
- data/examples/cocoa3-affine.rb +29 -29
- data/examples/cocoa4-font.rb +24 -24
- data/examples/cocoa5-image.rb +22 -22
- data/examples/cocoa6-sound.rb +24 -24
- data/examples/cocoa7-movie.rb +40 -40
- data/examples/cocoa8-movieoverlay.rb +42 -42
- data/examples/cocoa9-streaming.rb +40 -40
- data/examples/opengl1-basic.rb +14 -14
- data/examples/opengl11-application.rb +13 -13
- data/examples/opengl2-draw.rb +23 -23
- data/examples/opengl3-affine.rb +29 -29
- data/examples/sample1.rb +11 -11
- data/examples/sample10.rb +16 -16
- data/examples/sample11.rb +22 -22
- data/examples/sample11a.rb +33 -33
- data/examples/sample12.rb +30 -30
- data/examples/sample12a.rb +35 -35
- data/examples/sample13.rb +116 -116
- data/examples/sample15.rb +24 -24
- data/examples/sample16.rb +31 -31
- data/examples/sample16a.rb +35 -35
- data/examples/sample6.rb +18 -18
- data/examples/sample7.rb +16 -16
- data/examples/sample9.rb +20 -20
- data/examples/testgl.rb +169 -169
- data/lib/sgl/bass.rb +46 -46
- data/lib/sgl/cocoa-app.rb +43 -43
- data/lib/sgl/cocoa-color.rb +65 -65
- data/lib/sgl/cocoa-draw.rb +72 -72
- data/lib/sgl/cocoa-event.rb +229 -229
- data/lib/sgl/cocoa-media.rb +144 -144
- data/lib/sgl/cocoa-notuse.rb +493 -493
- data/lib/sgl/cocoa-window.rb +203 -203
- data/lib/sgl/cocoa.rb +8 -8
- data/lib/sgl/opengl-app.rb +38 -38
- data/lib/sgl/opengl-color.rb +44 -44
- data/lib/sgl/opengl-draw.rb +260 -260
- data/lib/sgl/opengl-event.rb +325 -325
- data/lib/sgl/opengl-modules.rb +22 -22
- data/lib/sgl/opengl-window.rb +224 -224
- data/lib/sgl/opengl.rb +7 -7
- data/lib/sgl/sgl-button.rb +135 -135
- data/lib/sgl/sgl-client.rb +21 -21
- data/lib/sgl/sgl-color.rb +68 -82
- data/lib/sgl/sgl-connect.rb +9 -9
- data/lib/sgl/sgl-server.rb +58 -58
- data/lib/sgl/sgl-spring.rb +216 -216
- data/lib/sgl/version.rb +2 -2
- data/scripts/lib-txt2html.rb +130 -0
- data/scripts/txt2html +2 -63
- data/spec/sgl_spec.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -0
- data/test/test_cocoa_app.rb +291 -291
- data/test/test_module_ruby16.rb +30 -30
- data/test/test_opengl_app.rb +147 -147
- data/test/test_opengl_basic.rb +22 -22
- data/test/test_opengl_fullscreen.rb +23 -23
- data/test/test_opengl_novice.rb +35 -35
- data/website/challenge1.html +91 -91
- data/website/challenge1.txt +3 -3
- data/website/challenge2.html +143 -144
- data/website/challenge2.txt +13 -14
- data/website/challenge3.html +66 -63
- data/website/challenge3.txt +7 -7
- data/website/cocoa.html +85 -88
- data/website/cocoa.txt +2 -4
- data/website/description.html +138 -138
- data/website/description.txt +1 -1
- data/website/exercise1.html +262 -264
- data/website/exercise1.txt +58 -53
- data/website/exercise2.html +241 -683
- data/website/exercise2.txt +11 -427
- data/website/exercise3.html +206 -0
- data/website/exercise3.txt +155 -0
- data/website/exercise4.html +198 -0
- data/website/exercise4.txt +151 -0
- data/website/exercise5.html +162 -0
- data/website/exercise5.txt +113 -0
- data/website/exhibition.html +84 -84
- data/website/howto.html +146 -134
- data/website/howto.txt +9 -0
- data/website/index.html +178 -178
- data/website/index.txt +20 -19
- data/website/sound.html +141 -141
- metadata +16 -3
data/examples/sample15.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require "sgl"
|
2
|
-
|
3
|
-
def setup
|
4
|
-
window 100, 100
|
5
|
-
end
|
6
|
-
|
7
|
-
def my_rect(x1, y1, x2, y2, outline, fill)
|
8
|
-
color fill
|
9
|
-
rect x1, y1, x2, y2
|
10
|
-
color outline
|
11
|
-
line x1, y1, x2, y1
|
12
|
-
line x2, y1, x2, y2
|
13
|
-
line x2, y2, x1, y2
|
14
|
-
line x1, y2, x1, y1
|
15
|
-
end
|
16
|
-
|
17
|
-
def display
|
18
|
-
mx = mouseX
|
19
|
-
my = mouseY
|
20
|
-
my_rect(20, 20, 40, 30, 80, 50)
|
21
|
-
my_rect(60, 60, 80, 90, 90, 30)
|
22
|
-
end
|
23
|
-
|
24
|
-
mainloop
|
1
|
+
require "sgl"
|
2
|
+
|
3
|
+
def setup
|
4
|
+
window 100, 100
|
5
|
+
end
|
6
|
+
|
7
|
+
def my_rect(x1, y1, x2, y2, outline, fill)
|
8
|
+
color fill
|
9
|
+
rect x1, y1, x2, y2
|
10
|
+
color outline
|
11
|
+
line x1, y1, x2, y1
|
12
|
+
line x2, y1, x2, y2
|
13
|
+
line x2, y2, x1, y2
|
14
|
+
line x1, y2, x1, y1
|
15
|
+
end
|
16
|
+
|
17
|
+
def display
|
18
|
+
mx = mouseX
|
19
|
+
my = mouseY
|
20
|
+
my_rect(20, 20, 40, 30, 80, 50)
|
21
|
+
my_rect(60, 60, 80, 90, 90, 30)
|
22
|
+
end
|
23
|
+
|
24
|
+
mainloop
|
data/examples/sample16.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require "sgl"
|
2
|
-
|
3
|
-
def setup
|
4
|
-
window -200, -200, 200, 200
|
5
|
-
background 100
|
6
|
-
end
|
7
|
-
|
8
|
-
def display
|
9
|
-
x = mouseX
|
10
|
-
y = mouseY
|
11
|
-
|
12
|
-
push
|
13
|
-
color 100, 0, 0
|
14
|
-
translate x, y, 0
|
15
|
-
rotateX x
|
16
|
-
rotateY y
|
17
|
-
scale 2
|
18
|
-
rect -5, -5, 5, 5
|
19
|
-
pop
|
20
|
-
|
21
|
-
push
|
22
|
-
color 100, 0, 0
|
23
|
-
translate x, y, 0
|
24
|
-
rotateX x
|
25
|
-
rotateY y
|
26
|
-
scale 2
|
27
|
-
rect 5, 5, 10, 10
|
28
|
-
pop
|
29
|
-
end
|
30
|
-
|
31
|
-
mainloop
|
1
|
+
require "sgl"
|
2
|
+
|
3
|
+
def setup
|
4
|
+
window -200, -200, 200, 200
|
5
|
+
background 100
|
6
|
+
end
|
7
|
+
|
8
|
+
def display
|
9
|
+
x = mouseX
|
10
|
+
y = mouseY
|
11
|
+
|
12
|
+
push
|
13
|
+
color 100, 0, 0
|
14
|
+
translate x, y, 0
|
15
|
+
rotateX x
|
16
|
+
rotateY y
|
17
|
+
scale 2
|
18
|
+
rect -5, -5, 5, 5
|
19
|
+
pop
|
20
|
+
|
21
|
+
push
|
22
|
+
color 100, 0, 0
|
23
|
+
translate x, y, 0
|
24
|
+
rotateX x
|
25
|
+
rotateY y
|
26
|
+
scale 2
|
27
|
+
rect 5, 5, 10, 10
|
28
|
+
pop
|
29
|
+
end
|
30
|
+
|
31
|
+
mainloop
|
data/examples/sample16a.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
require "sgl"
|
2
|
-
|
3
|
-
def setup
|
4
|
-
window -200, -200, 200, 200
|
5
|
-
background 100
|
6
|
-
$pos = [] # ���g����̔z���p�ӂ���D
|
7
|
-
end
|
8
|
-
|
9
|
-
def display
|
10
|
-
x = mouseX
|
11
|
-
y = mouseY
|
12
|
-
|
13
|
-
$pos << [x, y] # �z��Ɍ��݂̃}�E�X�̈ʒu��lj�����D
|
14
|
-
|
15
|
-
$pos.each {|pos| # �z��̊e�X�̗v�f�ɂ���{}�̒��g�����s����D
|
16
|
-
# ���̊e�X�̗v�f��pos�Ƃ����ϐ��ɓ���D
|
17
|
-
x = pos[0]
|
18
|
-
y = pos[1]
|
19
|
-
|
20
|
-
push
|
21
|
-
colorHSV 0, 100, 100, 10
|
22
|
-
translate x, y, 0
|
23
|
-
rotateX x
|
24
|
-
rotateY y
|
25
|
-
scale 20
|
26
|
-
rect -5, -5, 5, 5
|
27
|
-
pop
|
28
|
-
}
|
29
|
-
|
30
|
-
if 10 < $pos.length # �����z���܂肷�����ꍇ�͐擪���珇�Ɏ̂Ă�D
|
31
|
-
$pos.shift
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
mainloop
|
1
|
+
require "sgl"
|
2
|
+
|
3
|
+
def setup
|
4
|
+
window -200, -200, 200, 200
|
5
|
+
background 100
|
6
|
+
$pos = [] # ���g����̔z���p�ӂ���D
|
7
|
+
end
|
8
|
+
|
9
|
+
def display
|
10
|
+
x = mouseX
|
11
|
+
y = mouseY
|
12
|
+
|
13
|
+
$pos << [x, y] # �z��Ɍ��݂̃}�E�X�̈ʒu��lj�����D
|
14
|
+
|
15
|
+
$pos.each {|pos| # �z��̊e�X�̗v�f�ɂ���{}�̒��g�����s����D
|
16
|
+
# ���̊e�X�̗v�f��pos�Ƃ����ϐ��ɓ���D
|
17
|
+
x = pos[0]
|
18
|
+
y = pos[1]
|
19
|
+
|
20
|
+
push
|
21
|
+
colorHSV 0, 100, 100, 10
|
22
|
+
translate x, y, 0
|
23
|
+
rotateX x
|
24
|
+
rotateY y
|
25
|
+
scale 20
|
26
|
+
rect -5, -5, 5, 5
|
27
|
+
pop
|
28
|
+
}
|
29
|
+
|
30
|
+
if 10 < $pos.length # �����z���܂肷�����ꍇ�͐擪���珇�Ɏ̂Ă�D
|
31
|
+
$pos.shift
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
mainloop
|
data/examples/sample6.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require "sgl"
|
2
|
-
|
3
|
-
def setup
|
4
|
-
window 200, 200
|
5
|
-
end
|
6
|
-
|
7
|
-
def display
|
8
|
-
for a in 0..200
|
9
|
-
color a/2, 50, 50
|
10
|
-
if a < 100
|
11
|
-
line a, 50, a, 100
|
12
|
-
else
|
13
|
-
line a, 100, a, 150
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
mainloop
|
1
|
+
require "sgl"
|
2
|
+
|
3
|
+
def setup
|
4
|
+
window 200, 200
|
5
|
+
end
|
6
|
+
|
7
|
+
def display
|
8
|
+
for a in 0..200
|
9
|
+
color a/2, 50, 50
|
10
|
+
if a < 100
|
11
|
+
line a, 50, a, 100
|
12
|
+
else
|
13
|
+
line a, 100, a, 150
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
mainloop
|
data/examples/sample7.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require "sgl"
|
2
|
-
|
3
|
-
def setup
|
4
|
-
window 200, 200
|
5
|
-
end
|
6
|
-
|
7
|
-
def display
|
8
|
-
for a in 0..10
|
9
|
-
for b in 0..10
|
10
|
-
color a*10, b*10, b*10
|
11
|
-
rect a*20+5, b*20+5, a*20+15, b*20+15
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
mainloop
|
1
|
+
require "sgl"
|
2
|
+
|
3
|
+
def setup
|
4
|
+
window 200, 200
|
5
|
+
end
|
6
|
+
|
7
|
+
def display
|
8
|
+
for a in 0..10
|
9
|
+
for b in 0..10
|
10
|
+
color a*10, b*10, b*10
|
11
|
+
rect a*20+5, b*20+5, a*20+15, b*20+15
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
mainloop
|
data/examples/sample9.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require "sgl"
|
2
|
-
|
3
|
-
def setup
|
4
|
-
window -200, -200, 200, 200
|
5
|
-
end
|
6
|
-
|
7
|
-
def display
|
8
|
-
beginObj(POLYGON)
|
9
|
-
color 100, 0, 0, 0
|
10
|
-
vertex 60, 90
|
11
|
-
color 0, 100, 0, 100
|
12
|
-
vertex -120, 60
|
13
|
-
color 0, 0, 100, 100
|
14
|
-
vertex -90, -90
|
15
|
-
color 100, 100, 0, 0
|
16
|
-
vertex 120, -90
|
17
|
-
endObj
|
18
|
-
end
|
19
|
-
|
20
|
-
mainloop
|
1
|
+
require "sgl"
|
2
|
+
|
3
|
+
def setup
|
4
|
+
window -200, -200, 200, 200
|
5
|
+
end
|
6
|
+
|
7
|
+
def display
|
8
|
+
beginObj(POLYGON)
|
9
|
+
color 100, 0, 0, 0
|
10
|
+
vertex 60, 90
|
11
|
+
color 0, 100, 0, 100
|
12
|
+
vertex -120, 60
|
13
|
+
color 0, 0, 100, 100
|
14
|
+
vertex -90, -90
|
15
|
+
color 100, 100, 0, 0
|
16
|
+
vertex 120, -90
|
17
|
+
endObj
|
18
|
+
end
|
19
|
+
|
20
|
+
mainloop
|
data/examples/testgl.rb
CHANGED
@@ -1,169 +1,169 @@
|
|
1
|
-
# You can use this test program to run Ruby/SDL, Ruby/OpenGL themselves.
|
2
|
-
# I created sgl by extending this small program.
|
3
|
-
|
4
|
-
require 'sdl'
|
5
|
-
require 'opengl'
|
6
|
-
|
7
|
-
SDL.init SDL::INIT_VIDEO
|
8
|
-
SDL.setGLAttr SDL::GL_RED_SIZE,5
|
9
|
-
SDL.setGLAttr SDL::GL_GREEN_SIZE,5
|
10
|
-
SDL.setGLAttr SDL::GL_BLUE_SIZE,5
|
11
|
-
SDL.setGLAttr SDL::GL_DEPTH_SIZE,16
|
12
|
-
SDL.setGLAttr SDL::GL_DOUBLEBUFFER,1
|
13
|
-
SDL.setVideoMode 640,400,16,SDL::OPENGL
|
14
|
-
GL::Viewport( 0, 0, 640, 400 );
|
15
|
-
GL::MatrixMode( GL::PROJECTION );
|
16
|
-
GL::LoadIdentity( );
|
17
|
-
|
18
|
-
GL::MatrixMode( GL::MODELVIEW );
|
19
|
-
GL::LoadIdentity( );
|
20
|
-
|
21
|
-
GL::Enable(GL::DEPTH_TEST);
|
22
|
-
|
23
|
-
GL::DepthFunc(GL::LESS);
|
24
|
-
|
25
|
-
GL::ShadeModel(GL::SMOOTH);
|
26
|
-
|
27
|
-
event=SDL::Event.new
|
28
|
-
shadedCube=true
|
29
|
-
|
30
|
-
color =
|
31
|
-
[[ 1.0, 1.0, 0.0],
|
32
|
-
[ 1.0, 0.0, 0.0],
|
33
|
-
[ 0.0, 0.0, 0.0],
|
34
|
-
[ 0.0, 1.0, 0.0],
|
35
|
-
[ 0.0, 1.0, 1.0],
|
36
|
-
[ 1.0, 1.0, 1.0],
|
37
|
-
[ 1.0, 0.0, 1.0],
|
38
|
-
[ 0.0, 0.0, 1.0]]
|
39
|
-
|
40
|
-
cube =
|
41
|
-
[[ 0.5, 0.5, -0.5],
|
42
|
-
[ 0.5, -0.5, -0.5],
|
43
|
-
[-0.5, -0.5, -0.5],
|
44
|
-
[-0.5, 0.5, -0.5],
|
45
|
-
[-0.5, 0.5, 0.5],
|
46
|
-
[ 0.5, 0.5, 0.5],
|
47
|
-
[ 0.5, -0.5, 0.5],
|
48
|
-
[-0.5, -0.5, 0.5]]
|
49
|
-
|
50
|
-
|
51
|
-
loop do
|
52
|
-
|
53
|
-
if event.poll != 0 then
|
54
|
-
if event.type==SDL::Event::QUIT then
|
55
|
-
break
|
56
|
-
end
|
57
|
-
if event.type==SDL::Event::KEYDOWN then
|
58
|
-
exit
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
GL.ClearColor(0.0, 0.0, 0.0, 1.0);
|
63
|
-
GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
|
64
|
-
|
65
|
-
|
66
|
-
GL::Begin(GL::QUADS)
|
67
|
-
|
68
|
-
if shadedCube then
|
69
|
-
GL::Color(color[0]);
|
70
|
-
GL::Vertex(cube[0]);
|
71
|
-
GL::Color(color[1]);
|
72
|
-
GL::Vertex(cube[1]);
|
73
|
-
GL::Color(color[2]);
|
74
|
-
GL::Vertex(cube[2]);
|
75
|
-
GL::Color(color[3]);
|
76
|
-
GL::Vertex(cube[3]);
|
77
|
-
|
78
|
-
GL::Color(color[3]);
|
79
|
-
GL::Vertex(cube[3]);
|
80
|
-
GL::Color(color[4]);
|
81
|
-
GL::Vertex(cube[4]);
|
82
|
-
GL::Color(color[7]);
|
83
|
-
GL::Vertex(cube[7]);
|
84
|
-
GL::Color(color[2]);
|
85
|
-
GL::Vertex(cube[2]);
|
86
|
-
|
87
|
-
GL::Color(color[0]);
|
88
|
-
GL::Vertex(cube[0]);
|
89
|
-
GL::Color(color[5]);
|
90
|
-
GL::Vertex(cube[5]);
|
91
|
-
GL::Color(color[6]);
|
92
|
-
GL::Vertex(cube[6]);
|
93
|
-
GL::Color(color[1]);
|
94
|
-
GL::Vertex(cube[1]);
|
95
|
-
|
96
|
-
GL::Color(color[5]);
|
97
|
-
GL::Vertex(cube[5]);
|
98
|
-
GL::Color(color[4]);
|
99
|
-
GL::Vertex(cube[4]);
|
100
|
-
GL::Color(color[7]);
|
101
|
-
GL::Vertex(cube[7]);
|
102
|
-
GL::Color(color[6]);
|
103
|
-
GL::Vertex(cube[6]);
|
104
|
-
|
105
|
-
GL::Color(color[5]);
|
106
|
-
GL::Vertex(cube[5]);
|
107
|
-
GL::Color(color[0]);
|
108
|
-
GL::Vertex(cube[0]);
|
109
|
-
GL::Color(color[3]);
|
110
|
-
GL::Vertex(cube[3]);
|
111
|
-
GL::Color(color[4]);
|
112
|
-
GL::Vertex(cube[4]);
|
113
|
-
|
114
|
-
GL::Color(color[6]);
|
115
|
-
GL::Vertex(cube[6]);
|
116
|
-
GL::Color(color[1]);
|
117
|
-
GL::Vertex(cube[1]);
|
118
|
-
GL::Color(color[2]);
|
119
|
-
GL::Vertex(cube[2]);
|
120
|
-
GL::Color(color[7]);
|
121
|
-
GL::Vertex(cube[7]);
|
122
|
-
|
123
|
-
else
|
124
|
-
GL::Color(1.0, 0.0, 0.0);
|
125
|
-
GL::Vertex(cube[0]);
|
126
|
-
GL::Vertex(cube[1]);
|
127
|
-
GL::Vertex(cube[2]);
|
128
|
-
GL::Vertex(cube[3]);
|
129
|
-
|
130
|
-
GL::Color(0.0, 1.0, 0.0);
|
131
|
-
GL::Vertex(cube[3]);
|
132
|
-
GL::Vertex(cube[4]);
|
133
|
-
GL::Vertex(cube[7]);
|
134
|
-
GL::Vertex(cube[2]);
|
135
|
-
|
136
|
-
GL::Color(0.0, 0.0, 1.0);
|
137
|
-
GL::Vertex(cube[0]);
|
138
|
-
GL::Vertex(cube[5]);
|
139
|
-
GL::Vertex(cube[6]);
|
140
|
-
GL::Vertex(cube[1]);
|
141
|
-
|
142
|
-
GL::Color(0.0, 1.0, 1.0);
|
143
|
-
GL::Vertex(cube[5]);
|
144
|
-
GL::Vertex(cube[4]);
|
145
|
-
GL::Vertex(cube[7]);
|
146
|
-
GL::Vertex(cube[6]);
|
147
|
-
|
148
|
-
GL::Color(1.0, 1.0, 0.0);
|
149
|
-
GL::Vertex(cube[5]);
|
150
|
-
GL::Vertex(cube[0]);
|
151
|
-
GL::Vertex(cube[3]);
|
152
|
-
GL::Vertex(cube[4]);
|
153
|
-
|
154
|
-
GL::Color(1.0, 0.0, 1.0);
|
155
|
-
GL::Vertex(cube[6]);
|
156
|
-
GL::Vertex(cube[1]);
|
157
|
-
GL::Vertex(cube[2]);
|
158
|
-
GL::Vertex(cube[7]);
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
GL::End()
|
163
|
-
|
164
|
-
GL::MatrixMode(GL::MODELVIEW);
|
165
|
-
GL::Rotate(5.0, 1.0, 1.0, 1.0);
|
166
|
-
|
167
|
-
SDL.GLSwapBuffers
|
168
|
-
|
169
|
-
end
|
1
|
+
# You can use this test program to run Ruby/SDL, Ruby/OpenGL themselves.
|
2
|
+
# I created sgl by extending this small program.
|
3
|
+
|
4
|
+
require 'sdl'
|
5
|
+
require 'opengl'
|
6
|
+
|
7
|
+
SDL.init SDL::INIT_VIDEO
|
8
|
+
SDL.setGLAttr SDL::GL_RED_SIZE,5
|
9
|
+
SDL.setGLAttr SDL::GL_GREEN_SIZE,5
|
10
|
+
SDL.setGLAttr SDL::GL_BLUE_SIZE,5
|
11
|
+
SDL.setGLAttr SDL::GL_DEPTH_SIZE,16
|
12
|
+
SDL.setGLAttr SDL::GL_DOUBLEBUFFER,1
|
13
|
+
SDL.setVideoMode 640,400,16,SDL::OPENGL
|
14
|
+
GL::Viewport( 0, 0, 640, 400 );
|
15
|
+
GL::MatrixMode( GL::PROJECTION );
|
16
|
+
GL::LoadIdentity( );
|
17
|
+
|
18
|
+
GL::MatrixMode( GL::MODELVIEW );
|
19
|
+
GL::LoadIdentity( );
|
20
|
+
|
21
|
+
GL::Enable(GL::DEPTH_TEST);
|
22
|
+
|
23
|
+
GL::DepthFunc(GL::LESS);
|
24
|
+
|
25
|
+
GL::ShadeModel(GL::SMOOTH);
|
26
|
+
|
27
|
+
event=SDL::Event.new
|
28
|
+
shadedCube=true
|
29
|
+
|
30
|
+
color =
|
31
|
+
[[ 1.0, 1.0, 0.0],
|
32
|
+
[ 1.0, 0.0, 0.0],
|
33
|
+
[ 0.0, 0.0, 0.0],
|
34
|
+
[ 0.0, 1.0, 0.0],
|
35
|
+
[ 0.0, 1.0, 1.0],
|
36
|
+
[ 1.0, 1.0, 1.0],
|
37
|
+
[ 1.0, 0.0, 1.0],
|
38
|
+
[ 0.0, 0.0, 1.0]]
|
39
|
+
|
40
|
+
cube =
|
41
|
+
[[ 0.5, 0.5, -0.5],
|
42
|
+
[ 0.5, -0.5, -0.5],
|
43
|
+
[-0.5, -0.5, -0.5],
|
44
|
+
[-0.5, 0.5, -0.5],
|
45
|
+
[-0.5, 0.5, 0.5],
|
46
|
+
[ 0.5, 0.5, 0.5],
|
47
|
+
[ 0.5, -0.5, 0.5],
|
48
|
+
[-0.5, -0.5, 0.5]]
|
49
|
+
|
50
|
+
|
51
|
+
loop do
|
52
|
+
|
53
|
+
if event.poll != 0 then
|
54
|
+
if event.type==SDL::Event::QUIT then
|
55
|
+
break
|
56
|
+
end
|
57
|
+
if event.type==SDL::Event::KEYDOWN then
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
GL.ClearColor(0.0, 0.0, 0.0, 1.0);
|
63
|
+
GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
|
64
|
+
|
65
|
+
|
66
|
+
GL::Begin(GL::QUADS)
|
67
|
+
|
68
|
+
if shadedCube then
|
69
|
+
GL::Color(color[0]);
|
70
|
+
GL::Vertex(cube[0]);
|
71
|
+
GL::Color(color[1]);
|
72
|
+
GL::Vertex(cube[1]);
|
73
|
+
GL::Color(color[2]);
|
74
|
+
GL::Vertex(cube[2]);
|
75
|
+
GL::Color(color[3]);
|
76
|
+
GL::Vertex(cube[3]);
|
77
|
+
|
78
|
+
GL::Color(color[3]);
|
79
|
+
GL::Vertex(cube[3]);
|
80
|
+
GL::Color(color[4]);
|
81
|
+
GL::Vertex(cube[4]);
|
82
|
+
GL::Color(color[7]);
|
83
|
+
GL::Vertex(cube[7]);
|
84
|
+
GL::Color(color[2]);
|
85
|
+
GL::Vertex(cube[2]);
|
86
|
+
|
87
|
+
GL::Color(color[0]);
|
88
|
+
GL::Vertex(cube[0]);
|
89
|
+
GL::Color(color[5]);
|
90
|
+
GL::Vertex(cube[5]);
|
91
|
+
GL::Color(color[6]);
|
92
|
+
GL::Vertex(cube[6]);
|
93
|
+
GL::Color(color[1]);
|
94
|
+
GL::Vertex(cube[1]);
|
95
|
+
|
96
|
+
GL::Color(color[5]);
|
97
|
+
GL::Vertex(cube[5]);
|
98
|
+
GL::Color(color[4]);
|
99
|
+
GL::Vertex(cube[4]);
|
100
|
+
GL::Color(color[7]);
|
101
|
+
GL::Vertex(cube[7]);
|
102
|
+
GL::Color(color[6]);
|
103
|
+
GL::Vertex(cube[6]);
|
104
|
+
|
105
|
+
GL::Color(color[5]);
|
106
|
+
GL::Vertex(cube[5]);
|
107
|
+
GL::Color(color[0]);
|
108
|
+
GL::Vertex(cube[0]);
|
109
|
+
GL::Color(color[3]);
|
110
|
+
GL::Vertex(cube[3]);
|
111
|
+
GL::Color(color[4]);
|
112
|
+
GL::Vertex(cube[4]);
|
113
|
+
|
114
|
+
GL::Color(color[6]);
|
115
|
+
GL::Vertex(cube[6]);
|
116
|
+
GL::Color(color[1]);
|
117
|
+
GL::Vertex(cube[1]);
|
118
|
+
GL::Color(color[2]);
|
119
|
+
GL::Vertex(cube[2]);
|
120
|
+
GL::Color(color[7]);
|
121
|
+
GL::Vertex(cube[7]);
|
122
|
+
|
123
|
+
else
|
124
|
+
GL::Color(1.0, 0.0, 0.0);
|
125
|
+
GL::Vertex(cube[0]);
|
126
|
+
GL::Vertex(cube[1]);
|
127
|
+
GL::Vertex(cube[2]);
|
128
|
+
GL::Vertex(cube[3]);
|
129
|
+
|
130
|
+
GL::Color(0.0, 1.0, 0.0);
|
131
|
+
GL::Vertex(cube[3]);
|
132
|
+
GL::Vertex(cube[4]);
|
133
|
+
GL::Vertex(cube[7]);
|
134
|
+
GL::Vertex(cube[2]);
|
135
|
+
|
136
|
+
GL::Color(0.0, 0.0, 1.0);
|
137
|
+
GL::Vertex(cube[0]);
|
138
|
+
GL::Vertex(cube[5]);
|
139
|
+
GL::Vertex(cube[6]);
|
140
|
+
GL::Vertex(cube[1]);
|
141
|
+
|
142
|
+
GL::Color(0.0, 1.0, 1.0);
|
143
|
+
GL::Vertex(cube[5]);
|
144
|
+
GL::Vertex(cube[4]);
|
145
|
+
GL::Vertex(cube[7]);
|
146
|
+
GL::Vertex(cube[6]);
|
147
|
+
|
148
|
+
GL::Color(1.0, 1.0, 0.0);
|
149
|
+
GL::Vertex(cube[5]);
|
150
|
+
GL::Vertex(cube[0]);
|
151
|
+
GL::Vertex(cube[3]);
|
152
|
+
GL::Vertex(cube[4]);
|
153
|
+
|
154
|
+
GL::Color(1.0, 0.0, 1.0);
|
155
|
+
GL::Vertex(cube[6]);
|
156
|
+
GL::Vertex(cube[1]);
|
157
|
+
GL::Vertex(cube[2]);
|
158
|
+
GL::Vertex(cube[7]);
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
GL::End()
|
163
|
+
|
164
|
+
GL::MatrixMode(GL::MODELVIEW);
|
165
|
+
GL::Rotate(5.0, 1.0, 1.0, 1.0);
|
166
|
+
|
167
|
+
SDL.GLSwapBuffers
|
168
|
+
|
169
|
+
end
|