Browse Source

Add Sdl canvas

main
arnaucube 3 years ago
parent
commit
b9c4be977a
2 changed files with 19 additions and 2 deletions
  1. +1
    -2
      Cargo.toml
  2. +18
    -0
      src/main.rs

+ 1
- 2
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"}

+ 18
- 0
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,
}
}

Loading…
Cancel
Save