Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dev-dependencies #169

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gfx-glyph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ log = "0.4"
cgmath = "0.18"
env_logger = { version = "0.10", default-features = false }
gfx_device_gl = "0.16"
glutin = "0.30.3"
glutin-winit = "0.3"
old_school_gfx_glutin_ext = "0.31"
glutin = "0.31"
glutin-winit = "0.4"
old_school_gfx_glutin_ext = "0.32"
spin_sleep = "1"
winit = "0.28"
winit = "0.29"
148 changes: 76 additions & 72 deletions gfx-glyph/examples/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ use glutin_winit::GlWindow;
use init::init_example;
use std::error::Error;
use winit::{
event::{Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event::{Event, KeyEvent, WindowEvent},
event_loop::ControlFlow,
keyboard::{Key, NamedKey},
};

fn main() -> Result<(), Box<dyn Error>> {
init_example("depth");

let event_loop = winit::event_loop::EventLoop::new();
let event_loop = winit::event_loop::EventLoop::new()?;
event_loop.set_control_flow(ControlFlow::Poll);
let title = "gfx_glyph example - resize to see multi-text layout";
let window_builder = winit::window::WindowBuilder::new()
.with_title(title)
Expand Down Expand Up @@ -50,87 +52,89 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut loop_helper = spin_sleep::LoopHelper::builder().build_with_target_rate(250.0);
let mut view_size = window.inner_size();

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

event_loop.run(move |event, elwt| {
match event {
Event::AboutToWait => window.request_redraw(),
Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
WindowEvent::CloseRequested
| WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
..
},
..
}
| WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
_ => (),
},
Event::MainEventsCleared => {
// handle resizes
let w_size = window.inner_size();
if view_size != w_size {
window.resize_surface(&gl_surface, &gl_context);
old_school_gfx_glutin_ext::resize_views(
w_size,
&mut color_view,
&mut depth_view,
} => elwt.exit(),
WindowEvent::RedrawRequested => {
// handle resizes
let w_size = window.inner_size();
if view_size != w_size {
window.resize_surface(&gl_surface, &gl_context);
old_school_gfx_glutin_ext::resize_views(
w_size,
&mut color_view,
&mut depth_view,
);
view_size = w_size;
}

encoder.clear(&color_view, [0.02, 0.02, 0.02, 1.0]);
encoder.clear_depth(&depth_view, 1.0);

let (width, height) = (w_size.width as f32, w_size.height as f32);

// first section is queued, and therefore drawn, first with lower z
glyph_brush.queue(
Section::default()
.add_text(
Text::new("On top")
.with_scale(95.0)
.with_color([0.8, 0.8, 0.8, 1.0])
.with_z(0.2)
.with_font_id(italic_font),
)
.with_screen_position((width / 2.0, 100.0))
.with_bounds((width, height - 100.0))
.with_layout(Layout::default().h_align(HorizontalAlign::Center)),
);
view_size = w_size;
}

encoder.clear(&color_view, [0.02, 0.02, 0.02, 1.0]);
encoder.clear_depth(&depth_view, 1.0);

let (width, height) = (w_size.width as f32, w_size.height as f32);

// first section is queued, and therefore drawn, first with lower z
glyph_brush.queue(
Section::default()
.add_text(
Text::new("On top")
.with_scale(95.0)
.with_color([0.8, 0.8, 0.8, 1.0])
.with_z(0.2)
.with_font_id(italic_font),
)
.with_screen_position((width / 2.0, 100.0))
.with_bounds((width, height - 100.0))
.with_layout(Layout::default().h_align(HorizontalAlign::Center)),
);

// 2nd section is drawn last but with higher z,
// draws are subject to depth testing
glyph_brush.queue(
Section::default()
.add_text(
Text::new(&include_str!("lipsum.txt").replace("\n\n", "").repeat(10))
// 2nd section is drawn last but with higher z,
// draws are subject to depth testing
glyph_brush.queue(
Section::default()
.add_text(
Text::new(
&include_str!("lipsum.txt").replace("\n\n", "").repeat(10),
)
.with_scale(30.0)
.with_color([0.05, 0.05, 0.1, 1.0])
.with_z(1.0),
)
.with_bounds((width, height)),
);

glyph_brush
.use_queue()
// Enable depth testing with default less-equal drawing and update the depth buffer
.depth_target(&depth_view)
.draw(&mut encoder, &color_view)
.unwrap();

encoder.flush(&mut device);
gl_surface.swap_buffers(&gl_context).unwrap();
device.cleanup();

if let Some(rate) = loop_helper.report_rate() {
window.set_title(&format!("{title} - {rate:.0} FPS"));
}
)
.with_bounds((width, height)),
);

loop_helper.loop_sleep();
loop_helper.loop_start();
}
glyph_brush
.use_queue()
// Enable depth testing with default less-equal drawing and update the depth buffer
.depth_target(&depth_view)
.draw(&mut encoder, &color_view)
.unwrap();

encoder.flush(&mut device);
gl_surface.swap_buffers(&gl_context).unwrap();
device.cleanup();

if let Some(rate) = loop_helper.report_rate() {
window.set_title(&format!("{title} - {rate:.0} FPS"));
}

loop_helper.loop_sleep();
loop_helper.loop_start();
}
_ => (),
},
_ => (),
}
});
})?;
Ok(())
}
Loading