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