Created
September 8, 2019 23:09
-
-
Save ibebrett/3d77b9a3b2ca092d15a5812eaa898c40 to your computer and use it in GitHub Desktop.
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
struct SDLContext { | |
sdl: sdl2::Sdl, | |
audio: sdl2::AudioSubsystem, | |
window: Box<sdl2::video::Window>, | |
canvas: Box<sdl2::render::WindowCanvas>, | |
//texture_creator: sdl2::render::TextureCreator<sdl2::video::WindowContext>, | |
} | |
impl SDLContext { | |
fn new() -> Result<SDLContext, String> { | |
let sdl = sdl2::init()?; | |
let audio = sdl.audio()?; | |
let _image_context = sdl2::image::init(InitFlag::PNG | InitFlag::JPG)?; | |
let video_subsystem = sdl.video()?; | |
let window = Box::new( | |
video_subsystem | |
.window("Tiles", 1200, 1200) | |
.position_centered() | |
.build() | |
.map_err(|e| e.to_string())?, | |
); | |
let canvas = Box::new( | |
window | |
.into_canvas() | |
.software() | |
.build() | |
.map_err(|e| e.to_string())?, | |
); | |
//let texture_creator = canvas.texture_creator(); | |
let context = SDLContext { | |
sdl: sdl, | |
audio: audio, | |
window: window, | |
canvas: canvas | |
// texture: | |
// texture_creator, | |
}; | |
Ok(context) | |
} | |
} | |
fn main() -> Result<(), String> { | |
let mut sdl = SDLContext::new()?; | |
/* | |
let mut events = sdl.sdl.event_pump()?; | |
'mainloop: loop { | |
for event in events.poll_iter() { | |
match event { | |
Event::Quit { .. } => break 'mainloop, | |
_ => {} | |
} | |
} | |
sdl.canvas.clear(); | |
sdl.canvas.present(); | |
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60)); | |
}*/ | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment