moderngl-window is a cross-platform helper library for ModernGL, simplifying window creation and resource loading for OpenGL applications. It provides a unified API over various windowing backends like Pyglet, GLFW, and SDL2. The library is actively maintained with frequent updates, currently at version 3.1.1, ensuring compatibility and introducing new features.
pip install moderngl-windowVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a basic window by extending `moderngl_window.WindowConfig`. It sets up an OpenGL 3.3 context, specifies window dimensions and title, and provides a minimal `on_render` method to clear the screen with a red color. The `run()` method then starts the window's event loop.
Rename methods such as `render` to `on_render`, `resize` to `on_resize`, `key_event` to `on_key_event`, etc.
Set `resource_dir = Path(__file__).parent / "resources"` in your `WindowConfig` subclass or explicitly register resource directories using `moderngl_window.resources.register_dir('path/to/my/resources')`.Rely on `WindowConfig` to manage the OpenGL context (accessible via `self.ctx`). If explicit context control is needed, consider using `moderngl_window.create_window_from_settings()` or lower-level window APIs.
Rename the method `render` to `on_render`. Apply this `on_` prefix to all other callback methods like `resize`, `key_event`, etc.
Install the `moderngl` library: `pip install moderngl`.
Ensure `self.resource_dir` is correctly set in your `WindowConfig` to point to the directory containing your resources, or provide an absolute path to `self.load_program()`/`self.load_texture_2d()`. For example, `resource_dir = Path(__file__).parent.resolve() / "resources"`.