-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2af2e8b
commit f98ed1d
Showing
13 changed files
with
1,685 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changelog for egui_glow | ||
All notable changes to the `egui_glow` integration will be noted in this file. | ||
|
||
|
||
## Unreleased | ||
`egui_glow` has been newly created, with feature parity to `egui_glium`. | ||
As `glow` is a set of lower-level bindings to OpenGL, this crate could more unstable than `egui_glium`, | ||
but there are no known issues, and the crate will only become more stable over time, if any issues manifest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[package] | ||
name = "egui_glow" | ||
version = "0.14.0" | ||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"] | ||
description = "Bindings for using egui natively using the glow library" | ||
edition = "2018" | ||
homepage = "https://github.com/emilk/egui/tree/master/egui_glow" | ||
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
repository = "https://github.com/emilk/egui/tree/master/egui_glow" | ||
categories = ["gui", "game-development"] | ||
keywords = ["glow", "egui", "gui", "gamedev"] | ||
include = [ | ||
"../LICENSE-APACHE", | ||
"../LICENSE-MIT", | ||
"**/*.rs", | ||
"Cargo.toml", | ||
"src/shader/*.glsl", | ||
] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
|
||
[dependencies] | ||
egui = { version = "0.14.0", path = "../egui", default-features = false, features = ["single_threaded"] } | ||
egui-winit = { version = "0.14.0", path = "../egui-winit", default-features = false } | ||
epi = { version = "0.14.0", path = "../epi" } | ||
glutin = "0.27" | ||
glow = "0.11" | ||
memoffset = "0.6" | ||
|
||
# feature "persistence": | ||
directories-next = { version = "2", optional = true } | ||
ron = { version = "0.6", optional = true } | ||
serde = { version = "1", optional = true } | ||
|
||
# feature "time" | ||
chrono = { version = "0.4", optional = true } | ||
|
||
[dev-dependencies] | ||
image = { version = "0.23", default-features = false, features = ["png"] } | ||
|
||
[features] | ||
default = ["clipboard", "default_fonts", "links"] | ||
|
||
# enable cut/copy/paste to OS clipboard. | ||
# if disabled a clipboard will be simulated so you can still copy/paste within the egui app. | ||
clipboard = ["egui-winit/clipboard"] | ||
|
||
# If set, egui will use `include_bytes!` to bundle some fonts. | ||
# If you plan on specifying your own fonts you may disable this feature. | ||
default_fonts = ["egui/default_fonts"] | ||
|
||
# enable opening links in a browser when an egui hyperlink is clicked. | ||
links = ["egui-winit/links"] | ||
|
||
persistence = [ | ||
"directories-next", | ||
"egui-winit/serialize", | ||
"egui/persistence", | ||
"epi/persistence", | ||
"ron", | ||
"serde", | ||
] | ||
|
||
# experimental support for a screen reader | ||
screen_reader = ["egui-winit/screen_reader"] | ||
|
||
# for seconds_since_midnight (used in egui_demo_lib) | ||
time = ["chrono"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# egui_glow | ||
|
||
[](https://crates.io/crates/egui_glow) | ||
[](https://docs.rs/egui_glow) | ||
 | ||
 | ||
|
||
This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [glow](https://crates.io/crates/glow) which allows you to write GUI code using egui and compile it and run it natively, cross platform. | ||
|
||
To use on Linux, first run: | ||
|
||
``` | ||
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev | ||
``` | ||
|
||
This crate depends on [`egui-winit`](https://github.com/emilk/egui/tree/master/egui-winit). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
//! Example how to use pure `egui_glow` without [`epi`]. | ||
fn create_display( | ||
event_loop: &glutin::event_loop::EventLoop<()>, | ||
) -> ( | ||
glutin::WindowedContext<glutin::PossiblyCurrent>, | ||
glow::Context, | ||
) { | ||
let window_builder = glutin::window::WindowBuilder::new() | ||
.with_resizable(true) | ||
.with_inner_size(glutin::dpi::LogicalSize { | ||
width: 800.0, | ||
height: 600.0, | ||
}) | ||
.with_title("egui_glow example"); | ||
|
||
let gl_window = unsafe { | ||
glutin::ContextBuilder::new() | ||
.with_depth_buffer(0) | ||
.with_srgb(true) | ||
.with_stencil_buffer(0) | ||
.with_vsync(true) | ||
.build_windowed(window_builder, event_loop) | ||
.unwrap() | ||
.make_current() | ||
.unwrap() | ||
}; | ||
|
||
let gl = unsafe { glow::Context::from_loader_function(|s| gl_window.get_proc_address(s)) }; | ||
|
||
unsafe { | ||
use glow::HasContext; | ||
gl.enable(glow::FRAMEBUFFER_SRGB); | ||
} | ||
|
||
(gl_window, gl) | ||
} | ||
|
||
fn main() { | ||
let event_loop = glutin::event_loop::EventLoop::with_user_event(); | ||
let (gl_window, gl) = create_display(&event_loop); | ||
|
||
let mut egui = egui_glow::EguiGlow::new(&gl_window, &gl); | ||
|
||
event_loop.run(move |event, _, control_flow| { | ||
let mut redraw = || { | ||
egui.begin_frame(gl_window.window()); | ||
|
||
let mut quit = false; | ||
|
||
egui::SidePanel::left("my_side_panel").show(egui.ctx(), |ui| { | ||
ui.heading("Hello World!"); | ||
if ui.button("Quit").clicked() { | ||
quit = true; | ||
} | ||
|
||
egui::ComboBox::from_label("Version") | ||
.width(150.0) | ||
.selected_text("foo") | ||
.show_ui(ui, |ui| { | ||
egui::CollapsingHeader::new("Dev") | ||
.default_open(true) | ||
.show(ui, |ui| { | ||
ui.label("contents"); | ||
}); | ||
}); | ||
}); | ||
|
||
let (needs_repaint, shapes) = egui.end_frame(gl_window.window()); | ||
|
||
*control_flow = if quit { | ||
glutin::event_loop::ControlFlow::Exit | ||
} else if needs_repaint { | ||
gl_window.window().request_redraw(); | ||
glutin::event_loop::ControlFlow::Poll | ||
} else { | ||
glutin::event_loop::ControlFlow::Wait | ||
}; | ||
|
||
{ | ||
let clear_color = egui::Rgba::from_rgb(0.1, 0.3, 0.2); | ||
unsafe { | ||
use glow::HasContext; | ||
gl.clear_color( | ||
clear_color[0], | ||
clear_color[1], | ||
clear_color[2], | ||
clear_color[3], | ||
); | ||
gl.clear(glow::COLOR_BUFFER_BIT); | ||
} | ||
|
||
// draw things behind egui here | ||
|
||
egui.paint(&gl_window, &gl, shapes); | ||
|
||
// draw things on top of egui here | ||
|
||
gl_window.swap_buffers().unwrap(); | ||
} | ||
}; | ||
|
||
match event { | ||
// Platform-dependent event handlers to workaround a winit bug | ||
// See: https://github.com/rust-windowing/winit/issues/987 | ||
// See: https://github.com/rust-windowing/winit/issues/1619 | ||
glutin::event::Event::RedrawEventsCleared if cfg!(windows) => redraw(), | ||
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(), | ||
|
||
glutin::event::Event::WindowEvent { event, .. } => { | ||
if egui.is_quit_event(&event) { | ||
*control_flow = glutin::event_loop::ControlFlow::Exit; | ||
} | ||
|
||
if let glutin::event::WindowEvent::Resized(physical_size) = event { | ||
gl_window.resize(physical_size); | ||
} | ||
|
||
egui.on_event(&event); | ||
|
||
gl_window.window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead | ||
} | ||
glutin::event::Event::LoopDestroyed => { | ||
egui.destroy(&gl); | ||
} | ||
|
||
_ => (), | ||
} | ||
}); | ||
} |
Oops, something went wrong.