Crate imgui_glfw_rs

Crate imgui_glfw_rs 

Source
Expand description

ImGui input handling for Glfw.

§Example use

You can run this example with cargo run --example hello_world

use glfw::Context;
use imgui::Context as ImContext;
use imgui_glfw_rs::ImguiGLFW;
use imgui_glfw_rs::glfw;
use imgui_glfw_rs::imgui;
fn main() {
    let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
    glfw.window_hint(glfw::WindowHint::ContextVersion(3, 3));
    let (mut window, events) = glfw
        .create_window(
            1024,
            768,
            "imgui-glfw-rs example",
            glfw::WindowMode::Windowed,
        )
        .expect("Failed to create window");
    window.make_current();
    window.set_all_polling(true);
    gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
    unsafe {
        gl::Enable(gl::BLEND);
        gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
        gl::Enable(gl::DEPTH_TEST);
        gl::DepthFunc(gl::LESS);
        gl::ClearColor(0.1, 0.1, 0.1, 1.0);
    }
    let mut imgui = ImContext::create();
    imgui
        .fonts()
        .add_font(&[imgui::FontSource::DefaultFontData { config: None }]);
    if !imgui.fonts().is_built() {
        println!("NO FONTS BUILD");
    } else {
        println!("BUILD");
    }
    let mut imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window);
    while !window.should_close() {
        unsafe {
            gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
        }
        let ui = imgui_glfw.frame(&mut window, &mut imgui);
        ui.show_demo_window(&mut true);
        imgui_glfw.draw(&mut imgui, &mut window);
        window.swap_buffers();
        glfw.poll_events();
        for (_, event) in glfw::flush_messages(&events) {
            imgui_glfw.handle_event(&mut imgui, &event);
        }
    }
}

Re-exports§

pub use glfw;
pub use imgui;

Structs§

ImguiGLFW