diff --git a/src/plat/sdl2/main.rs b/src/plat/sdl2/main.rs index f829e76..63f5ca7 100644 --- a/src/plat/sdl2/main.rs +++ b/src/plat/sdl2/main.rs @@ -19,7 +19,7 @@ mod video; use audio::create_audio_player; use input::create_input; -use video::create_video_interface; +use video::{create_video_interface, SCALE, SCREEN_HEIGHT, SCREEN_WIDTH}; extern crate rustboyadvance_ng; use rustboyadvance_ng::prelude::*; @@ -47,7 +47,18 @@ fn main() { let cpu = cpu; let sdl_context = sdl2::init().unwrap(); - let video = Rc::new(RefCell::new(create_video_interface(&sdl_context))); + let video_subsystem = sdl_context.video().unwrap(); + let window = video_subsystem + .window( + "RustBoyAdvance", + SCREEN_WIDTH * SCALE, + SCREEN_HEIGHT * SCALE, + ) + .opengl() + .position_centered() + .build() + .unwrap(); + let video = Rc::new(RefCell::new(create_video_interface(window))); let audio = Rc::new(RefCell::new(create_audio_player(&sdl_context))); let input = Rc::new(RefCell::new(create_input())); diff --git a/src/plat/sdl2/video.rs b/src/plat/sdl2/video.rs index 78fe2e7..e516203 100644 --- a/src/plat/sdl2/video.rs +++ b/src/plat/sdl2/video.rs @@ -1,15 +1,14 @@ use sdl2::pixels::{Color, PixelFormatEnum}; use sdl2::rect::Rect; use sdl2::render::{TextureCreator, WindowCanvas}; -use sdl2::video::WindowContext; -use sdl2::Sdl; +use sdl2::video::{Window, WindowContext}; use rustboyadvance_ng::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH}; use rustboyadvance_ng::VideoInterface; -const SCREEN_WIDTH: u32 = DISPLAY_WIDTH as u32; -const SCREEN_HEIGHT: u32 = DISPLAY_HEIGHT as u32; -const SCALE: u32 = 3; // TODO control via CLI & support window resize +pub const SCREEN_WIDTH: u32 = DISPLAY_WIDTH as u32; +pub const SCREEN_HEIGHT: u32 = DISPLAY_HEIGHT as u32; +pub const SCALE: u32 = 3; // TODO control via CLI & support window resize pub struct Sdl2Video { tc: TextureCreator, @@ -46,18 +45,7 @@ impl VideoInterface for Sdl2Video { } } -pub fn create_video_interface(sdl: &Sdl) -> Sdl2Video { - let video_subsystem = sdl.video().unwrap(); - let window = video_subsystem - .window( - "RustBoyAdvance", - SCREEN_WIDTH * SCALE, - SCREEN_HEIGHT * SCALE, - ) - .opengl() - .position_centered() - .build() - .unwrap(); +pub fn create_video_interface(window: Window) -> Sdl2Video { let mut canvas = window.into_canvas().accelerated().build().unwrap(); canvas.set_draw_color(Color::RGB(0, 0, 0)); canvas.clear();