Pyodide-only WebGL bridge for imgui_bundle.
Available only in Pyodide builds (compile-time gated by
IMGUI_BUNDLE_WITH_WEBGL). On desktop, importing this submodule raises
ImportError; gate with imgui_bundle.has_submodule("webgl").
Typical usage:
import imgui_bundle
if imgui_bundle.has_submodule("webgl"):
from imgui_bundle import webgl
from js import document
gl = document.getElementById("canvas").getContext("webgl2")
tex = gl.createTexture()
# ... populate the texture via WebGL ...
tex_id = webgl.register_texture(tex)
# ... in the GUI loop ...
imgui.image(imgui.ImTextureRef(tex_id), ImVec2(256, 256))
# ... at shutdown ...
webgl.unregister_texture(tex_id)
gl.deleteTexture(tex)See _plans/pyodide_webgl_bridge__spec.md for the design rationale.
Upstream repository · The book’s page
Modules¶
In imgui_bundle (from imgui_bundle import webgl):
webgl: 2 functions, 0 classes, 0 enums
Demos using it¶
The demos of the catalog that use it (the pictures link to their code and to the playground).

WebGL shader as background¶
The Mandelbrot set, drawn by a fragment shader behind the GUI.
More
Pyodide only: this demo calls the browser’s WebGL2 API directly, through Python’s js interop. On desktop, you would use PyOpenGL instead.
Browser only
Uses: browser APIs

WebGL / OpenGL custom background¶
One source file, two platforms: a shader behind the GUI, with OpenGL on desktop and WebGL in the browser.
More
Uses: OpenGL, browser APIs

WebAudio synthesizer¶
A small synthesizer written in Python: play the piano with the mouse or the computer keyboard, or let it play a tune.
More
Pick a waveform, add some echo, and watch the scope. Pyodide only: it plays through the browser’s WebAudio API, via Pyodide’s js interop.
Browser only
Uses: knobs, browser APIs
