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,186 @@
|
|
1
|
+
module Ashton
|
2
|
+
class Texture
|
3
|
+
include Mixins::VersionChecking
|
4
|
+
|
5
|
+
DEFAULT_DRAW_COLOR = Gosu::Color::WHITE
|
6
|
+
VALID_DRAW_MODES = [:alpha_blend, :add, :multiply, :replace]
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# [Boolean] Whether or not to pixelate (rather than smooth) on #draw
|
10
|
+
attr_writer :pixelated
|
11
|
+
# [Boolean] Whether or not to pixelate (rather than smooth) on #draw. Set true when Gosu::enable_undocumented_retrofication called.
|
12
|
+
def pixelated?; @pixelated end
|
13
|
+
end
|
14
|
+
self.pixelated = false
|
15
|
+
|
16
|
+
# [Boolean] Is this texture being rendered to currently?
|
17
|
+
def rendering?; @rendering end
|
18
|
+
|
19
|
+
# @overload initialize(image)
|
20
|
+
# Create a texture from a Gosu::Image
|
21
|
+
#
|
22
|
+
# @see Image#to_texture
|
23
|
+
# @param image [Gosu::Image]
|
24
|
+
#
|
25
|
+
# @overload initialize(blob, width, height)
|
26
|
+
# Create a texture from a binary blob.
|
27
|
+
#
|
28
|
+
# @param blob [String]
|
29
|
+
# @param width [Integer]
|
30
|
+
# @param height [Integer]
|
31
|
+
#
|
32
|
+
# @overload initialize(width, height)
|
33
|
+
# Create a blank (transparent) texture.
|
34
|
+
#
|
35
|
+
# @param width [Integer]
|
36
|
+
# @param height [Integer]
|
37
|
+
def initialize(*args)
|
38
|
+
case args.size
|
39
|
+
when 1
|
40
|
+
# Create from Gosu::Image
|
41
|
+
image = args[0]
|
42
|
+
raise TypeError, "Expected Gosu::Image" unless image.is_a? Gosu::Image
|
43
|
+
initialize_ image.width, image.height, nil
|
44
|
+
|
45
|
+
render do
|
46
|
+
# TODO: Ideally we'd draw the image in replacement mode, but Gosu doesn't support that.
|
47
|
+
$window.gl do
|
48
|
+
info = image.gl_tex_info
|
49
|
+
Gl.glEnable Gl::GL_TEXTURE_2D
|
50
|
+
Gl.glBindTexture Gl::GL_TEXTURE_2D, info.tex_name
|
51
|
+
Gl.glEnable Gl::GL_BLEND
|
52
|
+
Gl.glBlendFunc Gl::GL_ONE, Gl::GL_ZERO
|
53
|
+
|
54
|
+
Gl.glBegin Gl::GL_QUADS do
|
55
|
+
Gl.glTexCoord2d info.left, info.top
|
56
|
+
Gl.glVertex2d 0, height # BL
|
57
|
+
|
58
|
+
Gl.glTexCoord2d info.left, info.bottom
|
59
|
+
Gl.glVertex2d 0, 0 # TL
|
60
|
+
|
61
|
+
Gl.glTexCoord2d info.right, info.bottom
|
62
|
+
Gl.glVertex2d width, 0 # TR
|
63
|
+
|
64
|
+
Gl.glTexCoord2d info.right, info.top
|
65
|
+
Gl.glVertex2d width, height # BR
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
when 2
|
71
|
+
# Create blank image.
|
72
|
+
width, height = *args
|
73
|
+
initialize_ width, height, nil
|
74
|
+
clear
|
75
|
+
|
76
|
+
when 3
|
77
|
+
# Create from blob - create a Gosu image first.
|
78
|
+
blob, width, height = *args
|
79
|
+
raise ArgumentError, "Blob data is not of expected size" if blob.length != width * height * 4
|
80
|
+
initialize_ width, height, blob
|
81
|
+
|
82
|
+
else
|
83
|
+
raise ArgumentError, "Expected 1, 2 or 3 parameters."
|
84
|
+
end
|
85
|
+
|
86
|
+
@rendering = false
|
87
|
+
end
|
88
|
+
|
89
|
+
public
|
90
|
+
# Clears the buffer, optionally to a specific color.
|
91
|
+
#
|
92
|
+
# @option options :color [Gosu::Color, Array<Float>] (transparent)
|
93
|
+
def clear(options = {})
|
94
|
+
options = {
|
95
|
+
color: [0.0, 0.0, 0.0, 0.0],
|
96
|
+
}.merge! options
|
97
|
+
|
98
|
+
color = options[:color]
|
99
|
+
color = color.to_opengl if color.is_a? Gosu::Color
|
100
|
+
|
101
|
+
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
|
102
|
+
|
103
|
+
Gl.glDisable Gl::GL_BLEND # Need to replace the alpha too.
|
104
|
+
Gl.glClearColor(*color)
|
105
|
+
Gl.glClear Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT
|
106
|
+
Gl.glEnable Gl::GL_BLEND
|
107
|
+
|
108
|
+
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, 0 unless rendering?
|
109
|
+
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
113
|
+
public
|
114
|
+
# Enable the texture to use (e.g. to draw or convert it).
|
115
|
+
def render
|
116
|
+
raise ArgumentError, "Block required" unless block_given?
|
117
|
+
raise Error, "Can't nest rendering" if rendering?
|
118
|
+
|
119
|
+
$window.flush # Ensure that any drawing _before_ the render block is drawn to screen, rather than into the buffer.
|
120
|
+
|
121
|
+
render_
|
122
|
+
|
123
|
+
@rendering = true
|
124
|
+
|
125
|
+
# Project onto the texture itself, using Gosu (inverted) coordinates.
|
126
|
+
Gl.glPushMatrix
|
127
|
+
Gl.glMatrixMode Gl::GL_PROJECTION
|
128
|
+
Gl.glLoadIdentity
|
129
|
+
Gl.glViewport 0, 0, width, height
|
130
|
+
Gl.glOrtho 0, width, height, 0, -1, 1
|
131
|
+
|
132
|
+
begin
|
133
|
+
yield self
|
134
|
+
ensure
|
135
|
+
$window.flush # Force all the drawing to draw now!
|
136
|
+
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, 0
|
137
|
+
|
138
|
+
@rendering = false
|
139
|
+
|
140
|
+
Gl.glPopMatrix
|
141
|
+
|
142
|
+
cache.refresh # Force lazy reloading of the cache.
|
143
|
+
end
|
144
|
+
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
148
|
+
# @!method draw(x, y, z, options = {})
|
149
|
+
# Draw the Texture.
|
150
|
+
#
|
151
|
+
# This is not as versatile as converting the Texture into a Gosu::Image and then
|
152
|
+
# drawing it, but it is many times faster, so use it when you are updating the buffer
|
153
|
+
# every frame, rather than just composing an image.
|
154
|
+
#
|
155
|
+
# Drawing in Gosu orientation will be flipped in standard OpenGL and visa versa.
|
156
|
+
#
|
157
|
+
# @param x [Number] Top left corner x.
|
158
|
+
# @param y [Number] Top left corner y.
|
159
|
+
# @param z [Number] Z-order (can be nil to draw immediately)
|
160
|
+
#
|
161
|
+
# @option options :shader [Ashton::Shader] Shader to apply to drawing.
|
162
|
+
# @option options :color [Gosu::Color] (Gosu::Color::WHITE) Color to apply to the drawing.
|
163
|
+
# @option options :mode [Symbol] (:alpha_blend) :alpha_blend, :add, :multiply, :replace
|
164
|
+
# @option options :multitexture [Texture] A texture to be used in a multi-texturing shader.
|
165
|
+
# @option options :pixelated [Boolean] (true if Gosu::enable_undocumented_retrofication ever called) Pixelate, rather than smooth, when zoomed out.
|
166
|
+
|
167
|
+
public
|
168
|
+
# Convert the current contents of the buffer into a Gosu::Image
|
169
|
+
#
|
170
|
+
# @option options :caching [Boolean] (true) TexPlay behaviour.
|
171
|
+
# @option options :tileable [Boolean] (false) Standard Gosu behaviour.
|
172
|
+
# @option options :rect [Array<Integer>] ([0, 0, width, height]) Rectangular area of buffer to use to create the image [x, y, w, h]
|
173
|
+
def to_image(*args)
|
174
|
+
cache.to_image(*args)
|
175
|
+
end
|
176
|
+
|
177
|
+
def dup
|
178
|
+
# Create a new texture and draw self into it.
|
179
|
+
new_texture = Texture.new width, height
|
180
|
+
new_texture.render do
|
181
|
+
draw 0, 0, 0, mode: :replace
|
182
|
+
end
|
183
|
+
new_texture
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Ashton
|
2
|
+
# A texture that is the same size as the Gosu::Window.
|
3
|
+
class WindowBuffer < Texture
|
4
|
+
def initialize
|
5
|
+
super $window.width, $window.height
|
6
|
+
end
|
7
|
+
|
8
|
+
public
|
9
|
+
# Copy the window contents into the buffer.
|
10
|
+
def capture
|
11
|
+
Gl.glBindTexture Gl::GL_TEXTURE_2D, id
|
12
|
+
Gl.glCopyTexImage2D Gl::GL_TEXTURE_2D, 0, Gl::GL_RGBA8, 0, 0, width, height, 0
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
require_relative "../helper.rb"
|
3
|
+
|
4
|
+
describe Ashton do
|
5
|
+
let(:accuracy) { 0.000001 }
|
6
|
+
|
7
|
+
describe "fast_sin" do
|
8
|
+
it "should give the same result as Math.sin" do
|
9
|
+
(-360..360).step 90 do |angle|
|
10
|
+
Ashton.fast_sin(angle).should be_within(accuracy).of Math.sin(angle.gosu_to_radians)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "fast_cos" do
|
16
|
+
it "should give the same result as Math.cos" do
|
17
|
+
(-360..360).step 90 do |angle|
|
18
|
+
Ashton.fast_cos(angle).should be_within(accuracy).of Math.cos(angle.gosu_to_radians)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "../../helper.rb"
|
2
|
+
|
3
|
+
describe Gosu::Color do
|
4
|
+
let :conversions do
|
5
|
+
[
|
6
|
+
[Gosu::Color::RED, [1.0, 0.0, 0.0, 1.0]],
|
7
|
+
[Gosu::Color::GREEN, [0.0, 1.0, 0.0, 1.0]],
|
8
|
+
[Gosu::Color::BLUE, [0.0, 0.0, 1.0, 1.0]],
|
9
|
+
[Gosu::Color.rgba(25, 50, 75, 125), [0.09803921568627451, 0.19607843137254902, 0.29411764705882354, 0.49019607843137253]],
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "to_opengl" do
|
14
|
+
it "should convert from Color to float array" do
|
15
|
+
conversions.each do |gosu, opengl|
|
16
|
+
gosu.to_opengl.should eq opengl
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".from_opengl" do
|
22
|
+
it "should create the expected Colors from a float array" do
|
23
|
+
conversions.each do |gosu, opengl|
|
24
|
+
Gosu::Color.from_opengl(opengl).should eq gosu
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "to_i" do
|
30
|
+
it "should convert to an ARGB8 value" do
|
31
|
+
Gosu::Color.new(0x01234567).to_i.should eq 0x01234567
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative "../../helper.rb"
|
2
|
+
|
3
|
+
describe Gosu::Font do
|
4
|
+
before :each do
|
5
|
+
$window = Gosu::Window.new 16, 16, false
|
6
|
+
end
|
7
|
+
let(:subject) { described_class.new $window, Gosu::default_font_name, 20 }
|
8
|
+
let(:shader) { Ashton::Shader.new }
|
9
|
+
|
10
|
+
describe "draw" do
|
11
|
+
it "should pass parameters through normally, without a hash" do
|
12
|
+
mock(subject).draw_without_hash "bleh", 1, 2, 3, 4, 5, 6, 7
|
13
|
+
|
14
|
+
subject.draw "bleh", 1, 2, 3, 4, 5, 6, 7
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should pass parameters through normally, without :shader in the hash" do
|
18
|
+
mock(subject).draw_without_hash "bleh", 1, 2, 3, 4, 5, 6, 7
|
19
|
+
|
20
|
+
subject.draw "bleh", 1, 2, 3, 4, 5, 6, 7, shader: shader
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use the shader if supplied" do
|
24
|
+
mock(shader) do |m|
|
25
|
+
m.enable 3
|
26
|
+
m.disable 3
|
27
|
+
end
|
28
|
+
mock(subject).draw_without_hash "bleh", 1, 2, 3, 4, 5, 6, 7
|
29
|
+
|
30
|
+
subject.draw "bleh", 1, 2, 3, 4, 5, 6, 7, shader: shader
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "draw_rel" do
|
35
|
+
it "should pass parameters through normally, without a hash" do
|
36
|
+
mock(subject).draw_rel_without_hash "bleh", 1, 2, 3, 4, 5, 6, 7, 8, 9
|
37
|
+
|
38
|
+
subject.draw_rel "bleh", 1, 2, 3, 4, 5, 6, 7, 8, 9
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should pass parameters through normally, without :shader in the hash" do
|
42
|
+
mock(subject).draw_rel_without_hash "bleh", 1, 2, 3, 4, 5, 6, 7, 8, 9
|
43
|
+
|
44
|
+
subject.draw_rel "bleh", 1, 2, 3, 4, 5, 6, 7, 8, 9, shader: shader
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should use the shader if supplied" do
|
48
|
+
mock(shader) do |m|
|
49
|
+
m.enable 3
|
50
|
+
m.disable 3
|
51
|
+
end
|
52
|
+
mock(subject).draw_rel_without_hash "bleh", 1, 2, 3, 4, 5, 6, 7, 8, 9
|
53
|
+
|
54
|
+
subject.draw_rel "bleh", 1, 2, 3, 4, 5, 6, 7, 8, 9, shader: shader
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative "../../helper.rb"
|
2
|
+
|
3
|
+
describe Gosu do
|
4
|
+
describe "enable_undocumented_retrofication" do
|
5
|
+
it "should set Texture.pixelated? true" do
|
6
|
+
Ashton::Texture.should_not be_pixelated
|
7
|
+
Gosu.enable_undocumented_retrofication
|
8
|
+
Ashton::Texture.should be_pixelated
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative "../../helper.rb"
|
2
|
+
|
3
|
+
describe Gosu::Image do
|
4
|
+
before :each do
|
5
|
+
$window = Gosu::Window.new 16, 16, false
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:subject) { described_class.new $window, media_path("LargeStar.png") }
|
9
|
+
|
10
|
+
describe "draw" do
|
11
|
+
it "should pass parameters through normally, without a hash" do
|
12
|
+
mock(subject).draw_without_hash 0, 1, 2, 3, 4, 5
|
13
|
+
|
14
|
+
subject.draw 0, 1, 2, 3, 4, 5
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should pass parameters through normally, without :shader in the hash" do
|
18
|
+
mock(subject).draw_without_hash 0, 1, 2, 3, 4, 5
|
19
|
+
|
20
|
+
subject.draw 0, 1, 2, 3, 4, 5, {}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use the shader if supplied" do
|
24
|
+
mock(shader = Ashton::Shader.new) do |m|
|
25
|
+
m.enable 2
|
26
|
+
m.image = subject
|
27
|
+
m.disable 2
|
28
|
+
end
|
29
|
+
mock(subject).draw_without_hash 0, 1, 2, 3, 4, 5
|
30
|
+
|
31
|
+
subject.draw 0, 1, 2, 3, 4, 5, :shader => shader
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "draw_rot" do
|
36
|
+
it "should pass parameters through normally, without a hash" do
|
37
|
+
mock(subject).draw_rot_without_hash 0, 1, 2, 3, 4, 5, 6, 7, 8
|
38
|
+
|
39
|
+
subject.draw_rot 0, 1, 2, 3, 4, 5, 6, 7, 8
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should pass parameters through normally, without :shader in the hash" do
|
43
|
+
mock(subject).draw_rot_without_hash 0, 1, 2, 3, 4, 5, 6, 7, 8
|
44
|
+
|
45
|
+
subject.draw_rot 0, 1, 2, 3, 4, 5, 6, 7, 8, {}
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should use the shader if supplied" do
|
49
|
+
mock(shader = Ashton::Shader.new) do |m|
|
50
|
+
m.enable 2
|
51
|
+
m.image = subject
|
52
|
+
m.disable 2
|
53
|
+
end
|
54
|
+
mock(subject).draw_rot_without_hash 0, 1, 2, 3, 4, 5, 6, 7, 8
|
55
|
+
|
56
|
+
subject.draw_rot 0, 1, 2, 3, 4, 5, 6, 7, 8, :shader => shader
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "to_texture" do
|
61
|
+
it "should create a texture identical to the image" do
|
62
|
+
texture = subject.to_texture
|
63
|
+
texture.to_blob.should eq subject.to_blob
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative "../../helper.rb"
|
2
|
+
|
3
|
+
describe Gosu::Window do
|
4
|
+
before :all do
|
5
|
+
$window ||= Gosu::Window.new 16, 16, false
|
6
|
+
end
|
7
|
+
|
8
|
+
# Class methods.
|
9
|
+
|
10
|
+
describe "Window.pixel" do
|
11
|
+
it "should be a 1x1 image" do
|
12
|
+
described_class.pixel.should be_kind_of Gosu::Image
|
13
|
+
described_class.pixel.width.should eq 1
|
14
|
+
described_class.pixel.height.should eq 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be white" do
|
18
|
+
described_class.pixel[0, 0].should eq [1.0, 1.0, 1.0, 1.0]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Window.primary_buffer" do
|
23
|
+
it "should be a window sized buffer" do
|
24
|
+
described_class.primary_buffer.should be_kind_of Ashton::WindowBuffer
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Window.secondary_buffer" do
|
29
|
+
it "should be a window sized buffer" do
|
30
|
+
described_class.secondary_buffer.should be_kind_of Ashton::WindowBuffer
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not be the same as the primary buffer" do
|
34
|
+
described_class.secondary_buffer.should_not eq described_class.primary_buffer
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Instance methods
|
39
|
+
|
40
|
+
describe "post_process" do
|
41
|
+
pending
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "pixel" do
|
45
|
+
it "should be a 1x1 image" do
|
46
|
+
$window.pixel.should be_kind_of Gosu::Image
|
47
|
+
$window.pixel.width.should eq 1
|
48
|
+
$window.pixel.height.should eq 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be white" do
|
52
|
+
$window.pixel[0, 0].should eq [1.0, 1.0, 1.0, 1.0]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "primary_buffer" do
|
57
|
+
it "should be a window sized buffer" do
|
58
|
+
$window.primary_buffer.should be_kind_of Ashton::WindowBuffer
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "secondary_buffer" do
|
63
|
+
it "should be a window sized buffer" do
|
64
|
+
$window.secondary_buffer.should be_kind_of Ashton::WindowBuffer
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not be the same as the primary buffer" do
|
68
|
+
$window.secondary_buffer.should_not eq $window.primary_buffer
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|