plat: sdl2: Keep the video subsystem in the main scope
Former-commit-id: 36b7c3478f4396b7d6dc2e234a0790ae3b3eba45
This commit is contained in:
parent
3687161b98
commit
467cd9728a
|
@ -19,7 +19,7 @@ mod video;
|
||||||
|
|
||||||
use audio::create_audio_player;
|
use audio::create_audio_player;
|
||||||
use input::create_input;
|
use input::create_input;
|
||||||
use video::create_video_interface;
|
use video::{create_video_interface, SCALE, SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||||
|
|
||||||
extern crate rustboyadvance_ng;
|
extern crate rustboyadvance_ng;
|
||||||
use rustboyadvance_ng::prelude::*;
|
use rustboyadvance_ng::prelude::*;
|
||||||
|
@ -47,7 +47,18 @@ fn main() {
|
||||||
let cpu = cpu;
|
let cpu = cpu;
|
||||||
|
|
||||||
let sdl_context = sdl2::init().unwrap();
|
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 audio = Rc::new(RefCell::new(create_audio_player(&sdl_context)));
|
||||||
let input = Rc::new(RefCell::new(create_input()));
|
let input = Rc::new(RefCell::new(create_input()));
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
use sdl2::pixels::{Color, PixelFormatEnum};
|
use sdl2::pixels::{Color, PixelFormatEnum};
|
||||||
use sdl2::rect::Rect;
|
use sdl2::rect::Rect;
|
||||||
use sdl2::render::{TextureCreator, WindowCanvas};
|
use sdl2::render::{TextureCreator, WindowCanvas};
|
||||||
use sdl2::video::WindowContext;
|
use sdl2::video::{Window, WindowContext};
|
||||||
use sdl2::Sdl;
|
|
||||||
|
|
||||||
use rustboyadvance_ng::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
|
use rustboyadvance_ng::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH};
|
||||||
use rustboyadvance_ng::VideoInterface;
|
use rustboyadvance_ng::VideoInterface;
|
||||||
|
|
||||||
const SCREEN_WIDTH: u32 = DISPLAY_WIDTH as u32;
|
pub const SCREEN_WIDTH: u32 = DISPLAY_WIDTH as u32;
|
||||||
const SCREEN_HEIGHT: u32 = DISPLAY_HEIGHT as u32;
|
pub const SCREEN_HEIGHT: u32 = DISPLAY_HEIGHT as u32;
|
||||||
const SCALE: u32 = 3; // TODO control via CLI & support window resize
|
pub const SCALE: u32 = 3; // TODO control via CLI & support window resize
|
||||||
|
|
||||||
pub struct Sdl2Video {
|
pub struct Sdl2Video {
|
||||||
tc: TextureCreator<WindowContext>,
|
tc: TextureCreator<WindowContext>,
|
||||||
|
@ -46,18 +45,7 @@ impl VideoInterface for Sdl2Video {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_video_interface(sdl: &Sdl) -> Sdl2Video {
|
pub fn create_video_interface(window: Window) -> Sdl2Video {
|
||||||
let video_subsystem = sdl.video().unwrap();
|
|
||||||
let window = video_subsystem
|
|
||||||
.window(
|
|
||||||
"RustBoyAdvance",
|
|
||||||
SCREEN_WIDTH * SCALE,
|
|
||||||
SCREEN_HEIGHT * SCALE,
|
|
||||||
)
|
|
||||||
.opengl()
|
|
||||||
.position_centered()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
let mut canvas = window.into_canvas().accelerated().build().unwrap();
|
let mut canvas = window.into_canvas().accelerated().build().unwrap();
|
||||||
canvas.set_draw_color(Color::RGB(0, 0, 0));
|
canvas.set_draw_color(Color::RGB(0, 0, 0));
|
||||||
canvas.clear();
|
canvas.clear();
|
||||||
|
|
Reference in a new issue