Skip to content

Commit

Permalink
fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbox-irl committed Sep 30, 2024
1 parent 852918c commit 8996968
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ glow = "0.14"
memoffset = "0.9"

[dev-dependencies]
glutin = "0.31.1"
glutin-winit = "0.4.2"
imgui-winit-support = { version = "0.12.0" }
glutin = "0.32"
glutin-winit = "0.5"
imgui-winit-support = "0.13.0"
image = "0.23"
raw-window-handle = "0.5.0"
winit = { version = "0.29.3", features = ["rwh_05"] }
raw-window-handle = "0.6.0"
winit = { version = "0.30", features = ["rwh_06"] }

[features]
# Features here are used to opt-out of compiling code that depends on certain
Expand Down
16 changes: 9 additions & 7 deletions examples/glow_01_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use imgui_winit_support::{
winit::{
dpi::LogicalSize,
event_loop::EventLoop,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
},
WinitPlatform,
};
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::HasWindowHandle;

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

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

// Standard winit event loop
#[allow(deprecated)]
event_loop
.run(move |event, window_target| {
match event {
Expand Down Expand Up @@ -112,19 +113,20 @@ fn create_window() -> (
) {
let event_loop = EventLoop::new().unwrap();

let window_builder = WindowBuilder::new()
let window_attributes = WindowAttributes::default()
.with_title(TITLE)
.with_inner_size(LogicalSize::new(1024, 768));
let (window, cfg) = glutin_winit::DisplayBuilder::new()
.with_window_builder(Some(window_builder))
.with_window_attributes(Some(window_attributes))
.build(&event_loop, ConfigTemplateBuilder::new(), |mut configs| {
configs.next().unwrap()
})
.expect("Failed to create OpenGL window");

let window = window.unwrap();

let context_attribs = ContextAttributesBuilder::new().build(Some(window.raw_window_handle()));
let context_attribs =
ContextAttributesBuilder::new().build(Some(window.window_handle().unwrap().as_raw()));
let context = unsafe {
cfg.display()
.create_context(&cfg, &context_attribs)
Expand All @@ -134,7 +136,7 @@ fn create_window() -> (
let surface_attribs = SurfaceAttributesBuilder::<WindowSurface>::new()
.with_srgb(Some(true))
.build(
window.raw_window_handle(),
window.window_handle().unwrap().as_raw(),
NonZeroU32::new(1024).unwrap(),
NonZeroU32::new(768).unwrap(),
);
Expand All @@ -161,7 +163,7 @@ fn imgui_init(window: &Window) -> (WinitPlatform, imgui::Context) {
let mut imgui_context = imgui::Context::create();
imgui_context.set_ini_filename(None);

let mut winit_platform = WinitPlatform::init(&mut imgui_context);
let mut winit_platform = WinitPlatform::new(&mut imgui_context);
winit_platform.attach_window(
imgui_context.io_mut(),
window,
Expand Down
1 change: 1 addition & 0 deletions examples/glow_02_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn main() {
let tri_renderer = Triangler::new(ig_renderer.gl_context(), "#version 330");

let mut last_frame = Instant::now();
#[allow(deprecated)]
event_loop
.run(move |event, window_target| {
match event {
Expand Down
1 change: 1 addition & 0 deletions examples/glow_03_triangle_gles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn main() {
let tri_renderer = Triangler::new(&gl, "#version 300 es\nprecision mediump float;");

let mut last_frame = Instant::now();
#[allow(deprecated)]
event_loop
.run(move |event, window_target| {
match event {
Expand Down
31 changes: 14 additions & 17 deletions examples/glow_04_custom_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn main() {
let textures_ui = TexturesUi::new(&gl, &mut textures);

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

struct TexturesUi {
generated_texture: imgui::TextureId,
lenna: SipiPng,
sipi: SipiPng,
}

impl TexturesUi {
fn new(gl: &glow::Context, textures: &mut imgui::Textures<glow::Texture>) -> Self {
Self {
generated_texture: Self::generate(gl, textures),
lenna: SipiPng::load(gl, textures),
sipi: SipiPng::load(gl, textures),
}
}

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

ui.text("Say hello to Lenna.jpg");
self.lenna.show(ui);
ui.text("Say hello to Peppers");
self.sipi.show(ui);

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

let draw_list = ui.get_window_draw_list();
draw_list
.add_image(
self.lenna.texture_id,
ui.item_rect_min(),
ui.item_rect_max(),
)
.add_image(self.sipi.texture_id, ui.item_rect_min(), ui.item_rect_max())
.col(tint)
.build();
}
Expand Down Expand Up @@ -232,7 +229,7 @@ impl TexturesUi {

let draw_list = ui.get_window_draw_list();
draw_list
.add_image_quad(self.lenna.texture_id, tl, tr, br, bl)
.add_image_quad(self.sipi.texture_id, tl, tr, br, bl)
.build();
}

Expand All @@ -244,7 +241,7 @@ impl TexturesUi {
let draw_list = ui.get_window_draw_list();
draw_list
.add_image_rounded(
self.lenna.texture_id,
self.sipi.texture_id,
ui.item_rect_min(),
ui.item_rect_max(),
16.0,
Expand All @@ -269,13 +266,13 @@ struct SipiPng {

impl SipiPng {
fn load(gl: &glow::Context, textures: &mut imgui::Textures<glow::Texture>) -> Self {
let lenna_image = image::io::Reader::new(Cursor::new(SIPI_PNG))
let sipi_png = image::io::Reader::new(Cursor::new(SIPI_PNG))
.with_guessed_format()
.unwrap()
.decode()
.expect("could not make decoder")
.to_rgba8();
let (width, height) = lenna_image.dimensions();
let (width, height) = sipi_png.dimensions();

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

Expand All @@ -294,13 +291,13 @@ impl SipiPng {
gl.tex_image_2d(
glow::TEXTURE_2D,
0,
glow::SRGB as _, // image file has sRGB encoded colors
glow::SRGB8_ALPHA8 as _, // image file has sRGB encoded colors
width as _,
height as _,
0,
glow::RGB,
glow::RGBA,
glow::UNSIGNED_BYTE,
Some(&lenna_image),
Some(&sipi_png),
)
}

Expand Down
1 change: 1 addition & 0 deletions examples/glow_05_framebufferobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn main() {
}));

let mut last_frame = Instant::now();
#[allow(deprecated)]
event_loop
.run(move |event, window_target| {
match event {
Expand Down
14 changes: 7 additions & 7 deletions examples/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use glutin::{
surface::{GlSurface, Surface, SurfaceAttributesBuilder, SwapInterval, WindowSurface},
};
use imgui_winit_support::WinitPlatform;
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::HasWindowHandle;
use winit::{
dpi::LogicalSize,
event_loop::EventLoop,
window::{Window, WindowBuilder},
window::{Window, WindowAttributes},
};

pub fn create_window(
Expand All @@ -26,11 +26,11 @@ pub fn create_window(
) {
let event_loop = EventLoop::new().unwrap();

let window_builder = WindowBuilder::new()
let window_attributes = WindowAttributes::default()
.with_title(title)
.with_inner_size(LogicalSize::new(1024, 768));
let (window, cfg) = glutin_winit::DisplayBuilder::new()
.with_window_builder(Some(window_builder))
.with_window_attributes(Some(window_attributes))
.build(&event_loop, ConfigTemplateBuilder::new(), |mut configs| {
configs.next().unwrap()
})
Expand All @@ -42,7 +42,7 @@ pub fn create_window(
if let Some(context_api) = context_api {
context_attribs = context_attribs.with_context_api(context_api);
}
let context_attribs = context_attribs.build(Some(window.raw_window_handle()));
let context_attribs = context_attribs.build(Some(window.window_handle().unwrap().as_raw()));
let context = unsafe {
cfg.display()
.create_context(&cfg, &context_attribs)
Expand All @@ -52,7 +52,7 @@ pub fn create_window(
let surface_attribs = SurfaceAttributesBuilder::<WindowSurface>::new()
.with_srgb(Some(true))
.build(
window.raw_window_handle(),
window.window_handle().unwrap().as_raw(),
NonZeroU32::new(1024).unwrap(),
NonZeroU32::new(768).unwrap(),
);
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn imgui_init(window: &Window) -> (WinitPlatform, imgui::Context) {
let mut imgui_context = imgui::Context::create();
imgui_context.set_ini_filename(None);

let mut winit_platform = WinitPlatform::init(&mut imgui_context);
let mut winit_platform = WinitPlatform::new(&mut imgui_context);
winit_platform.attach_window(
imgui_context.io_mut(),
window,
Expand Down

0 comments on commit 8996968

Please sign in to comment.