Skip to content

Instantly share code, notes, and snippets.

@mverzilli
Created September 25, 2014 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mverzilli/435a6122c008047c3113 to your computer and use it in GitHub Desktop.
Save mverzilli/435a6122c008047c3113 to your computer and use it in GitHub Desktop.
#Instead of this:
require "sdl2/sdl2"
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SDL2.init
window = SDL2.create_window("SDL Tutorial", LibSDL2::WINDOWPOS_UNDEFINED, LibSDL2::WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, LibSDL2::WINDOW_SHOWN)
raise "Window could not be created! SDL_Error: #{SDL2.error}" unless window
screen_surface = LibSDL2.get_window_surface window.window
format = screen_surface.value.format
rgb_map = LibSDL2.map_rgb format, 0xFF_u8, 0xFF_u8, 0xFF_u8
LibSDL2.fill_rect screen_surface, nil, rgb_map
LibSDL2.update_window_surface window.window
LibSDL2.delay 2000_u32
SDL2.quit
###### Do this:
require "sdl2/sdl2"
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SDL2.init do
window = SDL2.create_window("SDL Tutorial", LibSDL2::WINDOWPOS_UNDEFINED, LibSDL2::WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, LibSDL2::WINDOW_SHOWN)
raise "Window could not be created! SDL_Error: #{SDL2.error}" unless window
screen_surface = LibSDL2.get_window_surface window.window
format = screen_surface.value.format
rgb_map = LibSDL2.map_rgb format, 0xFF_u8, 0xFF_u8, 0xFF_u8
LibSDL2.fill_rect screen_surface, nil, rgb_map
LibSDL2.update_window_surface window.window
LibSDL2.delay 2000_u32
end # SDL2.quit after block is executed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment