danabr75-ashton 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +0 -0
- data/LICENSE +21 -0
- data/README.md +95 -0
- data/Rakefile +42 -0
- data/examples/bloom_example.rb +59 -0
- data/examples/lighting_example.rb +127 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/SmallStar.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/examples/media/Starfighter.png +0 -0
- data/examples/media/simple.png +0 -0
- data/examples/noise_example.rb +94 -0
- data/examples/outline_example.rb +86 -0
- data/examples/particle_emitter_example.rb +114 -0
- data/examples/pixelate_example.rb +52 -0
- data/examples/pixelated_texture_example.rb +69 -0
- data/examples/radial_blur_example.rb +61 -0
- data/examples/shader_image_example.rb +75 -0
- data/examples/shockwave_example.rb +75 -0
- data/examples/stencil_shader_example.rb +104 -0
- data/examples/texture_render_example.rb +54 -0
- data/examples/tv_screen_and_static_example.rb +60 -0
- data/ext/ashton/GLee.c +18170 -0
- data/ext/ashton/GLee.h +17648 -0
- data/ext/ashton/ashton.c +42 -0
- data/ext/ashton/ashton.h +31 -0
- data/ext/ashton/color.c +45 -0
- data/ext/ashton/color.h +25 -0
- data/ext/ashton/common.h +41 -0
- data/ext/ashton/extconf.rb +45 -0
- data/ext/ashton/fast_math.c +30 -0
- data/ext/ashton/fast_math.h +30 -0
- data/ext/ashton/font.c +8 -0
- data/ext/ashton/font.h +16 -0
- data/ext/ashton/gosu.c +18 -0
- data/ext/ashton/gosu.h +19 -0
- data/ext/ashton/image.c +8 -0
- data/ext/ashton/image.h +16 -0
- data/ext/ashton/particle_emitter.c +788 -0
- data/ext/ashton/particle_emitter.h +171 -0
- data/ext/ashton/pixel_cache.c +237 -0
- data/ext/ashton/pixel_cache.h +58 -0
- data/ext/ashton/shader.c +9 -0
- data/ext/ashton/shader.h +16 -0
- data/ext/ashton/texture.c +442 -0
- data/ext/ashton/texture.h +63 -0
- data/ext/ashton/vendor/gl/include/GL/GL.H +1526 -0
- data/ext/ashton/window.c +8 -0
- data/ext/ashton/window.h +16 -0
- data/lib/ashton.rb +38 -0
- data/lib/ashton/gosu_ext/color.rb +25 -0
- data/lib/ashton/gosu_ext/font.rb +58 -0
- data/lib/ashton/gosu_ext/gosu_module.rb +16 -0
- data/lib/ashton/gosu_ext/image.rb +96 -0
- data/lib/ashton/gosu_ext/window.rb +79 -0
- data/lib/ashton/image_stub.rb +33 -0
- data/lib/ashton/lighting/light_source.rb +146 -0
- data/lib/ashton/lighting/manager.rb +98 -0
- data/lib/ashton/mixins/version_checking.rb +23 -0
- data/lib/ashton/particle_emitter.rb +87 -0
- data/lib/ashton/pixel_cache.rb +24 -0
- data/lib/ashton/shader.rb +386 -0
- data/lib/ashton/shaders/bloom.frag +41 -0
- data/lib/ashton/shaders/color_inversion.frag +11 -0
- data/lib/ashton/shaders/contrast.frag +16 -0
- data/lib/ashton/shaders/default.frag +22 -0
- data/lib/ashton/shaders/default.vert +14 -0
- data/lib/ashton/shaders/fade.frag +14 -0
- data/lib/ashton/shaders/grayscale.frag +15 -0
- data/lib/ashton/shaders/include/classicnoise2d.glsl +113 -0
- data/lib/ashton/shaders/include/classicnoise3d.glsl +177 -0
- data/lib/ashton/shaders/include/classicnoise4d.glsl +302 -0
- data/lib/ashton/shaders/include/noise2d.glsl +70 -0
- data/lib/ashton/shaders/include/noise3d.glsl +102 -0
- data/lib/ashton/shaders/include/noise4d.glsl +128 -0
- data/lib/ashton/shaders/include/rand.glsl +5 -0
- data/lib/ashton/shaders/lighting/distort.frag +57 -0
- data/lib/ashton/shaders/lighting/draw_shadows.frag +60 -0
- data/lib/ashton/shaders/lighting/shadow_blur.frag +60 -0
- data/lib/ashton/shaders/mezzotint.frag +22 -0
- data/lib/ashton/shaders/multitexture2.vert +19 -0
- data/lib/ashton/shaders/outline.frag +45 -0
- data/lib/ashton/shaders/pixelate.frag +48 -0
- data/lib/ashton/shaders/radial_blur.frag +63 -0
- data/lib/ashton/shaders/sepia.frag +26 -0
- data/lib/ashton/shaders/shockwave.frag +38 -0
- data/lib/ashton/shaders/signed_distance_field.frag +80 -0
- data/lib/ashton/shaders/static.frag +25 -0
- data/lib/ashton/shaders/stencil.frag +27 -0
- data/lib/ashton/shaders/tv_screen.frag +23 -0
- data/lib/ashton/signed_distance_field.rb +151 -0
- data/lib/ashton/texture.rb +186 -0
- data/lib/ashton/version.rb +3 -0
- data/lib/ashton/window_buffer.rb +16 -0
- data/spec/ashton/ashton_spec.rb +22 -0
- data/spec/ashton/gosu_ext/color_spec.rb +34 -0
- data/spec/ashton/gosu_ext/font_spec.rb +57 -0
- data/spec/ashton/gosu_ext/gosu_spec.rb +11 -0
- data/spec/ashton/gosu_ext/image_spec.rb +66 -0
- data/spec/ashton/gosu_ext/window_spec.rb +71 -0
- data/spec/ashton/image_stub_spec.rb +46 -0
- data/spec/ashton/particle_emitter_spec.rb +123 -0
- data/spec/ashton/pixel_cache_spec.rb +153 -0
- data/spec/ashton/shader_spec.rb +152 -0
- data/spec/ashton/signed_distance_field_spec.rb +163 -0
- data/spec/ashton/texture_spec.rb +347 -0
- data/spec/helper.rb +12 -0
- metadata +309 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
require_relative "../helper.rb"
|
2
|
+
|
3
|
+
|
4
|
+
describe Ashton::SignedDistanceField do
|
5
|
+
before :all do
|
6
|
+
Gosu::enable_undocumented_retrofication
|
7
|
+
|
8
|
+
$window ||= Gosu::Window.new 16, 16, false
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:max_distance) { 3 }
|
12
|
+
let(:width) { 9 }
|
13
|
+
let(:height) { 10 }
|
14
|
+
|
15
|
+
let(:subject) do
|
16
|
+
described_class.new width, height, max_distance do
|
17
|
+
# ---------
|
18
|
+
# -XXX-----
|
19
|
+
# -XXXX----
|
20
|
+
# -XXXX----
|
21
|
+
# ---------
|
22
|
+
# ---------
|
23
|
+
# ---------
|
24
|
+
# ---------
|
25
|
+
# ---------
|
26
|
+
# ---------
|
27
|
+
$window.pixel.draw 1, 1, 0, 3, 3
|
28
|
+
$window.pixel.draw 4, 2, 0, 1, 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "initialize" do
|
33
|
+
it "should accept a block and yield itself" do
|
34
|
+
yielded = nil
|
35
|
+
field = described_class.new width, height, max_distance do |value|
|
36
|
+
yielded = value
|
37
|
+
end
|
38
|
+
|
39
|
+
yielded.should eq field
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should initialize itself to max_distance if not given a block" do
|
43
|
+
field = described_class.new width, height, max_distance
|
44
|
+
field.to_a.flatten.uniq.should eq [max_distance]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "width" do
|
49
|
+
it "should give the width" do
|
50
|
+
subject.width.should eq width
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "height" do
|
55
|
+
it "should give the height" do
|
56
|
+
subject.height.should eq height
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "position_clear?" do
|
61
|
+
it "should be true if there is room" do
|
62
|
+
subject.position_clear?(8, 4, 2).should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be false if there is no room" do
|
66
|
+
subject.position_clear?(8, 4, 4).should be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be false inside a solid" do
|
70
|
+
subject.position_clear?(2, 2, 1).should be_false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "sample_distance" do
|
75
|
+
it "should give the appropriate distance" do
|
76
|
+
subject.sample_distance(1, 0).should eq 1
|
77
|
+
subject.sample_distance(7, 4).should eq 3
|
78
|
+
subject.sample_distance(1, 1).should eq 0
|
79
|
+
subject.sample_distance(2, 2).should eq -1
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should max out at the specified limit" do
|
83
|
+
subject.sample_distance(8, 9).should eq max_distance
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "line_of_sight?" do
|
88
|
+
it "should be false if the sight line is blocked" do
|
89
|
+
subject.line_of_sight?(2, 0, 2, 9).should be_false
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should be true if the sight line is uninterrupted" do
|
93
|
+
subject.line_of_sight?(0, 0, 0, 9).should be_true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "line_of_sight_blocked_at" do
|
98
|
+
it "should be false if the sight line is blocked" do
|
99
|
+
subject.line_of_sight_blocked_at(2, 0, 2, 9).should eq [2, 1]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be nil if the sight line is uninterrupted" do
|
103
|
+
subject.line_of_sight_blocked_at(0, 0, 0, 9).should be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "sample_gradient" do
|
108
|
+
it "should give expected values" do
|
109
|
+
subject.sample_gradient(1, 0).should eq [0, -1]
|
110
|
+
subject.sample_gradient(0, 1).should eq [-1, 0]
|
111
|
+
|
112
|
+
subject.sample_gradient(5, 3).should eq [2, 0]
|
113
|
+
subject.sample_gradient(1, 4).should eq [0, 2]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "sample_normal" do
|
118
|
+
it "should give expected values" do
|
119
|
+
subject.sample_normal(1, 0).should eq [0.0, -1.0]
|
120
|
+
subject.sample_normal(0, 1).should eq [-1.0, 0.0]
|
121
|
+
|
122
|
+
subject.sample_normal(5, 3).should eq [1.0, 0.0]
|
123
|
+
subject.sample_normal(1, 4).should eq [0.0, 1.0]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "render_field" do
|
128
|
+
it "should yield the field" do
|
129
|
+
field = nil
|
130
|
+
subject.render_field do |value|
|
131
|
+
field = value
|
132
|
+
end
|
133
|
+
field.should eq subject
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should fail without a block" do
|
137
|
+
->{ subject.render_field }.should raise_error ArgumentError
|
138
|
+
end
|
139
|
+
|
140
|
+
pending
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "draw" do
|
144
|
+
pending
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "to_a" do
|
148
|
+
it "should generate the expected array" do
|
149
|
+
# Remember this is rotated so array[x][y] works.
|
150
|
+
subject.to_a.should eq [
|
151
|
+
[1, 1, 1, 1, 1, 2, 3, 3, 3, 3],
|
152
|
+
[1, 0, 0, 0, 1, 2, 3, 3, 3, 3],
|
153
|
+
[1, 0, -1, 0, 1, 2, 3, 3, 3, 3],
|
154
|
+
[1, 0, 0, 0, 1, 2, 3, 3, 3, 3],
|
155
|
+
[1, 1, 0, 0, 1, 2, 3, 3, 3, 3],
|
156
|
+
[2, 1, 1, 1, 1, 2, 3, 3, 3, 3],
|
157
|
+
[3, 2, 2, 2, 2, 3, 3, 3, 3, 3],
|
158
|
+
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
|
159
|
+
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
|
160
|
+
]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,347 @@
|
|
1
|
+
require_relative "../helper.rb"
|
2
|
+
|
3
|
+
describe Ashton::Texture do
|
4
|
+
before :each do
|
5
|
+
$window = Gosu::Window.new 16, 16, false # Horrible, but otherwise we can't flush out "wrong" params properly.
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:testcard_image) { Gosu::Image.new $window, media_path("simple.png") }
|
9
|
+
let(:subject) { described_class.new testcard_image }
|
10
|
+
|
11
|
+
describe "initialize" do
|
12
|
+
it "should fail with too few arguments" do
|
13
|
+
->{ described_class.new }.should raise_error ArgumentError, /Expected 1, 2 or 3 parameters./
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should fail with too many arguments" do
|
17
|
+
->{ described_class.new 1, 2, 3, 4 }.should raise_error ArgumentError, /Expected 1, 2 or 3 parameters./
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should fail if the texture size is too large" do
|
21
|
+
->{ described_class.new 100000, 100000 }.should raise_error ArgumentError, /Unable to create a texture of size 100000x100000/
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "creating blank image (1 parameter)" do
|
25
|
+
let(:subject) { described_class.new 10, 12 }
|
26
|
+
|
27
|
+
it "should be of the expected size" do
|
28
|
+
subject.width.should eq 10
|
29
|
+
subject.height.should eq 12
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be totally blank" do
|
33
|
+
color = Gosu::Color.rgba 0, 0, 0, 0
|
34
|
+
10.times do |x|
|
35
|
+
12.times do |y|
|
36
|
+
subject[x, y].should eq color
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "creating from Gosu::Image (2 parameters)" do
|
43
|
+
let(:image) { testcard_image }
|
44
|
+
let(:subject) { described_class.new image }
|
45
|
+
|
46
|
+
it "should be of the expected size" do
|
47
|
+
subject.width.should eq image.width
|
48
|
+
subject.height.should eq image.height
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be an identical copy of the image" do
|
52
|
+
subject.to_blob.should eq image.to_blob
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "creating from blob (3 parameters)" do
|
57
|
+
let(:image) { testcard_image }
|
58
|
+
let(:subject) { described_class.new image.to_blob, image.width, image.height }
|
59
|
+
|
60
|
+
it "should fail if the width/height are not the expected size" do
|
61
|
+
->{ described_class.new image.to_blob, image.width, image.height + 1 }.should raise_error ArgumentError, /Blob data is not of expected size/
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be of the expected size" do
|
65
|
+
subject.width.should eq image.width
|
66
|
+
subject.height.should eq image.height
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be filled with the blob data" do
|
70
|
+
subject.to_blob.should eq image.to_blob
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "id" do
|
76
|
+
it "should be a positive number" do
|
77
|
+
subject.id.should be_kind_of Integer
|
78
|
+
subject.id.should > 0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "fbo_id" do
|
83
|
+
it "should be a positive number" do
|
84
|
+
subject.fbo_id.should be_kind_of Integer
|
85
|
+
subject.fbo_id.should > 0
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "cache" do
|
90
|
+
it "should be a PixelCache" do
|
91
|
+
subject.cache.should be_kind_of Ashton::PixelCache
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be of the right size" do
|
95
|
+
subject.cache.width.should eq testcard_image.width
|
96
|
+
subject.cache.height.should eq testcard_image.height
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should consider the Texture its owner" do
|
100
|
+
subject.cache.owner.should eq subject
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "refresh_cache" do
|
105
|
+
it "should be defined" do
|
106
|
+
subject.should respond_to :refresh_cache
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "[]" do
|
111
|
+
it "should return the color of the pixel" do
|
112
|
+
subject[0, 0].should eq Gosu::Color::WHITE
|
113
|
+
subject[0, 1].should eq Gosu::Color::RED
|
114
|
+
subject[0, 2].should eq Gosu::Color::GREEN
|
115
|
+
subject[0, 3].should eq Gosu::Color::BLUE
|
116
|
+
subject[0, 4].should eq Gosu::Color.rgba(255, 255, 255, 153)
|
117
|
+
subject[0, 8].should eq Gosu::Color.rgba(0, 0, 0, 0)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return a null colour outside the texture" do
|
121
|
+
subject[0, -1].should eq Gosu::Color.new 0
|
122
|
+
subject[-1, 0].should eq Gosu::Color.new 0
|
123
|
+
subject[16, 0].should eq Gosu::Color.new 0
|
124
|
+
subject[0, 12].should eq Gosu::Color.new 0
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "rgba" do
|
129
|
+
it "should return the appropriate array of values" do
|
130
|
+
subject.rgba(0, 0).should eq [255, 255, 255, 255]
|
131
|
+
subject.rgba(0, 1).should eq [255, 0, 0, 255]
|
132
|
+
subject.rgba(0, 2).should eq [0, 255, 0, 255]
|
133
|
+
subject.rgba(0, 3).should eq [0, 0, 255, 255]
|
134
|
+
subject.rgba(0, 4).should eq [255, 255, 255, 153]
|
135
|
+
subject.rgba(0, 8).should eq [0, 0, 0, 0]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "red" do
|
140
|
+
it "should return the appropriate value" do
|
141
|
+
subject.red(0, 0).should eq 255
|
142
|
+
subject.red(0, 1).should eq 255
|
143
|
+
subject.red(0, 2).should eq 0
|
144
|
+
subject.red(0, 3).should eq 0
|
145
|
+
subject.red(0, 8).should eq 0
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "green" do
|
150
|
+
it "should return the appropriate value" do
|
151
|
+
subject.green(0, 0).should eq 255
|
152
|
+
subject.green(0, 1).should eq 0
|
153
|
+
subject.green(0, 2).should eq 255
|
154
|
+
subject.green(0, 3).should eq 0
|
155
|
+
subject.green(0, 8).should eq 0
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "blue" do
|
160
|
+
it "should return the appropriate value" do
|
161
|
+
subject.blue(0, 0).should eq 255
|
162
|
+
subject.blue(0, 1).should eq 0
|
163
|
+
subject.blue(0, 2).should eq 0
|
164
|
+
subject.blue(0, 3).should eq 255
|
165
|
+
subject.blue(0, 8).should eq 0
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "alpha" do
|
170
|
+
it "should return the appropriate value" do
|
171
|
+
subject.alpha(0, 0).should eq 255
|
172
|
+
subject.alpha(0, 1).should eq 255
|
173
|
+
subject.alpha(0, 2).should eq 255
|
174
|
+
subject.alpha(0, 3).should eq 255
|
175
|
+
subject.alpha(0, 8).should eq 0
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "transparent?" do
|
180
|
+
it "should be false where the buffer is opaque or semi-transparent" do
|
181
|
+
subject.transparent?(0, 1).should be_false
|
182
|
+
subject.transparent?(0, 5).should be_false
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should be true where the buffer is transparent" do
|
186
|
+
subject.transparent?(0, 8).should be_true
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "width" do
|
191
|
+
it "should be initially set" do
|
192
|
+
subject.width.should eq testcard_image.width
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "height" do
|
197
|
+
it "should be initially set" do
|
198
|
+
subject.height.should eq testcard_image.height
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "render" do
|
203
|
+
it "should fail without a block" do
|
204
|
+
->{ subject.render }.should raise_error ArgumentError, /block required/i
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should fail if nested" do
|
208
|
+
->{
|
209
|
+
subject.render do
|
210
|
+
subject.render {}
|
211
|
+
end
|
212
|
+
}.should raise_error Ashton::Error, /nest rendering/i
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should pass itself into the block" do
|
216
|
+
buffer = nil
|
217
|
+
subject.render do |fb|
|
218
|
+
buffer = fb
|
219
|
+
end
|
220
|
+
|
221
|
+
buffer.should eq subject
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should be rendering in the block, but not rendering before and after it" do
|
225
|
+
subject.should_not be_rendering
|
226
|
+
subject.render do
|
227
|
+
subject.should be_rendering
|
228
|
+
end
|
229
|
+
subject.should_not be_rendering
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "clear" do
|
234
|
+
it "should clear the buffer to transparent" do
|
235
|
+
subject.clear
|
236
|
+
subject.width.times do |x|
|
237
|
+
subject.height.times do |y|
|
238
|
+
subject[x, y].should eq Gosu::Color.rgba(0, 0, 0, 0)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should clear the buffer to a specified Gosu::Color" do
|
244
|
+
subject.clear color: Gosu::Color::CYAN
|
245
|
+
subject.width.times do |x|
|
246
|
+
subject.height.times do |y|
|
247
|
+
subject[x, y].should eq Gosu::Color::CYAN
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should clear the buffer to a specified opengl color float array" do
|
253
|
+
subject.clear color: Gosu::Color::CYAN.to_opengl
|
254
|
+
subject.width.times do |x|
|
255
|
+
subject.height.times do |y|
|
256
|
+
subject[x, y].should eq Gosu::Color::CYAN
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe "draw" do
|
263
|
+
it "should be able to be drawn" do
|
264
|
+
subject.draw 1, 2, 3
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should be drawn with a specific blend mode" do
|
268
|
+
[:alpha_blend, :add, :multiply, :replace].each do |mode|
|
269
|
+
subject.draw 1, 2, 3, mode: mode
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should fail with a bad blend mode name" do
|
274
|
+
->{ subject.draw 1, 2, 3, mode: :fish }.should raise_error(ArgumentError, /Unsupported draw :mode, :fish/)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should fail with a bad blend mode type" do
|
278
|
+
->{ subject.draw 1, 2, 3, mode: 12 }.should raise_error TypeError
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should be drawn with a specific color" do
|
282
|
+
subject.draw 1, 2, 3, color: Gosu::Color::RED
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should fail with a bad color type" do
|
286
|
+
->{ subject.draw 1, 2, 3, color: 12 }.should raise_error TypeError
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should be drawn with a specific shader" do
|
290
|
+
subject.draw 1, 2, 3, shader: Ashton::Shader.new
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should fail with a bad shader type" do
|
294
|
+
->{ subject.draw 1, 2, 3, shader: 12 }.should raise_error TypeError
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should draw with a Texture passed to multitexture" do
|
298
|
+
subject.draw 1, 2, 3, multitexture: Ashton::Texture.new(10, 10)
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should fail with a bad multitexture option" do
|
302
|
+
->{ subject.draw 1, 2, 3, multitexture: :fish }.should raise_error(TypeError, /Expected :multitexture option of type Ashton::Texture/)
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should draw with pixelated on" do
|
306
|
+
subject.draw 1, 2, 3, pixelated: true
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should draw with pixelated off" do
|
310
|
+
subject.draw 1, 2, 3, pixelated: false
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
describe "to_blob" do
|
315
|
+
it "should create a blob the same as an equivalent image would" do
|
316
|
+
subject.to_blob.should eq testcard_image.to_blob
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe "to_image" do
|
321
|
+
let(:image) { subject.to_image }
|
322
|
+
|
323
|
+
it "should create a Gosu::Image" do
|
324
|
+
image.should be_kind_of Gosu::Image
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should create an image of the appropriate size" do
|
328
|
+
image.width.should eq testcard_image.width
|
329
|
+
image.height.should eq testcard_image.height
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should create an image identical to the one that was drawn into it originally" do
|
333
|
+
image.to_blob.should eq testcard_image.to_blob
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe "dup" do
|
338
|
+
it "should create a new Texture object" do
|
339
|
+
new = subject.dup.should be_kind_of described_class
|
340
|
+
new.should_not be subject
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should create an exact copy of the Texture" do
|
344
|
+
subject.dup.to_blob.should eq subject.to_blob
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|