Sha256: f0a5f5ab3921ec3e02d421d47658a814e848b06e81b520c2bbc69f44f0ec447b

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

# Use of GLSL shader in Gosu.

begin
  require 'rubygems'
rescue LoadError
end

$LOAD_PATH.unshift File.expand_path('../lib/', File.dirname(__FILE__))
require "ashton"

def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end

class GameWindow < Gosu::Window
  def initialize
    super 800, 600, false
    self.caption = "Ashton::Texture example - composing an image - hold <LMB> to draw - <delete> to clear"

    @font = Gosu::Font.new(self, Gosu::default_font_name, 20)
    @star = Gosu::Image.new(self, media_path("LargeStar.png"), true)
    @texture = Ashton::Texture.new width, height
  end

  def update
    $gosu_blocks.clear if defined? $gosu_blocks # Workaround for Gosu bug (0.7.45)

    if button_down? Gosu::MsLeft
      # Draw into the texture, rather than onto the screen.
      @texture.render do
        @star.draw_rot mouse_x, mouse_y, 0, 0, 0.5, 0.5
      end
    end
  end

  def needs_cursor?; true end

  def draw
    @texture.draw 0, 0, 0
    @star.draw_rot mouse_x, mouse_y, 0, 0, 0.5, 0.5

    @font.draw "FPS: #{Gosu::fps}", 0, 0, 0
  end

  def button_down(id)
    case id
      when Gosu::KbDelete
        @texture.clear color: Gosu::Color.rgb(rand() * 255, rand() * 255, rand() * 255)
      when Gosu::KbEscape
        close
    end
  end
end

window = GameWindow.new
window.show

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
danabr75-ashton-0.1.5 examples/texture_render_example.rb
ashton-0.1.6 examples/texture_render_example.rb
ashton-0.1.5 examples/texture_render_example.rb
ashton-0.1.4 examples/texture_render_example.rb
ashton-0.1.3 examples/texture_render_example.rb
ashton-0.1.2 examples/texture_render_example.rb
ashton-0.1.1 examples/texture_render_example.rb
ashton-0.1.0 examples/texture_render_example.rb
ashton-0.0.4alpha examples/texture_render_example.rb