Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add egui_glow backend as alternative to egui_glium #685

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Puts an egui app inside the web browser by compiling to WASM and binding to the
### `egui_glium`
Puts an egui app inside a native window on your laptop. Paints the triangles that egui outputs using [glium](https://github.com/glium/glium).

### `egui_glow`
Puts an egui app inside a native window on your laptop. Paints the triangles that egui outputs using [glow](https://github.com/grovesNL/glow).
An alternative to `egui_glium`, not used by `eframe` at this time.

### `eframe`
A wrapper around `egui_web` + `egui_glium`, so you can compile the same app for either web or native.

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ The integration needs to do two things:

### Official

I maintain two official egui integrations made for apps:
There are three official egui integrations made for apps:

* [`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).
* [`egui_glium`](https://github.com/emilk/egui/tree/master/egui_glium) for compiling native apps with [Glium](https://github.com/glium/glium).
* [`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`.
* [`egui_glow`](https://github.com/emilk/egui/tree/master/egui_glow) for compiling native apps with [Glow](https://github.com/grovesNL/glow).
* [`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`.

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`).

Expand Down Expand Up @@ -211,7 +212,7 @@ loop {
}
```

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).
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).

### Debugging your integration

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


## 0.14.0 - 2021-08-24
Expand Down
8 changes: 8 additions & 0 deletions egui_glow/CHANGELOG.md
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 is potentially less stable than `egui_glium`,
but there are no known issues, and the crate will only become more stable over time, if any issues manifest.
70 changes: 70 additions & 0 deletions egui_glow/Cargo.toml
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 <[email protected]>"]
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"]
16 changes: 16 additions & 0 deletions egui_glow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# egui_glow

[![Latest version](https://img.shields.io/crates/v/egui_glow.svg)](https://crates.io/crates/egui_glow)
[![Documentation](https://docs.rs/egui_glow/badge.svg)](https://docs.rs/egui_glow)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

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).
130 changes: 130 additions & 0 deletions egui_glow/examples/pure.rs
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);
}

_ => (),
}
});
}
Loading