ashton 0.0.1alpha → 0.0.2alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/LICENSE +21 -21
  2. data/README.md +95 -68
  3. data/Rakefile +41 -23
  4. data/examples/bloom_example.rb +59 -0
  5. data/examples/lighting_example.rb +127 -0
  6. data/examples/media/SmallStar.png +0 -0
  7. data/examples/media/Starfighter.png +0 -0
  8. data/examples/media/simple.png +0 -0
  9. data/examples/noise_example.rb +94 -0
  10. data/examples/outline_example.rb +86 -0
  11. data/examples/particle_emitter_example.rb +114 -0
  12. data/examples/pixelate_example.rb +51 -49
  13. data/examples/pixelated_texture_example.rb +69 -0
  14. data/examples/radial_blur_example.rb +60 -62
  15. data/examples/shader_image_example.rb +74 -41
  16. data/examples/{shockwave2_example.rb → shockwave_example.rb} +74 -75
  17. data/examples/stencil_shader_example.rb +104 -0
  18. data/examples/{framebuffer_example.rb → texture_render_example.rb} +53 -49
  19. data/examples/{tv_screen_and_noise_example.rb → tv_screen_and_static_example.rb} +59 -59
  20. data/ext/ashton/GLee.c +18170 -0
  21. data/ext/ashton/GLee.h +17647 -0
  22. data/ext/ashton/ashton.c +42 -0
  23. data/ext/ashton/ashton.h +31 -0
  24. data/ext/ashton/color.c +45 -0
  25. data/ext/ashton/color.h +25 -0
  26. data/ext/ashton/common.h +41 -0
  27. data/ext/ashton/extconf.rb +42 -0
  28. data/ext/ashton/fast_math.c +30 -0
  29. data/ext/ashton/fast_math.h +30 -0
  30. data/ext/ashton/font.c +8 -0
  31. data/ext/ashton/font.h +16 -0
  32. data/ext/ashton/gosu.c +18 -0
  33. data/ext/ashton/gosu.h +19 -0
  34. data/ext/ashton/image.c +8 -0
  35. data/ext/ashton/image.h +16 -0
  36. data/ext/ashton/particle_emitter.c +788 -0
  37. data/ext/ashton/particle_emitter.h +171 -0
  38. data/ext/ashton/pixel_cache.c +237 -0
  39. data/ext/ashton/pixel_cache.h +58 -0
  40. data/ext/ashton/shader.c +9 -0
  41. data/ext/ashton/shader.h +16 -0
  42. data/ext/ashton/texture.c +442 -0
  43. data/ext/ashton/texture.h +63 -0
  44. data/ext/ashton/window.c +8 -0
  45. data/ext/ashton/window.h +16 -0
  46. data/lib/ashton.rb +38 -26
  47. data/lib/ashton/1.9/ashton.so +0 -0
  48. data/lib/ashton/gosu_ext/color.rb +24 -11
  49. data/lib/ashton/gosu_ext/font.rb +58 -0
  50. data/lib/ashton/gosu_ext/gosu_module.rb +16 -0
  51. data/lib/ashton/gosu_ext/image.rb +95 -31
  52. data/lib/ashton/gosu_ext/window.rb +78 -35
  53. data/lib/ashton/image_stub.rb +32 -36
  54. data/lib/ashton/lighting/light_source.rb +146 -0
  55. data/lib/ashton/lighting/manager.rb +98 -0
  56. data/lib/ashton/mixins/version_checking.rb +23 -0
  57. data/lib/ashton/particle_emitter.rb +87 -0
  58. data/lib/ashton/pixel_cache.rb +24 -0
  59. data/lib/ashton/shader.rb +353 -35
  60. data/lib/ashton/shaders/bloom.frag +41 -0
  61. data/lib/ashton/shaders/color_inversion.frag +11 -0
  62. data/lib/ashton/{post_process → shaders}/contrast.frag +16 -16
  63. data/lib/ashton/{shader → shaders}/default.frag +22 -19
  64. data/lib/ashton/{shader → shaders}/default.vert +13 -13
  65. data/lib/ashton/shaders/fade.frag +14 -0
  66. data/lib/ashton/shaders/grayscale.frag +15 -0
  67. data/lib/ashton/shaders/include/classicnoise2d.glsl +113 -0
  68. data/lib/ashton/shaders/include/classicnoise3d.glsl +177 -0
  69. data/lib/ashton/shaders/include/classicnoise4d.glsl +302 -0
  70. data/lib/ashton/{include/simplex.glsl → shaders/include/noise2d.glsl} +70 -63
  71. data/lib/ashton/shaders/include/noise3d.glsl +102 -0
  72. data/lib/ashton/shaders/include/noise4d.glsl +128 -0
  73. data/lib/ashton/shaders/include/rand.glsl +5 -0
  74. data/lib/ashton/shaders/lighting/distort.frag +57 -0
  75. data/lib/ashton/shaders/lighting/draw_shadows.frag +60 -0
  76. data/lib/ashton/shaders/lighting/shadow_blur.frag +60 -0
  77. data/lib/ashton/shaders/mezzotint.frag +22 -0
  78. data/lib/ashton/shaders/multitexture2.vert +19 -0
  79. data/lib/ashton/shaders/outline.frag +45 -0
  80. data/lib/ashton/{post_process → shaders}/pixelate.frag +48 -48
  81. data/lib/ashton/shaders/radial_blur.frag +63 -0
  82. data/lib/ashton/shaders/sepia.frag +26 -0
  83. data/lib/ashton/{post_process/shockwave2.frag → shaders/shockwave.frag} +38 -35
  84. data/lib/ashton/shaders/signed_distance_field.frag +80 -0
  85. data/lib/ashton/{post_process/noise.frag → shaders/static.frag} +25 -27
  86. data/lib/ashton/shaders/stencil.frag +27 -0
  87. data/lib/ashton/shaders/tv_screen.frag +23 -0
  88. data/lib/ashton/signed_distance_field.rb +151 -0
  89. data/lib/ashton/texture.rb +186 -0
  90. data/lib/ashton/version.rb +2 -2
  91. data/lib/ashton/window_buffer.rb +16 -0
  92. data/spec/ashton/ashton_spec.rb +22 -0
  93. data/spec/ashton/gosu_ext/color_spec.rb +34 -0
  94. data/spec/ashton/gosu_ext/font_spec.rb +57 -0
  95. data/spec/ashton/gosu_ext/gosu_spec.rb +11 -0
  96. data/spec/ashton/gosu_ext/image_spec.rb +66 -0
  97. data/spec/ashton/gosu_ext/window_spec.rb +71 -0
  98. data/spec/ashton/image_stub_spec.rb +46 -0
  99. data/spec/ashton/particle_emitter_spec.rb +123 -0
  100. data/spec/ashton/pixel_cache_spec.rb +153 -0
  101. data/spec/ashton/shader_spec.rb +152 -0
  102. data/spec/ashton/signed_distance_field_spec.rb +163 -0
  103. data/spec/ashton/texture_spec.rb +347 -0
  104. data/spec/helper.rb +12 -0
  105. metadata +159 -28
  106. data/examples/output/README.txt +0 -1
  107. data/lib/ashton/base_shader.rb +0 -172
  108. data/lib/ashton/framebuffer.rb +0 -183
  109. data/lib/ashton/post_process.rb +0 -83
  110. data/lib/ashton/post_process/default.vert +0 -9
  111. data/lib/ashton/post_process/fade.frag +0 -11
  112. data/lib/ashton/post_process/mezzotint.frag +0 -24
  113. data/lib/ashton/post_process/radial_blur.frag +0 -31
  114. data/lib/ashton/post_process/sepia.frag +0 -19
  115. data/lib/ashton/post_process/shockwave.frag +0 -40
  116. data/lib/ashton/post_process/tv_screen.frag +0 -32
