softbuffer
softbuffer copied to clipboard
README.md Example not working (outdated?)
The example on the README.md file (Here) seems to contain structs(?) like softbuffer::Context
and softbuffer::Surface
which aren't in the documentation. (nor seem to exist at all?)
There's an extremely similar example used in the docs.rs softbuffer home-page (Here) which does compile.
What's strange is that I can't seem to find any mention of softbuffer::Context
and softbuffer::Surface
in any of the older versions' documentation.
The API was updated in https://github.com/rust-windowing/softbuffer/pull/64. The example in the README should work on the git master
of softbuffer, but not the latest release.
Allow me to save you some time.
let mut graphics_context = unsafe { GraphicsContext::new(&window, &window) }.unwrap();
Event::RedrawRequested(window_id) => {
if window_id == window.id() {
let (width, height) = {
let size = window.inner_size();
(size.width, size.height)
};
let buffer = (0..((width * height) as usize))
.map(|index| {
let y = index / (width as usize);
let x = index % (width as usize);
let red = x % 255;
let green = y % 255;
let blue = (x * y) % 255;
let color = blue | (green << 8) | (red << 16);
color as u32
})
.collect::<Vec<_>>();
graphics_context.set_buffer(&buffer, width as u16, height as u16);
}
}
Alternatively, modify the entry in Cargo.toml and use what is was in the README.
softbuffer = { git = "https://github.com/rust-windowing/softbuffer.git" rev = "e5d546" }
As of now, README.md
contains the correctly released code.