We now have a working window; it'd be nice to draw into it. First, we need to get the window's canvas before starting the main loop:
let mut canvas = window.into_canvas() .target_texture() .present_vsync() .build() .expect("Couldn't get window's canvas");
A few explanations for the preceding code:
into_canvas
transforms the window into a canvas so that we can manipulate it more easilytarget_texture
activates texture rendering supportpresent_vsync
enables the v-sync (also known as vertical-synchronization) limitbuild
creates the canvas by applying all previously set parameters
Then we'll create a texture that we'll paste onto the window's canvas. First, let's get the texture creator, but before that, add this include at the top of the file:
use sdl2::render::{Canvas, Texture, TextureCreator};
Now we can get the texture creator:
let texture_creator: TextureCreator<_> = canvas.texture_creator...