arnaucube
arnaucube/chip8-rsPublic Self-hosted repository
Add Sdl canvas
arnaucube root@arnaucube.com
Sat, 17 Oct 2020 23:08:01 +0200
commit

b9c4be977ad237cfd6d27d49b6b0583a678ccc63

parent

755a772036e12463682bd3df6b79fcdac482043e

2 files changed, 19 insertions(+), 2 deletions(-)

jump to
M Cargo.toml → Cargo.toml

@@ -4,8 +4,7 @@ version = "0.0.1"

authors = ["arnaucube <root@arnaucube.com>"] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] clap = "2.33.3" +sdl2 = "0.34.3" chip8 = {path="./chip8"}
M src/main.rs → src/main.rs

@@ -1,3 +1,8 @@

+extern crate sdl2; + +use sdl2::pixels::Color; +use sdl2::render::Canvas; + use clap::{App, Arg}; use chip8::Chip8;

@@ -6,6 +11,7 @@ struct SdlEmulator {

w: usize, h: usize, zoom: usize, + canvas: Canvas<sdl2::video::Window>, chip8: Chip8, }

@@ -13,10 +19,22 @@ impl SdlEmulator {

fn new(w: usize, h: usize, zoom: usize) -> SdlEmulator { let mut c = Chip8::new(); + let sdl_context = sdl2::init().unwrap(); + let video_subsystem = sdl_context.video().unwrap(); + + let window = video_subsystem + .window("rust-sdl2 demo", 800, 600) + .position_centered() + .build() + .unwrap(); + + let mut canvas = window.into_canvas().build().unwrap(); + SdlEmulator { w, h, zoom, + canvas, chip8: c, } }