Skip to content

Commit 3633a2d

Browse files
committed
Add egui_glow backend as alternative to egui_glium
1 parent 2af2e8b commit 3633a2d

File tree

13 files changed

+1685
-3
lines changed

13 files changed

+1685
-3
lines changed

ARCHITECTURE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Puts an egui app inside the web browser by compiling to WASM and binding to the
3636
### `egui_glium`
3737
Puts an egui app inside a native window on your laptop. Paints the triangles that egui outputs using [glium](https://github.com/glium/glium).
3838

39+
### `egui_glow`
40+
Puts an egui app inside a native window on your laptop. Paints the triangles that egui outputs using [glow](https://github.com/grovesNL/glow).
41+
An alternative to `egui_glium`, not used by `eframe` at this time.
42+
3943
### `eframe`
4044
A wrapper around `egui_web` + `egui_glium`, so you can compile the same app for either web or native.
4145

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ The integration needs to do two things:
163163

164164
### Official
165165

166-
I maintain two official egui integrations made for apps:
166+
There are three official egui integrations made for apps:
167167

168168
* [`egui_web`](https://github.com/emilk/egui/tree/master/egui_web) for making a web app. Compiles to WASM, renders with WebGL. [Click to run the egui demo](https://emilk.github.io/egui/index.html).
169169
* [`egui_glium`](https://github.com/emilk/egui/tree/master/egui_glium) for compiling native apps with [Glium](https://github.com/glium/glium).
170-
* [`egui-winit`](https://github.com/emilk/egui/tree/master/egui-winit) for integrating with [`winit`](https://github.com/rust-windowing/winit). `egui-winit` is used by `egui_glium`.
170+
* [`egui_glow`](https://github.com/emilk/egui/tree/master/egui_glow) for compiling native apps with [Glow](https://github.com/grovesNL/glow).
171+
* [`egui-winit`](https://github.com/emilk/egui/tree/master/egui-winit) for integrating with [`winit`](https://github.com/rust-windowing/winit). `egui-winit` is used by `egui_glium` and `egui_glow`.
171172

172173
If you making an app, consider using [`eframe`](https://github.com/emilk/egui/tree/master/eframe), a framework which allows you to write code that works on both the web (`egui_web`) and native (using `egui_glium`).
173174

@@ -211,7 +212,7 @@ loop {
211212
}
212213
```
213214

214-
For a reference OpenGL backend, see [the `egui_glium` painter](https://github.com/emilk/egui/blob/master/egui_glium/src/painter.rs) or [the `egui_web` `WebGL` painter](https://github.com/emilk/egui/blob/master/egui_web/src/webgl1.rs).
215+
For a reference OpenGL backend, see [the `egui_glium` painter](https://github.com/emilk/egui/blob/master/egui_glium/src/painter.rs), [the `egui_glow` painter](https://github.com/emilk/egui/blob/master/egui_glow/src/painter.rs), or [the `egui_web` `WebGL` painter](https://github.com/emilk/egui/blob/master/egui_web/src/webgl1.rs).
215216

216217
### Debugging your integration
217218

eframe/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ NOTE: [`egui_web`](egui_web/CHANGELOG.md), [`egui-winit`](egui-winit/CHANGELOG.m
99
* Remove "http" feature (use https://github.com/emilk/ehttp instead!).
1010
* Increase native scroll speed.
1111
* Add `App::persist_native_window` and `App::persist_egui_memory` to control what gets persisted.
12+
* Add new backend `egui_glow` as an alternative to `egui_glium` (not yet exposed as a feature flag)
1213

1314

1415
## 0.14.0 - 2021-08-24

egui_glow/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog for egui_glow
2+
All notable changes to the `egui_glow` integration will be noted in this file.
3+
4+
5+
## Unreleased
6+
`egui_glow` has been newly created, with feature parity to `egui_glium`.
7+
As `glow` is a set of lower-level bindings to OpenGL, this crate is potentially less stable than `egui_glium`,
8+
but there are no known issues, and the crate will only become more stable over time, if any issues manifest.

egui_glow/Cargo.toml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[package]
2+
name = "egui_glow"
3+
version = "0.14.0"
4+
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
5+
description = "Bindings for using egui natively using the glow library"
6+
edition = "2018"
7+
homepage = "https://github.com/emilk/egui/tree/master/egui_glow"
8+
license = "MIT OR Apache-2.0"
9+
readme = "README.md"
10+
repository = "https://github.com/emilk/egui/tree/master/egui_glow"
11+
categories = ["gui", "game-development"]
12+
keywords = ["glow", "egui", "gui", "gamedev"]
13+
include = [
14+
"../LICENSE-APACHE",
15+
"../LICENSE-MIT",
16+
"**/*.rs",
17+
"Cargo.toml",
18+
"src/shader/*.glsl",
19+
]
20+
21+
[package.metadata.docs.rs]
22+
all-features = true
23+
24+
[dependencies]
25+
egui = { version = "0.14.0", path = "../egui", default-features = false, features = ["single_threaded"] }
26+
egui-winit = { version = "0.14.0", path = "../egui-winit", default-features = false }
27+
epi = { version = "0.14.0", path = "../epi" }
28+
glutin = "0.27"
29+
glow = "0.11"
30+
memoffset = "0.6"
31+
32+
# feature "persistence":
33+
directories-next = { version = "2", optional = true }
34+
ron = { version = "0.6", optional = true }
35+
serde = { version = "1", optional = true }
36+
37+
# feature "time"
38+
chrono = { version = "0.4", optional = true }
39+
40+
[dev-dependencies]
41+
image = { version = "0.23", default-features = false, features = ["png"] }
42+
43+
[features]
44+
default = ["clipboard", "default_fonts", "links"]
45+
46+
# enable cut/copy/paste to OS clipboard.
47+
# if disabled a clipboard will be simulated so you can still copy/paste within the egui app.
48+
clipboard = ["egui-winit/clipboard"]
49+
50+
# If set, egui will use `include_bytes!` to bundle some fonts.
51+
# If you plan on specifying your own fonts you may disable this feature.
52+
default_fonts = ["egui/default_fonts"]
53+
54+
# enable opening links in a browser when an egui hyperlink is clicked.
55+
links = ["egui-winit/links"]
56+
57+
persistence = [
58+
"directories-next",
59+
"egui-winit/serialize",
60+
"egui/persistence",
61+
"epi/persistence",
62+
"ron",
63+
"serde",
64+
]
65+
66+
# experimental support for a screen reader
67+
screen_reader = ["egui-winit/screen_reader"]
68+
69+
# for seconds_since_midnight (used in egui_demo_lib)
70+
time = ["chrono"]

egui_glow/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# egui_glow
2+
3+
[![Latest version](https://img.shields.io/crates/v/egui_glow.svg)](https://crates.io/crates/egui_glow)
4+
[![Documentation](https://docs.rs/egui_glow/badge.svg)](https://docs.rs/egui_glow)
5+
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
6+
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)
7+
8+
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.
9+
10+
To use on Linux, first run:
11+
12+
```
13+
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libssl-dev
14+
```
15+
16+
This crate depends on [`egui-winit`](https://github.com/emilk/egui/tree/master/egui-winit).

egui_glow/examples/pure.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
//! Example how to use pure `egui_glow` without [`epi`].
2+
3+
fn create_display(
4+
event_loop: &glutin::event_loop::EventLoop<()>,
5+
) -> (
6+
glutin::WindowedContext<glutin::PossiblyCurrent>,
7+
glow::Context,
8+
) {
9+
let window_builder = glutin::window::WindowBuilder::new()
10+
.with_resizable(true)
11+
.with_inner_size(glutin::dpi::LogicalSize {
12+
width: 800.0,
13+
height: 600.0,
14+
})
15+
.with_title("egui_glow example");
16+
17+
let gl_window = unsafe {
18+
glutin::ContextBuilder::new()
19+
.with_depth_buffer(0)
20+
.with_srgb(true)
21+
.with_stencil_buffer(0)
22+
.with_vsync(true)
23+
.build_windowed(window_builder, event_loop)
24+
.unwrap()
25+
.make_current()
26+
.unwrap()
27+
};
28+
29+
let gl = unsafe { glow::Context::from_loader_function(|s| gl_window.get_proc_address(s)) };
30+
31+
unsafe {
32+
use glow::HasContext;
33+
gl.enable(glow::FRAMEBUFFER_SRGB);
34+
}
35+
36+
(gl_window, gl)
37+
}
38+
39+
fn main() {
40+
let event_loop = glutin::event_loop::EventLoop::with_user_event();
41+
let (gl_window, gl) = create_display(&event_loop);
42+
43+
let mut egui = egui_glow::EguiGlow::new(&gl_window, &gl);
44+
45+
event_loop.run(move |event, _, control_flow| {
46+
let mut redraw = || {
47+
egui.begin_frame(gl_window.window());
48+
49+
let mut quit = false;
50+
51+
egui::SidePanel::left("my_side_panel").show(egui.ctx(), |ui| {
52+
ui.heading("Hello World!");
53+
if ui.button("Quit").clicked() {
54+
quit = true;
55+
}
56+
57+
egui::ComboBox::from_label("Version")
58+
.width(150.0)
59+
.selected_text("foo")
60+
.show_ui(ui, |ui| {
61+
egui::CollapsingHeader::new("Dev")
62+
.default_open(true)
63+
.show(ui, |ui| {
64+
ui.label("contents");
65+
});
66+
});
67+
});
68+
69+
let (needs_repaint, shapes) = egui.end_frame(gl_window.window());
70+
71+
*control_flow = if quit {
72+
glutin::event_loop::ControlFlow::Exit
73+
} else if needs_repaint {
74+
gl_window.window().request_redraw();
75+
glutin::event_loop::ControlFlow::Poll
76+
} else {
77+
glutin::event_loop::ControlFlow::Wait
78+
};
79+
80+
{
81+
let clear_color = egui::Rgba::from_rgb(0.1, 0.3, 0.2);
82+
unsafe {
83+
use glow::HasContext;
84+
gl.clear_color(
85+
clear_color[0],
86+
clear_color[1],
87+
clear_color[2],
88+
clear_color[3],
89+
);
90+
gl.clear(glow::COLOR_BUFFER_BIT);
91+
}
92+
93+
// draw things behind egui here
94+
95+
egui.paint(&gl_window, &gl, shapes);
96+
97+
// draw things on top of egui here
98+
99+
gl_window.swap_buffers().unwrap();
100+
}
101+
};
102+
103+
match event {
104+
// Platform-dependent event handlers to workaround a winit bug
105+
// See: https://github.com/rust-windowing/winit/issues/987
106+
// See: https://github.com/rust-windowing/winit/issues/1619
107+
glutin::event::Event::RedrawEventsCleared if cfg!(windows) => redraw(),
108+
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(),
109+
110+
glutin::event::Event::WindowEvent { event, .. } => {
111+
if egui.is_quit_event(&event) {
112+
*control_flow = glutin::event_loop::ControlFlow::Exit;
113+
}
114+
115+
if let glutin::event::WindowEvent::Resized(physical_size) = event {
116+
gl_window.resize(physical_size);
117+
}
118+
119+
egui.on_event(&event);
120+
121+
gl_window.window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead
122+
}
123+
glutin::event::Event::LoopDestroyed => {
124+
egui.destroy(&gl);
125+
}
126+
127+
_ => (),
128+
}
129+
});
130+
}

0 commit comments

Comments
 (0)