Skip to content

Instantly share code, notes, and snippets.

@mverzilli
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save mverzilli/f09aa7a837eefc6063cb to your computer and use it in GitHub Desktop.

Select an option

Save mverzilli/f09aa7a837eefc6063cb 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