Currently, graphics is done with SDL. Use the ndless-sdl crate to do
so. You'll first need to initialize the screen at the beginning of your
main
function:
use ndless_sdl::{SurfaceFlag, VideoFlag};
ndless_sdl::init(&[ndless_sdl::InitFlag::Video]);
let screen = ndless_sdl::video::set_video_mode(
320,
240,
16,
&[SurfaceFlag::SWSurface],
&[VideoFlag::NoFrame],
)
.expect("failed to set video mode");
Then, at the end, stop it:
ndless_sdl::quit();
Now, you can draw on the screen with the screen
variable, which is a
Surface
. Typically, you'll want to use fill_rect
to draw
rectangles, draw_str
to draw low-res text, and blit_rect
to draw
images loaded by the image
module. When you're ready to display to
the screen, call screen.flip()
. For a basic example, see
hello-world-sdl. For a more advanced example loading a real font, see
hello-world-text. For a real program using fonts and images, see
n-flashcards.