Created
June 21, 2009 06:34
-
-
Save jacius/133428 to your computer and use it in GitHub Desktop.
A sample script to demonstrate Ruby-SDL-FFI (as of June 21, 2009)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
# A sample script to demonstrate Ruby-SDL-FFI (as of June 21, 2009). | |
# NOTE: Ruby-SDL-FFI API is still in flux. | |
require 'ruby-sdl-ffi' | |
path = ARGV[0] | |
if path.nil? | |
puts "Usage: load_image.rb /path/to/image" | |
exit 1 | |
elsif not File.exist?( File.expand_path(path) ) | |
puts "Error: file doesn't exist: #{path}" | |
exit 1 | |
end | |
path = File.expand_path(path) | |
# Load the image file. | |
image = SDL::Surface.new( SDL::Image::IMG_Load( path ) ) | |
# Create a new window the same size as the image. | |
screen = SDL::Surface.new( SDL::SDL_SetVideoMode(image.w, image.h, 0, 0) ) | |
# Blit the image onto the screen surface. | |
SDL::SDL_BlitSurface( image, nil, screen, nil ) | |
# Update the screen. | |
SDL::SDL_UpdateRect( screen, 0, 0, 0, 0 ) | |
# Set the screen title to the filename of the image. | |
SDL::SDL_WM_SetCaption( File.basename(path), File.basename(path) ) | |
# Pause while the user admires the image. | |
sleep 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment