-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0addfc0
commit 7985349
Showing
3 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "softbuf" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
fltk = { version = "1", features = ["rwh06"] } | ||
softbuffer = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use fltk::{prelude::*, *}; | ||
use std::num::NonZeroU32; | ||
|
||
fn main() { | ||
const width: u32 = 400; | ||
const height: u32 = 300; | ||
let a = app::App::default(); | ||
let mut w = window::Window::default().with_size(width as i32, height as i32); | ||
w.end(); | ||
w.show(); | ||
w.wait_for_expose(); | ||
|
||
let context = softbuffer::Context::new(w.clone()).unwrap(); | ||
let mut surface = softbuffer::Surface::new(&context, w.clone()).unwrap(); | ||
surface | ||
.resize( | ||
NonZeroU32::new(width).unwrap(), | ||
NonZeroU32::new(height).unwrap(), | ||
) | ||
.unwrap(); | ||
|
||
app::add_timeout(1.0, move || { | ||
let mut buffer = surface.buffer_mut().unwrap(); | ||
for index in 0..(width * height) { | ||
let y = index / width; | ||
let x = index % width; | ||
let red = x % 255; | ||
let green = y % 255; | ||
let blue = (x * y) % 255; | ||
|
||
buffer[index as usize] = blue | (green << 8) | (red << 16); | ||
} | ||
buffer.present().unwrap(); | ||
}); | ||
|
||
|
||
a.run().unwrap(); | ||
} |