Skip to content

Commit

Permalink
fixing v1
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNachoBIT committed Aug 24, 2024
1 parent 8edf2c5 commit f1769c6
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions examples/simple_sdl2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@ extern crate sdl2;

use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::time::Duration;

use std::num::NonZeroUsize;

use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, DebugLayers, Renderer, RendererOptions, Scene};
use vello::kurbo::{Affine, Circle, Ellipse, Line, RoundedRect, Stroke};
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, DebugLayers, Renderer, RendererOptions, Scene};

use vello::wgpu;

use pollster;

pub fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();

let width: u32 = 800;
let height: u32 = 600;

let window = video_subsystem.window("Vello SDL2 Demo", width, height)
let window = video_subsystem
.window("Vello SDL2 Demo", width, height)
.position_centered()
.metal_view()
.build()
.unwrap();

let mut context = RenderContext::new();

let surface_future = unsafe {
let surface_future = unsafe {
context.create_surface_unsafe(
wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap(),
width,
Expand All @@ -40,18 +38,17 @@ pub fn main() {
};

let surface = pollster::block_on(surface_future).expect("Error creating surface.");

let mut renderers: Vec<Option<Renderer>> = vec![];

renderers.resize_with(context.devices.len(), || None);
renderers[surface.dev_id].insert(create_vello_renderer(&context, &surface));
let _ = renderers[surface.dev_id].insert(create_vello_renderer(&context, &surface));

let mut scene = Scene::new();

let mut event_pump = sdl_context.event_pump().unwrap();

'running: loop {

scene.reset();

add_shapes_to_scene(&mut scene);
Expand Down Expand Up @@ -83,17 +80,16 @@ pub fn main() {

for event in event_pump.poll_iter() {
match event {
Event::Quit {..} |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running
},
Event::Quit { .. }
| Event::KeyDown {
keycode: Some(Keycode::Escape),
..
} => break 'running,
_ => {}
}
}

surface_texture.present();

//::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
}
}

Expand Down Expand Up @@ -143,4 +139,4 @@ fn add_shapes_to_scene(scene: &mut Scene) {
let line = Line::new((260.0, 20.0), (620.0, 100.0));
let line_stroke_color = Color::rgb(0.5373, 0.7059, 0.9804);
scene.stroke(&stroke, Affine::IDENTITY, line_stroke_color, None, &line);
}
}

0 comments on commit f1769c6

Please sign in to comment.