Skip to content

Commit e28d8b2

Browse files
committed
lights rust example
1 parent 219d754 commit e28d8b2

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ path = "examples/animated_mesh.rs"
6464
name = "custom_attribute"
6565
path = "examples/custom_attribute.rs"
6666

67+
[[example]]
68+
name = "lights"
69+
path = "examples/lights.rs"
70+
6771
[profile.wasm-release]
6872
inherits = "release"
6973
opt-level = "z"

examples/lights.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
mod glfw;
2+
3+
use glfw::GlfwContext;
4+
use processing::prelude::*;
5+
use processing_render::render::command::DrawCommand;
6+
7+
fn main() {
8+
match sketch() {
9+
Ok(_) => {
10+
eprintln!("Sketch completed successfully");
11+
exit(0).unwrap();
12+
}
13+
Err(e) => {
14+
eprintln!("Sketch error: {:?}", e);
15+
exit(1).unwrap();
16+
}
17+
};
18+
}
19+
20+
fn sketch() -> error::Result<()> {
21+
let mut glfw_ctx = GlfwContext::new(400, 400)?;
22+
init(Config::default())?;
23+
24+
let width = 400;
25+
let height = 400;
26+
let scale_factor = 1.0;
27+
28+
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
29+
let graphics = graphics_create(surface, width, height)?;
30+
let box_geo = geometry_box(10.0, 10.0, 10.0)?;
31+
32+
let point_light = light_create()?;
33+
34+
graphics_mode_3d(graphics)?;
35+
graphics_camera_position(graphics, 100.0, 100.0, 300.0)?;
36+
graphics_camera_look_at(graphics, 0.0, 0.0, 0.0)?;
37+
38+
let mut angle = 0.0;
39+
40+
while glfw_ctx.poll_events() {
41+
graphics_begin_draw(graphics)?;
42+
43+
graphics_record_command(
44+
graphics,
45+
DrawCommand::BackgroundColor(bevy::color::Color::srgb(0.18, 0.20, 0.15)),
46+
)?;
47+
48+
graphics_record_command(graphics, DrawCommand::Light(point_light))?;
49+
50+
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
51+
graphics_record_command(graphics, DrawCommand::Translate { x: 25.0, y: 25.0 })?;
52+
graphics_record_command(graphics, DrawCommand::Rotate { angle })?;
53+
graphics_record_command(graphics, DrawCommand::Geometry(box_geo))?;
54+
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
55+
56+
graphics_record_command(graphics, DrawCommand::PushMatrix)?;
57+
graphics_record_command(graphics, DrawCommand::Translate { x: -25.0, y: 20.0 })?;
58+
graphics_record_command(graphics, DrawCommand::Scale { x: 1.5, y: 2.0 })?;
59+
graphics_record_command(graphics, DrawCommand::Rotate { angle })?;
60+
graphics_record_command(graphics, DrawCommand::Geometry(box_geo))?;
61+
graphics_record_command(graphics, DrawCommand::PopMatrix)?;
62+
63+
graphics_end_draw(graphics)?;
64+
65+
angle += 0.02;
66+
}
67+
Ok(())
68+
}

0 commit comments

Comments
 (0)