Now that you’ve uploaded your code to your Git hosting platform, start coding.

Start at the entrance

Write directly in the main function, and then organize the code. Before writing code, create a branch and try not to change things on the main branch.

git checkout -b create-a-window

use self::time::Duration;
use sdl2::pixels::Color;
use std::{thread, time};

fn main() {
    let sdl2_context = sdl2::init().unwrap();
    let video = sdl2_context.video().unwrap();
    let window = video
        .window("Arcade Shooter".800.600)
        .position_centered()
        .opengl()
        .build()
        .unwrap();
    let mut canvas = window.renderer().accelerated().build().unwrap();
    canvas.set_draw_color(Color::RGB(0.0.0));
    canvas.clear();
    canvas.present();
    thread::sleep(Duration::from_millis(10000));
}
Copy the code

Now you have created a window and left it open for 10 seconds.

Code reading

Extern Crate SDL2 is required to introduce sdL2 module in the old version. The new version really improves the development experience. Use SDL2 directly to use SDL2. After the main function goes in, the Result

is initialized by sdL2’s init function. Normally, just unwrap the Sdl instance, or expect can pass in a slice of the String that prompts the error condition. This is the beginning of the SDL we will use later. The rest is easy to understand, initialize the video subsystem via the VIDEO function of the Sdl instance, then use this instance to call the window function to create the window builder, configure the window center, configure OpenGL support, and finally build a window. In fact, this code is a Hello world thing.
,>


This section should be very simple, is to turn over the nature of the document.