-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathblend_modes.rs
More file actions
109 lines (95 loc) · 2.86 KB
/
blend_modes.rs
File metadata and controls
109 lines (95 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use processing_glfw::GlfwContext;
use processing::prelude::*;
const MODES: &[BlendMode] = &[
BlendMode::Blend,
BlendMode::Add,
BlendMode::Subtract,
BlendMode::Darkest,
BlendMode::Lightest,
BlendMode::Difference,
BlendMode::Exclusion,
BlendMode::Multiply,
BlendMode::Screen,
BlendMode::Replace,
];
fn main() {
match sketch() {
Ok(_) => exit(0).unwrap(),
Err(e) => {
eprintln!("Error: {e:?}");
exit(1).unwrap();
}
}
}
fn sketch() -> error::Result<()> {
let width = 500;
let height = 500;
let mut glfw_ctx = GlfwContext::new(width, height)?;
init(Config::default())?;
let surface = glfw_ctx.create_surface(width, height)?;
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
let mut index: usize = 0;
while glfw_ctx.poll_events() {
if input_key_just_pressed(KeyCode::ArrowRight)? || input_key_just_pressed(KeyCode::Space)? {
index = (index + 1) % MODES.len();
eprintln!("{}", MODES[index].name());
} else if input_key_just_pressed(KeyCode::ArrowLeft)? {
index = (index + MODES.len() - 1) % MODES.len();
eprintln!("{}", MODES[index].name());
}
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::BackgroundColor(bevy::color::Color::srgba(0.15, 0.15, 0.15, 1.0)),
)?;
graphics_record_command(graphics, DrawCommand::NoStroke)?;
graphics_record_command(
graphics,
DrawCommand::BlendMode(MODES[index].to_blend_state()),
)?;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgba(0.9, 0.2, 0.2, 0.75)),
)?;
graphics_record_command(
graphics,
DrawCommand::Rect {
x: 80.0,
y: 100.0,
w: 200.0,
h: 250.0,
radii: [0.0; 4],
},
)?;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgba(0.2, 0.8, 0.2, 0.75)),
)?;
graphics_record_command(
graphics,
DrawCommand::Rect {
x: 180.0,
y: 80.0,
w: 200.0,
h: 250.0,
radii: [0.0; 4],
},
)?;
graphics_record_command(
graphics,
DrawCommand::Fill(bevy::color::Color::srgba(0.2, 0.3, 0.9, 0.75)),
)?;
graphics_record_command(
graphics,
DrawCommand::Rect {
x: 130.0,
y: 200.0,
w: 200.0,
h: 200.0,
radii: [0.0; 4],
},
)?;
graphics_end_draw(graphics)?;
}
Ok(())
}