A new platform back-end, similar to imgui_impl_glfw, removing any dependency on GLFW, for use when building with Emscripten running in a web browser. Instead of using Emscripten's GLFW compatibility wrapper for input to imgui, it uses Emscripten's HTML5 API directly.
Motivation
The primary motivation for this is the development of WebGPU, and relative obsolescence of GLFW in that context.
Imgui has a rendering backend which allows one to build web applications with Emscripten rendering with WebGPU instead of WebGL. When rendering with WebGPU instead of WebGL, most of GLFW's functionality is no longer required. However, GLFW remains the standard way of processing input for imgui when running on web, building with Emscripten. The version of GLFW shipped with Emscripten is actually a compatibility wrapper around the HTML5 javascript API, so when the imgui_impl_glfw platform backend creates its callbacks to pass data to imgui, it adds another layer of translation and indirection from the underlying API itself, which isn't really necessary.
This platform backend seeks to replace the GLFW backend when building with Emscripten for the web, in situations where rendering with WebGL is not necessary - either when rendering with WebGPU, or other hypothetical rendering backends.
What's added
The proposed imgui_impl_emscripten backend uses Emscripten's HTML5 API to set callbacks directly, to trigger relevant state changes in imgui:
Keyboard input
Window resizing
Cursor position
Cursor enters and leaves the window
Application focus
Browser cursors (native browser cursor changes using a cut-down version of my emscripten-browser-cursor library)
What is omitted
Anything render-related. You would typically use this alongside a rendering backend like imgui_impl_wgpu.
Touch event support. At the moment I don't have a mobile device with touch support capable of running a version of any browser that supports WebGPU on mobile devices, so this isn't something I can currently test. I'll aim to add this as support for WebGPU develops.
Gamepad support. This is by design; any application that wants to pass input to imgui with a gamepad is certainly also going to want to process gamepad input for its own purposes, so processing this input twice is just going to add inefficiency. Additionally, every application will want different ways to handle deadzones, saturation, analogue input curves, and selecting one out of multiple gamepads for input at any given time. Instead of attempting to handle any of that in this backend, an external example is provided for how to use the Emscripten HTML5 gamepad API to collect both in-game events and pass controls to imgui: https://github.com/Armchair-Software/webgpu-demo2/blob/master/main.cpp#L113
What is it?
A new platform back-end, similar to
imgui_impl_glfw
, removing any dependency on GLFW, for use when building with Emscripten running in a web browser. Instead of using Emscripten's GLFW compatibility wrapper for input to imgui, it uses Emscripten's HTML5 API directly.Motivation
The primary motivation for this is the development of WebGPU, and relative obsolescence of GLFW in that context.
Imgui has a rendering backend which allows one to build web applications with Emscripten rendering with WebGPU instead of WebGL. When rendering with WebGPU instead of WebGL, most of GLFW's functionality is no longer required. However, GLFW remains the standard way of processing input for imgui when running on web, building with Emscripten. The version of GLFW shipped with Emscripten is actually a compatibility wrapper around the HTML5 javascript API, so when the
imgui_impl_glfw
platform backend creates its callbacks to pass data to imgui, it adds another layer of translation and indirection from the underlying API itself, which isn't really necessary.This platform backend seeks to replace the GLFW backend when building with Emscripten for the web, in situations where rendering with WebGL is not necessary - either when rendering with WebGPU, or other hypothetical rendering backends.
What's added
The proposed
imgui_impl_emscripten
backend uses Emscripten's HTML5 API to set callbacks directly, to trigger relevant state changes in imgui:What is omitted
imgui_impl_wgpu
.Demo