January 2018
Beginner to intermediate
454 pages
10h 8m
English
Just like textures, we need to initialize the image context. Now that we've activated the image feature, we can call the linked functions and import them. Let's add some new imports:
use sdl2::image::{LoadTexture, INIT_PNG, INIT_JPG};
Then we create the image context:
sdl2::image::init(INIT_PNG | INIT_JPG).expect("Couldn't initialize image context");Now that the context has been initialized, let's actually load the image:
let image_texture = texture_creator.load_texture("assets/my_image.png") .expect("Couldn't load image");
A few explanations for the preceding code:
load_texture takes a file path as an argument. Be very careful with paths, even more when they're relative!
After that, it's just like we did with ...