danabr75-ashton 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,86 @@
|
|
1
|
+
# Use of GLSL shader in Gosu to post-process the entire screen.
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
|
9
|
+
require "ashton"
|
10
|
+
|
11
|
+
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
|
12
|
+
|
13
|
+
class TestWindow < Gosu::Window
|
14
|
+
def initialize
|
15
|
+
super 640, 480, false
|
16
|
+
|
17
|
+
Gosu::enable_undocumented_retrofication
|
18
|
+
|
19
|
+
self.caption = "Image, font and buffer composition drawn with 'outline' shader"
|
20
|
+
|
21
|
+
@outline = Ashton::Shader.new fragment: :outline
|
22
|
+
|
23
|
+
@font = Gosu::Font.new self, Gosu::default_font_name, 40
|
24
|
+
@ship = Gosu::Image.new(self, media_path("Starfighter.png"), true)
|
25
|
+
@background = Gosu::Image.new(self, media_path("Earth.png"), true)
|
26
|
+
|
27
|
+
@buffer = Ashton::Texture.new width, height
|
28
|
+
|
29
|
+
render_to_buffer
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
$gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
|
34
|
+
render_to_buffer
|
35
|
+
end
|
36
|
+
|
37
|
+
def render_to_buffer
|
38
|
+
# Draw together into a temp buffer, before outlining all together.
|
39
|
+
@buffer.render do |buffer|
|
40
|
+
buffer.clear
|
41
|
+
|
42
|
+
10.downto(1) do |i|
|
43
|
+
scale = i / 2.0
|
44
|
+
angle = i * 15 + Time.now.to_f * 10
|
45
|
+
|
46
|
+
@ship.draw_rot i * 25, 15 + i * 30, 0, angle, 0.5, 0.5, scale, scale
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def button_down(id)
|
52
|
+
if id == Gosu::KbEscape
|
53
|
+
close
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def draw
|
58
|
+
@background.draw 0, 0, 0, width.fdiv(@background.width), height.fdiv(@background.height)
|
59
|
+
|
60
|
+
@outline.outline_width = 2.0
|
61
|
+
@outline.outline_color = Gosu::Color::YELLOW
|
62
|
+
@buffer.draw 0, 0, 0, shader: @outline
|
63
|
+
|
64
|
+
# Draw individually, each with their own outline.
|
65
|
+
10.downto(1) do |i|
|
66
|
+
scale = i / 2.0
|
67
|
+
angle = i * 15 + Time.now.to_f * 10
|
68
|
+
|
69
|
+
@outline.outline_color = [Gosu::Color::RED, Gosu::Color::WHITE][i % 2]
|
70
|
+
|
71
|
+
# This keeps the outline of constant width on the screen,
|
72
|
+
# compared to the sprite pixels. Wouldn't keep updating this in real usage, of course.
|
73
|
+
@outline.outline_width = 0.9 / scale
|
74
|
+
|
75
|
+
@ship.draw_rot 225 + i * 25, 15 + i * 30, 0, angle, 0.5, 0.5, scale, scale, :shader => @outline
|
76
|
+
end
|
77
|
+
|
78
|
+
# Guitastic!
|
79
|
+
@outline.outline_width = 2.0
|
80
|
+
@outline.outline_color = Gosu::Color::BLACK
|
81
|
+
@font.draw "FPS:", 0, 0, 0, 1, 1, Gosu::Color::BLUE, shader: @outline
|
82
|
+
@font.draw_rel "#{Gosu::fps}", 150, 0, 0, 1, 0, 1, 1, Gosu::Color::GREEN, shader: @outline
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
TestWindow.new.show
|
@@ -0,0 +1,114 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
|
7
|
+
require "ashton"
|
8
|
+
|
9
|
+
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
|
10
|
+
|
11
|
+
class TestWindow < Gosu::Window
|
12
|
+
def initialize
|
13
|
+
super 640, 480, false
|
14
|
+
self.caption = "Particle emitters - 4 emitters at static positions and one on mouse"
|
15
|
+
|
16
|
+
@grayscale = Ashton::Shader.new fragment: :grayscale
|
17
|
+
|
18
|
+
@font = Gosu::Font.new self, Gosu::default_font_name, 24
|
19
|
+
@star = Gosu::Image.new self, media_path("SmallStar.png"), true
|
20
|
+
|
21
|
+
@image_emitter = Ashton::ParticleEmitter.new 450, 100, 0,
|
22
|
+
image: @star,
|
23
|
+
scale: 0.2,
|
24
|
+
speed: 40,
|
25
|
+
friction: 0.1,
|
26
|
+
max_particles: 30000,
|
27
|
+
interval: 0.00015,
|
28
|
+
fade: 57, # loses 25 alpha/s
|
29
|
+
angular_velocity: -50..50
|
30
|
+
|
31
|
+
@shaded_image_emitter = Ashton::ParticleEmitter.new 450, 350, 0,
|
32
|
+
image: @star,
|
33
|
+
shader: @grayscale,
|
34
|
+
interval: 0.00015,
|
35
|
+
offset: 0..10,
|
36
|
+
max_particles: 30000,
|
37
|
+
angular_velocity: 20..50,
|
38
|
+
center_x: 3..8, center_y: 3..8,
|
39
|
+
zoom: -0.22 # Shrinks, so doesn't need TTL.
|
40
|
+
|
41
|
+
@point_emitter = Ashton::ParticleEmitter.new 100, 100, 1,
|
42
|
+
scale: 10,
|
43
|
+
speed: 200,
|
44
|
+
interval: 0.0002,
|
45
|
+
max_particles: 30000,
|
46
|
+
interval: 0.0001,
|
47
|
+
color: Gosu::Color.rgba(255, 0, 0, 150),
|
48
|
+
fade: 50 # loses 50 alpha/s
|
49
|
+
|
50
|
+
@shaded_point_emitter = Ashton::ParticleEmitter.new 100, 300, 2,
|
51
|
+
scale: 4..10,
|
52
|
+
shader: @grayscale,
|
53
|
+
speed: 60..100,
|
54
|
+
offset: 0..10,
|
55
|
+
time_to_live: 12,
|
56
|
+
interval: 0.0003,
|
57
|
+
max_particles: 30000,
|
58
|
+
color: Gosu::Color.rgba(255, 0, 0, 100),
|
59
|
+
gravity: 60 # pixels/s*s
|
60
|
+
|
61
|
+
@mouse_emitter = Ashton::ParticleEmitter.new 0, 0, 3,
|
62
|
+
scale: 4,
|
63
|
+
speed: 20..50,
|
64
|
+
max_particles: 5000,
|
65
|
+
offset: 0..5,
|
66
|
+
interval: 0.0010,
|
67
|
+
color: Gosu::Color.rgba(0, 255, 255, 100),
|
68
|
+
fade: 25,
|
69
|
+
gravity: 60 # pixels/s*s
|
70
|
+
end
|
71
|
+
|
72
|
+
def needs_cursor?; true end
|
73
|
+
|
74
|
+
def update
|
75
|
+
$gosu_blocks.clear if defined? $gosu_blocks # workaround for Gosu 0.7.45 bug.
|
76
|
+
|
77
|
+
# Calculate delta from milliseconds.
|
78
|
+
@last_update_at ||= Gosu::milliseconds
|
79
|
+
delta = [Gosu::milliseconds - @last_update_at, 100].min * 0.001 # Limit delta to 100ms (10fps), in case of freezing.
|
80
|
+
@last_update_at = Gosu::milliseconds
|
81
|
+
|
82
|
+
@image_emitter.update delta unless button_down? Gosu::Kb1
|
83
|
+
@shaded_image_emitter.update delta unless button_down? Gosu::Kb2
|
84
|
+
@point_emitter.update delta unless button_down? Gosu::Kb3
|
85
|
+
@shaded_point_emitter.update delta unless button_down? Gosu::Kb4
|
86
|
+
|
87
|
+
@mouse_emitter.x, @mouse_emitter.y = mouse_x, mouse_y
|
88
|
+
@mouse_emitter.update delta unless button_down? Gosu::Kb5
|
89
|
+
end
|
90
|
+
|
91
|
+
def button_down(id)
|
92
|
+
if id == Gosu::KbEscape
|
93
|
+
close
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def draw
|
98
|
+
@point_emitter.draw
|
99
|
+
@shaded_image_emitter.draw
|
100
|
+
@shaded_point_emitter.draw
|
101
|
+
@image_emitter.draw
|
102
|
+
@mouse_emitter.draw
|
103
|
+
|
104
|
+
num_particles = @point_emitter.count + @shaded_point_emitter.count +
|
105
|
+
@image_emitter.count + @shaded_image_emitter.count +
|
106
|
+
@mouse_emitter.count
|
107
|
+
@font.draw "FPS: #{Gosu::fps} Particles: #{num_particles}", 0, 0, Float::INFINITY
|
108
|
+
|
109
|
+
totals = "Pnt: #{@point_emitter.count} ShaPnt: #{@shaded_point_emitter.count} Img: #{@image_emitter.count} ShaImg: #{@shaded_image_emitter.count} Mouse: #{@mouse_emitter.count}"
|
110
|
+
@font.draw_rel totals, 0, height, Float::INFINITY, 0, 1
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
TestWindow.new.show
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Use of GLSL shader in Gosu to post-process the entire screen.
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
|
9
|
+
require "ashton"
|
10
|
+
|
11
|
+
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
|
12
|
+
|
13
|
+
class TestWindow < Gosu::Window
|
14
|
+
def initialize
|
15
|
+
super 640, 480, false
|
16
|
+
self.caption = "Post-processing with 'pixelate' - 1..9 affect pixel size"
|
17
|
+
|
18
|
+
@pixelate = Ashton::Shader.new fragment: :pixelate, uniforms: {
|
19
|
+
pixel_size: @pixel_size = 4,
|
20
|
+
}
|
21
|
+
|
22
|
+
@font = Gosu::Font.new self, Gosu::default_font_name, 40
|
23
|
+
@star = Gosu::Image.new(self, media_path("LargeStar.png"), true)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
$gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
|
28
|
+
end
|
29
|
+
|
30
|
+
def button_down(id)
|
31
|
+
if (Gosu::Kb1..Gosu::Kb9).include? id
|
32
|
+
@pixel_size = (id - Gosu::Kb1 + 1) ** 2
|
33
|
+
@pixelate.pixel_size = @pixel_size
|
34
|
+
elsif id == Gosu::KbEscape
|
35
|
+
close
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw
|
40
|
+
post_process @pixelate do
|
41
|
+
@font.draw_rel "Hello world!", 350, 50, 0, 0.5, 0.5
|
42
|
+
@font.draw_rel "Goodbye world!", 400, 350, 0, 0.5, 0.5
|
43
|
+
@star.draw 0, 0, 0
|
44
|
+
@star.draw 200, 100, 0
|
45
|
+
end
|
46
|
+
|
47
|
+
# Drawing after the effect isn't processed, which is useful for GUI elements.
|
48
|
+
@font.draw "Pixel ratio: 1:#{@pixel_size}", 0, 0, 0
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
TestWindow.new.show
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Use of GLSL shader in Gosu.
|
2
|
+
|
3
|
+
require_relative '../lib/ashton'
|
4
|
+
|
5
|
+
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
|
6
|
+
|
7
|
+
class GameWindow < Gosu::Window
|
8
|
+
def initialize
|
9
|
+
super 800, 600, false
|
10
|
+
|
11
|
+
# Enable pixelation for all Gosu Images (must be called before creating any Images).
|
12
|
+
# Comment this line out to see default Gosu behaviour (smoothing).
|
13
|
+
Gosu.enable_undocumented_retrofication
|
14
|
+
|
15
|
+
self.caption = "Ashton::Texture pixelation example (Gosu::enable_undocumented_retrofication HAS "
|
16
|
+
self.caption += "NOT " unless Ashton::Texture.pixelated?
|
17
|
+
self.caption += "been called)"
|
18
|
+
|
19
|
+
@image = Gosu::Image.new self, media_path("Starfighter.bmp"), true
|
20
|
+
@texture = @image.to_texture
|
21
|
+
@font = Gosu::Font.new $window, Gosu::default_font_name, 15
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
$gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
|
26
|
+
end
|
27
|
+
|
28
|
+
def draw
|
29
|
+
# Drawing Textures will pixelate by default if Gosu::enable_undocumented_retrofication has ever been called.
|
30
|
+
@font.draw "Gosu::Image", 0, 0, 0
|
31
|
+
@font.draw "Ashton::Texture default", 200, 0, 0
|
32
|
+
@font.draw "Ashton::Texture pixelated: true", 400, 0, 0
|
33
|
+
@font.draw "Ashton::Texture pixelated: false", 600, 0, 0
|
34
|
+
|
35
|
+
# Zoom in a Texture, so smoothing/pixelation occurs based on preference.
|
36
|
+
scale 4 do
|
37
|
+
@image.draw 0, 10, 0
|
38
|
+
@texture.draw 50, 10, 0
|
39
|
+
@texture.draw 100, 10, 0, pixelated: true
|
40
|
+
@texture.draw 150, 10, 0, pixelated: false
|
41
|
+
end
|
42
|
+
|
43
|
+
# Actual size, so all will look the same.
|
44
|
+
@image.draw 0, 300, 0
|
45
|
+
@texture.draw 200, 300, 0
|
46
|
+
@texture.draw 400, 300, 0, pixelated: true
|
47
|
+
@texture.draw 600, 300, 0, pixelated: false
|
48
|
+
|
49
|
+
# Zooming out a Texture will _always_ smooth (with Gosu::Image it will pixelate on zooming out, which looks terrible!)
|
50
|
+
scale 0.5 do
|
51
|
+
@image.draw 0, 900, 0
|
52
|
+
@texture.draw 400, 900, 0
|
53
|
+
@texture.draw 800, 900, 0, pixelated: true
|
54
|
+
@texture.draw 1200, 900, 0, pixelated: false
|
55
|
+
end
|
56
|
+
|
57
|
+
@font.draw "Ashton::Texture is <i>always</i> smoothed when zoomed out, so it doesn't distort", 0, 400, 0
|
58
|
+
end
|
59
|
+
|
60
|
+
def button_down(id)
|
61
|
+
case id
|
62
|
+
when Gosu::KbEscape
|
63
|
+
close
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
window = GameWindow.new
|
69
|
+
window.show
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Use of GLSL shader in Gosu to post-process the entire screen.
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
|
9
|
+
require "ashton"
|
10
|
+
|
11
|
+
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
|
12
|
+
|
13
|
+
class TestWindow < Gosu::Window
|
14
|
+
def initialize
|
15
|
+
super 640, 480, false
|
16
|
+
self.caption = "Post-processing with 'radial_blur' - mouse pos affects spacing/strength"
|
17
|
+
|
18
|
+
@blur = Ashton::Shader.new fragment: :radial_blur
|
19
|
+
@font = Gosu::Font.new self, Gosu::default_font_name, 40
|
20
|
+
@background = Gosu::Image.new(self, media_path("Earth.png"), true)
|
21
|
+
|
22
|
+
update # Ensure the values are initially set.
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
$gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
|
27
|
+
|
28
|
+
@blur.spacing = [2.0 * mouse_x / width, 0.0].max
|
29
|
+
@blur.strength = [4.4 * mouse_y / height, 0.0].max
|
30
|
+
end
|
31
|
+
|
32
|
+
def needs_cursor?; true end
|
33
|
+
|
34
|
+
def button_down(id)
|
35
|
+
if (Gosu::Kb1..Gosu::Kb9).include? id
|
36
|
+
@blur_factor = (id - Gosu::Kb1 + 1).to_f
|
37
|
+
@blur.blur_factor = @blur_factor
|
38
|
+
elsif id == Gosu::KbEscape
|
39
|
+
close
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def draw
|
44
|
+
shaders = button_down?(Gosu::KbSpace) ? [] : [@blur]
|
45
|
+
post_process(*shaders) do
|
46
|
+
@background.draw 0, 0, 0, width.fdiv(@background.width), height.fdiv(@background.height)
|
47
|
+
|
48
|
+
@font.draw_rel "Hello world!", 100, 100, 0, 0.5, 0.5, 1, 1, Gosu::Color::RED
|
49
|
+
@font.draw_rel "Goodbye world!", 400, 280, 0, 0.5, 0.5, 1, 1, Gosu::Color::BLUE
|
50
|
+
end
|
51
|
+
|
52
|
+
# Drawing after the effect isn't processed, which is useful for GUI elements.
|
53
|
+
@font.draw_rel "Less spacing", 0, height / 2, 0, 0, 0.5
|
54
|
+
@font.draw_rel "More spacing", width, height / 2, 0, 1, 0.5
|
55
|
+
|
56
|
+
@font.draw_rel "Less strength", width / 2, 0, 0, 0.5, 0
|
57
|
+
@font.draw_rel "More strength", width / 2, height, 0, 0.5, 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
TestWindow.new.show
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Use of GLSL shader in Gosu.
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
|
9
|
+
require "ashton"
|
10
|
+
|
11
|
+
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
|
12
|
+
def output_path(file); File.expand_path "output/#{file}", File.dirname(__FILE__) end
|
13
|
+
|
14
|
+
class GameWindow < Gosu::Window
|
15
|
+
def initialize
|
16
|
+
super 640, 480, false
|
17
|
+
self.caption = "Gosu & OpenGL Integration Demo (SHADERS)"
|
18
|
+
|
19
|
+
@font = Gosu::Font.new self, Gosu::default_font_name, 24
|
20
|
+
@image = Gosu::Image.new self, media_path("Earth.png"), true
|
21
|
+
|
22
|
+
@sepia = Ashton::Shader.new fragment: :sepia
|
23
|
+
@contrast = Ashton::Shader.new fragment: :contrast
|
24
|
+
@mezzotint = Ashton::Shader.new fragment: :mezzotint
|
25
|
+
@grayscale = Ashton::Shader.new fragment: :grayscale
|
26
|
+
@color_inversion = Ashton::Shader.new fragment: :color_inversion
|
27
|
+
@fade = Ashton::Shader.new fragment: :fade, uniforms: {
|
28
|
+
fade: 0.75,
|
29
|
+
}
|
30
|
+
|
31
|
+
update # Ensure values are set before draw.
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
$gosu_blocks.clear if defined? $gosu_blocks # workaround for Gosu 0.7.45 bug.
|
36
|
+
|
37
|
+
@fade.fade = @fade_fade = Math::sin(Gosu::milliseconds / 1000.0) / 2 + 0.5
|
38
|
+
@contrast.contrast = @contrast_contrast = Math::sin(Gosu::milliseconds / 1000.0) * 2 + 2
|
39
|
+
@mezzotint.t = (Gosu::milliseconds / 100.0).to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def draw
|
43
|
+
@image.draw 0, 0, 0, width.fdiv(@image.width), height.fdiv(@image.height)
|
44
|
+
|
45
|
+
# draw, with and without colour.
|
46
|
+
@image.draw 10, 10, 0, :shader => @sepia
|
47
|
+
@font.draw ":sepia", 10, 150, 0
|
48
|
+
|
49
|
+
@image.draw 10, @image.height + 120, 0, 1, 1, Gosu::Color::RED, :shader => @mezzotint
|
50
|
+
@font.draw ":mezzotint", 10, 400, 0
|
51
|
+
|
52
|
+
# draw_rot, with and without colour.
|
53
|
+
@image.draw_rot 235, 0, 0, 10, 0, 0, :shader => @contrast
|
54
|
+
@font.draw ":contrast #{"%.2f" % @contrast_contrast}", 235, 150, 0
|
55
|
+
|
56
|
+
@image.draw_rot 235, @image.height + 110, 0, 10, 0, 0, 1, 1, Gosu::Color::RED, :shader => @fade
|
57
|
+
@font.draw ":fade #{"%.2f" % @fade_fade}", 235, 400, 0
|
58
|
+
|
59
|
+
# More draws.
|
60
|
+
@image.draw 430, 10, 0, :shader => @grayscale
|
61
|
+
@font.draw ":grayscale", 430, 150, 0
|
62
|
+
|
63
|
+
@image.draw 430, @image.height + 110, 0, :shader => @color_inversion
|
64
|
+
@font.draw ":color_inversion", 430, 400, 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def button_down(id)
|
68
|
+
if id == Gosu::KbEscape
|
69
|
+
close
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
window = GameWindow.new
|
75
|
+
window.show
|