Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions src/concurrent_window_sdl2.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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)
}
}
7 changes: 7 additions & 0 deletions src/game_window_sdl2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! A window implemented by SDL2 back-end.

// External crates.
use gfx;
use device;
use sdl2;
use piston::{
GameWindow,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down