Skip to content

Commit 8996968

Browse files
committed
fixed examples
1 parent 852918c commit 8996968

File tree

7 files changed

+38
-36
lines changed

7 files changed

+38
-36
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ glow = "0.14"
1414
memoffset = "0.9"
1515

1616
[dev-dependencies]
17-
glutin = "0.31.1"
18-
glutin-winit = "0.4.2"
19-
imgui-winit-support = { version = "0.12.0" }
17+
glutin = "0.32"
18+
glutin-winit = "0.5"
19+
imgui-winit-support = "0.13.0"
2020
image = "0.23"
21-
raw-window-handle = "0.5.0"
22-
winit = { version = "0.29.3", features = ["rwh_05"] }
21+
raw-window-handle = "0.6.0"
22+
winit = { version = "0.30", features = ["rwh_06"] }
2323

2424
[features]
2525
# Features here are used to opt-out of compiling code that depends on certain

examples/glow_01_basic.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use imgui_winit_support::{
1414
winit::{
1515
dpi::LogicalSize,
1616
event_loop::EventLoop,
17-
window::{Window, WindowBuilder},
17+
window::{Window, WindowAttributes},
1818
},
1919
WinitPlatform,
2020
};
21-
use raw_window_handle::HasRawWindowHandle;
21+
use raw_window_handle::HasWindowHandle;
2222

2323
const TITLE: &str = "Hello, imgui-rs!";
2424

