Implementation:Google deepmind Dm control GLFW Context
| Knowledge Sources | |
|---|---|
| Domains | Rendering, OpenGL |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
GLFWContext implements the GLFW-backed OpenGL rendering context for MuJoCo scene rendering, used on systems with display servers (typically desktop environments with GPUs).
Description
GLFWContext extends ContextBase and creates an invisible, non-double-buffered GLFW window as the OpenGL context surface. During initialization (_platform_init), it configures GLFW window hints to hide the window and disable double buffering, then creates a window of the specified maximum dimensions. The window is invisible and exists solely to provide an OpenGL context for offscreen rendering.
It always uses PassthroughRenderExecutor because GLFW must be called from the main thread. The _platform_make_current method activates the GLFW context, and _platform_free safely releases the context and destroys the window. A reference to glfw.destroy_window is stored to prevent it from being garbage-collected before the last window is destroyed. Import errors from the glfw module are re-raised as ImportError to enable clean fallback in the backend selection logic.
Usage
Use this context on desktop environments where a display server and GPU are available. This is the highest-priority rendering backend and provides hardware-accelerated OpenGL rendering for MuJoCo visualization and pixel-based observations.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/_render/glfw_renderer.py
- Lines: 1-68
Signature
class GLFWContext(base.ContextBase):
def __init__(self, max_width, max_height):
def _platform_init(self, max_width, max_height):
def _platform_make_current(self):
def _platform_free(self):
Import
from dm_control._render.glfw_renderer import GLFWContext
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| max_width | int | Yes | Maximum framebuffer width in pixels |
| max_height | int | Yes | Maximum framebuffer height in pixels |
Outputs
| Name | Type | Description |
|---|---|---|
| instance | GLFWContext | A fully initialized OpenGL context backed by an invisible GLFW window |
Usage Examples
from dm_control._render.glfw_renderer import GLFWContext
# Create a GLFW-backed OpenGL context
context = GLFWContext(max_width=1024, max_height=768)
# Use the context for rendering
with context.make_current() as ctx:
ctx.call(render_function, scene)
# Free when done
context.free()