{"id":5942,"library":"glcontext","title":"glcontext","description":"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.","status":"active","version":"3.0.0","language":"en","source_language":"en","source_url":"https://github.com/moderngl/glcontext","tags":["opengl","graphics","headless","context"],"install":[{"cmd":"pip install glcontext","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"`headless_context` was removed and renamed to `create_context` in version 3.0.0. The `standalone` argument is now used to specify a standalone context.","wrong":"from glcontext import headless_context","symbol":"create_context","correct":"from glcontext import create_context"}],"quickstart":{"code":"import glcontext\n\n# Create a headless OpenGL context using the standalone backend.\n# This is the recommended way for most headless environments.\n# Other backends like 'egl', 'osmesa', 'wgl', 'glx' can be specified\n# via the 'backend' argument, e.g., create_context(backend='egl')\ntry:\n    ctx = glcontext.create_context(standalone=True)\n    print(f\"Successfully created glcontext: {ctx}\")\n    print(f\"OpenGL Version: {ctx.version_string}\")\n    # The context is now available for OpenGL operations.\n    # For example, if using with moderngl:\n    # ctx.make_current()\n    # import moderngl\n    # mgl_ctx = moderngl.create_context(require=ctx.version_code)\n    # print(f\"ModernGL context created with version: {mgl_ctx.version_code}\")\n    ctx.release() # Release the context when done\nexcept Exception as e:\n    print(f\"Failed to create glcontext: {e}\")\n    print(\"Ensure appropriate OpenGL drivers or Mesa libraries are installed for headless operation.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Replace calls to `glcontext.headless_context()` with `glcontext.create_context(standalone=True)`.","message":"The `glcontext.headless_context` function was removed and replaced by `glcontext.create_context`. To create a standalone headless context, use `create_context(standalone=True)`.","severity":"breaking","affected_versions":"3.0.0 and newer"},{"fix":"Ensure your system has the necessary OpenGL drivers and libraries (e.g., Mesa for `osmesa`, appropriate vendor drivers for `egl`/`glx`) installed and accessible. Check `glcontext.available` for supported backends before attempting to create a context.","message":"Context creation can fail if the required OpenGL drivers or backend libraries (e.g., EGL, OSMesa, GLX) are not available or correctly configured on the system. Error messages can sometimes be generic or misleading.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always call `ctx.release()` on the `Context` object when you are finished with it to free up underlying system resources.","message":"Not explicitly releasing OpenGL contexts can lead to resource leaks, especially in applications that create and destroy many contexts or run for extended periods.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}