$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../lib") $:.unshift File.expand_path(File.dirname(__FILE__) + "/../../ext") require 'ray' Ray::Game.new("Shaders test") do register do add_hook :quit, method(:exit!) end scene :shader do img = Ray::Image.new(:w => 100, :h => 100).fill(Ray::Color.green) img.draw_line([0, 0], [100, 100], Ray::Color.black, 2) img.draw_line([0, 100], [100, 0], Ray::Color.white, 2) img.draw_filled_circle([50, 50], 10, Ray::Color.cyan) img.update shader = Ray::Shader.new StringIO.new(<<-SHADER) uniform sampler2D texture; uniform vec3 ratio; void main() { vec4 color = texture2D(texture, gl_TexCoord[0].xy); float gray = dot(color.xyz, ratio); gl_FragColor = vec4(gray, gray, gray, 1.0); } SHADER shader["texture"] = :current shader["ratio"] = [0.299, 0.587, 0.114] render do |win| win.fill(Ray::Color.black) img.draw(:on => win, :at => [0, 0], :shader => shader) img.draw(:on => win, :at => [100, 100], :shader => nil) end end push_scene :shader end