Skip to content

Commit 5bd14ff

Browse files
committed
Merge pull request #30 from bvssvni/master
Added gfx-rs support
2 parents 3511ef2 + e774601 commit 5bd14ff

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ git = "https://github.com/PistonDevelopers/piston"
2727

2828
git = "https://github.com/bjz/gl-rs"
2929

30+
[dependencies.gfx]
31+
32+
git = "https://github.com/gfx-rs/gfx-rs"
33+
3034
[[lib]]
3135

3236
name = "sdl2_game_window"

src/concurrent_window_sdl2.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! RenderWindow and ConcurrentWindow implemented by SDL2 back-end.
22
33
// External crates.
4+
use gfx;
5+
use gfx::DeviceHelper;
6+
use device;
47
use std;
58
use sdl2;
69
use piston::{
@@ -145,4 +148,14 @@ impl ConcurrentWindowSDL2 {
145148
);
146149

147150
}
151+
152+
/// Creates a gfx device and front end.
153+
pub fn gfx(&self) -> (device::GlDevice, gfx::FrontEnd) {
154+
let mut device = device::GlDevice::new(|s| unsafe {
155+
std::mem::transmute(sdl2::video::gl_get_proc_address(s))
156+
});
157+
let (w, h) = self.get_size();
158+
let frontend = device.create_frontend(w as u16, h as u16).unwrap();
159+
(device, frontend)
160+
}
148161
}

src/game_window_sdl2.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! A window implemented by SDL2 back-end.
22
33
// External crates.
4+
use gfx;
5+
use device;
46
use sdl2;
57
use piston::{
68
GameWindow,
@@ -35,6 +37,11 @@ impl GameWindowSDL2 {
3537
render_window: render_window,
3638
}
3739
}
40+
41+
/// Creates a gfx devince and front end.
42+
pub fn gfx(&self) -> (device::GlDevice, gfx::FrontEnd) {
43+
self.concurrent_window.gfx()
44+
}
3845
}
3946

4047
impl GameWindow for GameWindowSDL2 {

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
extern crate sdl2;
77
extern crate piston;
88
extern crate gl;
9+
extern crate gfx;
10+
extern crate device;
911

1012
pub use GameWindowSDL2 = game_window_sdl2::GameWindowSDL2;
1113
pub use ConcurrentWindowSDL2 = concurrent_window_sdl2::ConcurrentWindowSDL2;

0 commit comments

Comments
 (0)