Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README.md Example not working (outdated?) #78

Open
BerryArray opened this issue Mar 4, 2023 · 2 comments
Open

README.md Example not working (outdated?) #78

BerryArray opened this issue Mar 4, 2023 · 2 comments

Comments

@BerryArray
Copy link

BerryArray commented Mar 4, 2023

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.

@ids1024
Copy link
Member

ids1024 commented Mar 4, 2023

The API was updated in #64. The example in the README should work on the git master of softbuffer, but not the latest release.

@ghost
Copy link

ghost commented Mar 31, 2023

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" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants