Skip to content

Instantly share code, notes, and snippets.

@chasepeck
Last active June 11, 2022 01:44
Show Gist options
  • Save chasepeck/2ff217dd2ea579fb951f35a54e43610b to your computer and use it in GitHub Desktop.
Save chasepeck/2ff217dd2ea579fb951f35a54e43610b to your computer and use it in GitHub Desktop.
use sdl2::render::Canvas;
pub fn new_sdl(name: &str, width: u32, height: u32)
-> (sdl2::Sdl, Canvas<sdl2::video::Window>, sdl2::VideoSubsystem)
{
let context = sdl2::init().unwrap();
let video_subsystem = context.video().unwrap();
let window = new_window(name, width, height, &video_subsystem);
let canvas = new_canvas(window);
(context, canvas, video_subsystem)
}
pub fn new_window(name: &str, width: u32, height: u32, video: &sdl2::VideoSubsystem)
-> sdl2::video::Window
{
let window = video.window(&name, width, height)
.position_centered()
.build()
.unwrap();
window
}
pub fn new_canvas(window: sdl2::video::Window)
-> Canvas<sdl2::video::Window>
{
let canvas = window.into_canvas().build().unwrap();
canvas
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment