glcontext

3.0.0 · active · verified Tue Apr 14

glcontext is a Python library providing portable headless OpenGL context creation, making it possible to run OpenGL applications without a display server or window. It supports various backends like standalone, EGL, OSMesa, WGL, and GLX. The current version is 3.0.0, with a release cadence tied to the moderngl ecosystem and bug fixes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a basic headless OpenGL context using the `create_context` function and the `standalone=True` argument. It also shows how to retrieve basic context information and correctly release resources.

import glcontext

# Create a headless OpenGL context using the standalone backend.
# This is the recommended way for most headless environments.
# Other backends like 'egl', 'osmesa', 'wgl', 'glx' can be specified
# via the 'backend' argument, e.g., create_context(backend='egl')
try:
    ctx = glcontext.create_context(standalone=True)
    print(f"Successfully created glcontext: {ctx}")
    print(f"OpenGL Version: {ctx.version_string}")
    # The context is now available for OpenGL operations.
    # For example, if using with moderngl:
    # ctx.make_current()
    # import moderngl
    # mgl_ctx = moderngl.create_context(require=ctx.version_code)
    # print(f"ModernGL context created with version: {mgl_ctx.version_code}")
    ctx.release() # Release the context when done
except Exception as e:
    print(f"Failed to create glcontext: {e}")
    print("Ensure appropriate OpenGL drivers or Mesa libraries are installed for headless operation.")

view raw JSON →