Binary file
Binary file
Binary file
@@ -0,0 +1,94 @@
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
+ NOISE_FRAGMENT =<<-END
15
+ #version 110
16
+
17
+ // Use 3D Simplex noise, even though the shader operates on a 2D
18
+ // texture, since then we can make the Z-coordinate act as time.
19
+ #include <noise3d>
20
+
21
+ uniform sampler2D in_Texture;
22
+
23
+ uniform float in_T;
24
+ uniform vec4 in_BlobColor;
25
+
26
+ varying vec2 var_TexCoord;
27
+
28
+ void main()
29
+ {
30
+ gl_FragColor = texture2D(in_Texture, var_TexCoord);
31
+
32
+ // First layer. faster, low intensity, small scale blobbing.
33
+ // Use [x, y, t] to create a 2D noise that varies over time.
34
+ vec3 position1 = vec3(var_TexCoord * 25.0, in_T * 1.6);
35
+
36
+ // Gives range 0.75..1.25
37
+ float brightness1 = snoise(position1) / 4.0 + 1.0;
38
+
39
+ // Second layer - slow, high intensity, large-scale blobbing
40
+ // This decides where the first layer will be "seen"
41
+ // Use [x, y, t] to create a 2D noise that varies over time.
42
+ vec3 position2 = vec3(var_TexCoord * 3.0, in_T * 0.16);
43
+
44
+ // Gives range 0.3..1.3
45
+ float brightness2 = snoise(position2) / 2.0 + 0.8;
46
+
47
+ if(brightness2 > 0.8)
48
+ {
49
+ gl_FragColor.rgb += in_BlobColor.rgb;
50
+ gl_FragColor.rgb *= brightness1 * brightness2;
51
+ }
52
+ }
53
+ END
54
+
55
+ def initialize
56
+ super 640, 480, false
57
+ self.caption = "Post-processing with the simplex noise function - intelligent blob?"
58
+
59
+ @noise = Ashton::Shader.new fragment: NOISE_FRAGMENT, uniforms: {
60
+ blob_color: Gosu::Color.rgb(0, 40, 0),
61
+ }
62
+
63
+ @font = Gosu::Font.new self, Gosu::default_font_name, 40
64
+ @background = Gosu::Image.new(self, media_path("Earth.png"), true)
65
+ @start_time = Time.now
66
+
67
+ update # Ensure the values are initially set.
68
+ end
69
+
70
+ def update
71
+ $gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)
72
+ @noise.t = Time.now - @start_time
73
+ end
74
+
75
+ def draw
76
+ post_process @noise do
77
+ @background.draw 0, 0, 0, width.fdiv(@background.width), height.fdiv(@background.height)
78
+
79
+ @font.draw_rel "Hello world!", 350, 50, 0, 0.5, 0.5, 1, 1, Gosu::Color::GREEN
80
+ @font.draw_rel "Goodbye world!", 400, 350, 0, 0.5, 0.5, 2, 2, Gosu::Color::BLUE
81
+ end
82
+
83
+ # Drawing after the effect isn't processed, which is useful for GUI elements.
84
+ @font.draw "FPS: #{Gosu::fps}", 0, 0, 0
85
+ end
86
+
87
+ def button_down(id)
88
+ if id == Gosu::KbEscape
89
+ close
90
+ end
91
+ end
92
+ end
93
+
94
+ TestWindow.new.show
@@ -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
@@ -1,50 +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 shader(file); File.read File.expand_path("../lib/ashton/post_process/#{file}", File.dirname(__FILE__)) end
12
- def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
13
-
14
- class TestWindow < Gosu::Window
15
- def initialize
16
- super 640, 480, false
17
- self.caption = "Post-processing with 'pixelate' - 1..9 affect pixel size"
18
-
19
- @pixelate = Ashton::PostProcess.new shader('pixelate.frag')
20
- @pixelate['in_PixelSize'] = @pixel_size = 4
21
-
22
- @font = Gosu::Font.new self, Gosu::default_font_name, 40
23
- @star = Gosu::Image.new(self, media_path("LargeStar.png"), true)
24
-
25
- update # Ensure the values are initially set.
26
- end
27
-
28
- def button_down(id)
29
- if (Gosu::Kb1..Gosu::Kb9).include? id
30
- @pixel_size = (id - Gosu::Kb1 + 1) ** 2
31
- @pixelate['in_PixelSize'] = @pixel_size
32
- elsif id == Gosu::KbEscape
33
- close
34
- end
35
- end
36
-
37
- def draw
38
- post_process @pixelate do
39
- @font.draw_rel "Hello world!", 350, 50, 0, 0.5, 0.5
40
- @font.draw_rel "Goodbye world!", 400, 350, 0, 0.5, 0.5
41
- @star.draw 0, 0, 0
42
- @star.draw 200, 100, 0
43
- end
44
-
45
- # Drawing after the effect isn't processed, which is useful for GUI elements.
46
- @font.draw "Pixel ratio: 1:#{@pixel_size}", 0, 0, 0
47
- end
48
- end
49
-
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
+
50
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