@@ -39,6 +39,7 @@ fn main() {
3939
let mut last_frame = Instant::now();
4040

4141
// Standard winit event loop
42+
#[allow(deprecated)]
4243
event_loop
4344
.run(move |event, window_target| {
4445
match event {
@@ -112,19 +113,20 @@ fn create_window() -> (
112113
) {
113114
let event_loop = EventLoop::new().unwrap();
114115

115-
let window_builder = WindowBuilder::new()
116+
let window_attributes = WindowAttributes::default()
116117
.with_title(TITLE)
117118
.with_inner_size(LogicalSize::new(1024, 768));
118119
let (window, cfg) = glutin_winit::DisplayBuilder::new()
119-
.with_window_builder(Some(window_builder))
120+
.with_window_attributes(Some(window_attributes))
120121
.build(&event_loop, ConfigTemplateBuilder::new(), |mut configs| {
121122
configs.next().unwrap()
122123
})
123124
.expect("Failed to create OpenGL window");
124125

125126
let window = window.unwrap();
126127

127-
let context_attribs = ContextAttributesBuilder::new().build(Some(window.raw_window_handle()));
128+
let context_attribs =
129+
ContextAttributesBuilder::new().build(Some(window.window_handle().unwrap().as_raw()));
128130
let context = unsafe {
129131
cfg.display()
130132
.create_context(&cfg, &context_attribs)
@@ -134,7 +136,7 @@ fn create_window() -> (
134136
let surface_attribs = SurfaceAttributesBuilder::<WindowSurface>::new()
135137
.with_srgb(Some(true))
136138
.build(
137-
window.raw_window_handle(),
139+
window.window_handle().unwrap().as_raw(),
138140
NonZeroU32::new(1024).unwrap(),
139141
NonZeroU32::new(768).unwrap(),
140142
);
@@ -161,7 +163,7 @@ fn imgui_init(window: &Window) -> (WinitPlatform, imgui::Context) {
161163
let mut imgui_context = imgui::Context::create();
162164
imgui_context.set_ini_filename(None);
163165

164-
let mut winit_platform = WinitPlatform::init(&mut imgui_context);
166+
let mut winit_platform = WinitPlatform::new(&mut imgui_context);
165167
winit_platform.attach_window(
166168
imgui_context.io_mut(),
167169
window,

examples/glow_02_triangle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn main() {
1717
let tri_renderer = Triangler::new(ig_renderer.gl_context(), "#version 330");
1818

1919
let mut last_frame = Instant::now();
20+
#[allow(deprecated)]
2021
event_loop
2122
.run(move |event, window_target| {
2223
match event {

examples/glow_03_triangle_gles.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn main() {
3535
let tri_renderer = Triangler::new(&gl, "#version 300 es\nprecision mediump float;");
3636

3737
let mut last_frame = Instant::now();
38+
#[allow(deprecated)]
3839
event_loop
3940
.run(move |event, window_target| {
4041
match event {

examples/glow_04_custom_textures.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn main() {
3636
let textures_ui = TexturesUi::new(&gl, &mut textures);
3737

3838
let mut last_frame = Instant::now();
39+
#[allow(deprecated)]
3940
event_loop
4041
.run(move |event, window_target| {
4142
// Note we can potentially make the loop more efficient by
@@ -109,14 +110,14 @@ fn main() {
109110

110111
struct TexturesUi {
111112
generated_texture: imgui::TextureId,
112-
lenna: SipiPng,
113+
sipi: SipiPng,
113114
}
114115

115116
impl TexturesUi {
116117
fn new(gl: &glow::Context, textures: &mut imgui::Textures<glow::Texture>) -> Self {
117118
Self {
118119
generated_texture: Self::generate(gl, textures),
119-
lenna: SipiPng::load(gl, textures),
120+
sipi: SipiPng::load(gl, textures),
120121
}
121122
}
122123

@@ -176,11 +177,11 @@ impl TexturesUi {
176177
ui.text("Some generated texture");
177178
imgui::Image::new(self.generated_texture, [100.0, 100.0]).build(ui);
178179

179-
ui.text("Say hello to Lenna.jpg");
180-
self.lenna.show(ui);
180+
ui.text("Say hello to Peppers");
181+
self.sipi.show(ui);
181182

182183
// Example of using custom textures on a button
183-
ui.text("The Lenna buttons");
184+
ui.text("The Peppers buttons");
184185
{
185186
ui.invisible_button("Boring Button", [100.0, 100.0]);
186187
// See also `imgui::Ui::style_color`
@@ -199,11 +200,7 @@ impl TexturesUi {
199200

200201
let draw_list = ui.get_window_draw_list();
201202
draw_list
202-
.add_image(
203-
self.lenna.texture_id,
204-
ui.item_rect_min(),
205-
ui.item_rect_max(),
206-
)
203+
.add_image(self.sipi.texture_id, ui.item_rect_min(), ui.item_rect_max())
207204
.col(tint)
208205
.build();
209206
}
@@ -232,7 +229,7 @@ impl TexturesUi {
232229

233230
let draw_list = ui.get_window_draw_list();
234231
draw_list
235-
.add_image_quad(self.lenna.texture_id, tl, tr, br, bl)
232+
.add_image_quad(self.sipi.texture_id, tl, tr, br, bl)
236233
.build();
237234
}
238235

@@ -244,7 +241,7 @@ impl TexturesUi {
244241
let draw_list = ui.get_window_draw_list();
245242
draw_list
246243
.add_image_rounded(
247-
self.lenna.texture_id,
244+
self.sipi.texture_id,
248245
ui.item_rect_min(),
249246
ui.item_rect_max(),
250247
16.0,
@@ -269,13 +266,13 @@ struct SipiPng {
269266

270267
impl SipiPng {
271268
fn load(gl: &glow::Context, textures: &mut imgui::Textures<glow::Texture>) -> Self {
272-
let lenna_image = image::io::Reader::new(Cursor::new(SIPI_PNG))
269+
let sipi_png = image::io::Reader::new(Cursor::new(SIPI_PNG))
273270
.with_guessed_format()
274271
.unwrap()
275272
.decode()
276273
.expect("could not make decoder")
277274
.to_rgba8();
278-
let (width, height) = lenna_image.dimensions();
275+
let (width, height) = sipi_png.dimensions();
279276

280277
let gl_texture = unsafe { gl.create_texture() }.expect("unable to create GL texture");
281278

@@ -294,13 +291,13 @@ impl SipiPng {
294291
gl.tex_image_2d(
295292
glow::TEXTURE_2D,
296293
0,
297-
glow::SRGB as _, // image file has sRGB encoded colors
294+
glow::SRGB8_ALPHA8 as _, // image file has sRGB encoded colors
298295
width as _,
299296
height as _,
300297
0,
301-
glow::RGB,
298+
glow::RGBA,
302299
glow::UNSIGNED_BYTE,
303-
Some(&lenna_image),
300+
Some(&sipi_png),
304301
)
305302
}
306303

examples/glow_05_framebufferobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fn main() {
5656
}));
5757

5858
let mut last_frame = Instant::now();
59+
#[allow(deprecated)]
5960
event_loop
6061
.run(move |event, window_target| {
6162
match event {

examples/utils/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use glutin::{
88
surface::{GlSurface, Surface, SurfaceAttributesBuilder, SwapInterval, WindowSurface},
99
};
1010
use imgui_winit_support::WinitPlatform;
11-
use raw_window_handle::HasRawWindowHandle;
11+
use raw_window_handle::HasWindowHandle;
1212
use winit::{
1313
dpi::LogicalSize,
1414
event_loop::EventLoop,
15-
window::{Window, WindowBuilder},
15+
window::{Window, WindowAttributes},
1616
};
1717

1818
pub fn create_window(
@@ -26,11 +26,11 @@ pub fn create_window(
2626
) {
2727
let event_loop = EventLoop::new().unwrap();
2828

29-
let window_builder = WindowBuilder::new()
29+
let window_attributes = WindowAttributes::default()
3030
.with_title(title)
3131
.with_inner_size(LogicalSize::new(1024, 768));
3232
let (window, cfg) = glutin_winit::DisplayBuilder::new()
33-
.with_window_builder(Some(window_builder))
33+
.with_window_attributes(Some(window_attributes))
3434
.build(&event_loop, ConfigTemplateBuilder::new(), |mut configs| {
3535
configs.next().unwrap()
3636
})
@@ -42,7 +42,7 @@ pub fn create_window(
4242
if let Some(context_api) = context_api {
4343
context_attribs = context_attribs.with_context_api(context_api);
4444
}
45-
let context_attribs = context_attribs.build(Some(window.raw_window_handle()));
45+
let context_attribs = context_attribs.build(Some(window.window_handle().unwrap().as_raw()));
4646
let context = unsafe {
4747
cfg.display()
4848
.create_context(&cfg, &context_attribs)
@@ -52,7 +52,7 @@ pub fn create_window(
5252
let surface_attribs = SurfaceAttributesBuilder::<WindowSurface>::new()
5353
.with_srgb(Some(true))
5454
.build(
55-
window.raw_window_handle(),
55+
window.window_handle().unwrap().as_raw(),
5656
NonZeroU32::new(1024).unwrap(),
5757
NonZeroU32::new(768).unwrap(),
5858
);
@@ -83,7 +83,7 @@ pub fn imgui_init(window: &Window) -> (WinitPlatform, imgui::Context) {
8383
let mut imgui_context = imgui::Context::create();
8484
imgui_context.set_ini_filename(None);
8585

86-
let mut winit_platform = WinitPlatform::init(&mut imgui_context);
86+
let mut winit_platform = WinitPlatform::new(&mut imgui_context);
8787
winit_platform.attach_window(
8888
imgui_context.io_mut(),
8989
window,

0 commit comments

Comments
 (0)