Sha256: 05ab0c0ecafdaa608d6cfda10d5825ca41a1775c7e81957a30e83e7ca4de14d1

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../lib")
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../ext")

require 'ray'

def path_of(res)
  File.expand_path(res, File.join(File.dirname(__FILE__), '../../test/res'))
end

class CustomDrawable < Ray::Drawable
  include Ray::GL

  def initialize
    super
    self.vertex_count = 3
    @custom_shader = Ray::Shader.new(:vertex => path_of("vert.c"),
                                     :frag   => path_of("frag_gray.c"))

    @custom_shader["in_ModelView"]  = Ray::Matrix.identity

  end

  def fill_vertices
     [Ray::Vertex.new([0,   0],   Ray::Color.red),
      Ray::Vertex.new([0.5, 0],   Ray::Color.green),
      Ray::Vertex.new([0.5, 0.5], Ray::Color.blue)]
  end

  def render(vertex, index)
    @custom_shader["in_Projection"] = matrix

    @custom_shader.bind
    draw_arrays :triangles, vertex, 3
  end
end


Ray.game "OpenGL test" do
  register do
    add_hook :quit, method(:exit!)
  end

  scene :triangle do
    @obj = CustomDrawable.new

    render do |win|
      win.draw @obj
    end
  end

  scenes << :triangle
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ray-0.1.1 samples/opengl/shader.rb
ray-0.1.0 samples/opengl/shader.rb