diff --git a/Cargo.toml b/Cargo.toml index 19e9579..29b8507 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,10 @@ git = "https://github.com/PistonDevelopers/piston" git = "https://github.com/bjz/gl-rs" +[dependencies.gfx] + +git = "https://github.com/gfx-rs/gfx-rs" + [[lib]] name = "sdl2_game_window" diff --git a/src/concurrent_window_sdl2.rs b/src/concurrent_window_sdl2.rs index 33d0b24..d13ddb3 100644 --- a/src/concurrent_window_sdl2.rs +++ b/src/concurrent_window_sdl2.rs @@ -1,6 +1,9 @@ //! RenderWindow and ConcurrentWindow implemented by SDL2 back-end. // External crates. +use gfx; +use gfx::DeviceHelper; +use device; use std; use sdl2; use piston::{ @@ -145,4 +148,14 @@ impl ConcurrentWindowSDL2 { ); } + + /// Creates a gfx device and front end. + pub fn gfx(&self) -> (device::GlDevice, gfx::FrontEnd) { + let mut device = device::GlDevice::new(|s| unsafe { + std::mem::transmute(sdl2::video::gl_get_proc_address(s)) + }); + let (w, h) = self.get_size(); + let frontend = device.create_frontend(w as u16, h as u16).unwrap(); + (device, frontend) + } } diff --git a/src/game_window_sdl2.rs b/src/game_window_sdl2.rs index afe5d8b..e16964f 100644 --- a/src/game_window_sdl2.rs +++ b/src/game_window_sdl2.rs @@ -1,6 +1,8 @@ //! A window implemented by SDL2 back-end. // External crates. +use gfx; +use device; use sdl2; use piston::{ GameWindow, @@ -35,6 +37,11 @@ impl GameWindowSDL2 { render_window: render_window, } } + + /// Creates a gfx devince and front end. + pub fn gfx(&self) -> (device::GlDevice, gfx::FrontEnd) { + self.concurrent_window.gfx() + } } impl GameWindow for GameWindowSDL2 { diff --git a/src/lib.rs b/src/lib.rs index 99487fc..fcf99e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,8 @@ extern crate sdl2; extern crate piston; extern crate gl; +extern crate gfx; +extern crate device; pub use GameWindowSDL2 = game_window_sdl2::GameWindowSDL2; pub use ConcurrentWindowSDL2 = concurrent_window_sdl2::ConcurrentWindowSDL2;