|
|
@@ -1,18 +1,25 @@ |
|
|
|
use sdl2::pixels::Color; |
|
|
|
use sdl2::event::Event; |
|
|
|
use sdl2::keyboard::Keycode; |
|
|
|
use sdl2::render::WindowCanvas; |
|
|
|
use sdl2::render::{WindowCanvas, Texture}; |
|
|
|
use sdl2::image::{self, LoadTexture, InitFlag}; |
|
|
|
use std::time::Duration; |
|
|
|
|
|
|
|
fn render(canvas: &mut WindowCanvas, color: Color) { |
|
|
|
fn render(canvas: &mut WindowCanvas, color: Color, texture: &Texture) -> Result<(), String> { |
|
|
|
canvas.set_draw_color(color); |
|
|
|
canvas.clear(); |
|
|
|
|
|
|
|
canvas.copy(texture, None, None)?; |
|
|
|
|
|
|
|
canvas.present(); |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|
fn main() -> Result<(), String> { |
|
|
|
let sdl_context = sdl2::init()?; |
|
|
|
let video_subsystem = sdl_context.video()?; |
|
|
|
let _image_context = image::init(InitFlag::PNG | InitFlag::JPG)?; |
|
|
|
|
|
|
|
let window = video_subsystem.window("game tutorial", 800, 600) |
|
|
|
.position_centered() |
|
|
@@ -22,6 +29,9 @@ fn main() -> Result<(), String> { |
|
|
|
let mut canvas = window.into_canvas().build() |
|
|
|
.expect("could not make a canvas"); |
|
|
|
|
|
|
|
let texture_creator = canvas.texture_creator(); |
|
|
|
let texture = texture_creator.load_texture("assets/bardo.png")?; |
|
|
|
|
|
|
|
let mut event_pump = sdl_context.event_pump()?; |
|
|
|
let mut i = 0; |
|
|
|
'running: loop { |
|
|
@@ -37,7 +47,7 @@ fn main() -> Result<(), String> { |
|
|
|
|
|
|
|
i = (i + 1) % 255; |
|
|
|
|
|
|
|
render(&mut canvas, Color::RGB(i, 64, 255-i)); |
|
|
|
render(&mut canvas, Color::RGB(i, 64, 255-i), &texture)?; |
|
|
|
|
|
|
|
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60)); |
|
|
|
} |