SDL2 seems like the best way to get started with retro video games. It’s simple.
Prerequisite:
dnf install SDL2-devel
To easily draw primitives:
dnf install SDL2_gfx-devel
Create the window:
let sdl_context = sdl2::init().unwrap();
let sdl_video = sdl_context.video().unwrap();
let window = sdl_video
.window("Fluid 2D", 800, 600)
.opengl()
.build().unwrap();
let canvas = window.into_canvas().build().unwrap();
unwrap gets the result or panics upon error. Alternatively, ? will get the result or return the error from the function.
Draw a circle:
canvas.clear();
canvas.filled_circle(x as i16, y as i16, radius as i16, Color::RGB(r as u8, g as u8, b as u8)).unwrap();
Refresh the window:
canvas.present();
Process events:
let event_pump = sdl_context.event_pump().unwrap();
for event in self.event_pump.poll_iter() {
match event {
Event::Quit { .. } | Event::KeyDown {
keycode: Some(sdl2::keyboard::Keycode::Escape),
..
} => return false,
Event::MouseMotion { x, y, .. } => {
canvas.filled_circle(x as i16, y as i16, particle_radius, Color::RGB(60, 110, 255)).unwrap();
}
_ => {}
}
}