PyOpenGL Documentation

repository·master·Indexed 19 days ago

https://github.com/mcfletch/pyopengl

Standard OpenGL bindings for Python. PyOpenGL provides an automated wrapper around Khronos XML definitions to produce the OpenGL API hierarchy, utilizing both autogenerated and secondary API wrappers. It is often used with PyOpenGL_accelerate for improved performance via C extensions.

Tokens
1.5K
Snippets
7
Records
10
Agent score
65%

What's inside PyOpenGL

  1. How PyOpenGL extensions are generated from Khronos XML

    master
    PyOpenGL is largely an automated wrapper around the Khronos XML definitions found in the official Khronos Registry. The generation process involves downloading the registry, building an index, and using ctypeslib with a custom OpenGLGenerator class to produce the OpenGL.raw hierarchy. This automation includes injecting common headers, customizing method generation to use platform.createBaseFunction, and emitting structured OpenGL.constant.Constant objects and array metadata decorations.
  2. Understand PyOpenGL wrapper hierarchies

    master

    PyOpenGL uses two main types of wrappers:

    1. Autogenerated Wrappers: These reside in the OpenGL/raw hierarchy and are derived directly from Khronos XML. They provide the base bindings.
    2. Secondary/API Wrappers: Located in OpenGL/$API hierarchies (e.g., OpenGL.GL), these are wrapper functions that implement logic for connections between arguments (e.g., ensuring a specific flag requires a specific parameter size). These modules often consist of autogenerated code supplemented by manually maintained bits to handle complex specifications that autogeneration cannot capture.
  3. Run the PyOpenGL test suite

    master

    The easiest way to run the test suite from a source-code checkout is using the uv runner with tox:

    $ uv run --with tox,tox-uv tox

    Prerequisites

    To run the tests, you need:

    • git
    • GLUT (FreeGLUT)
    • GLExtrusion library (libgle)
    • GLU
    • uv

    Test Suite Behavior

    • Windows/Display: The test suite opens many windows. On a desktop, this can make the machine difficult to interact with.
    • Parallelism: You can use tox -p for parallel runs, but be cautious as this can crash your desktop due to the number of windows being opened.
    • Wayland: The glfw window may not proceed if your Wayland session is locked.
  4. Generate PyOpenGL documentation using directdocs

    master

    To produce the PyOpenGL documentation set, you must have PyOpenGL already installed on your system. This process involves running a sequence of scripts that collect original documentation, samples, and references, and then generate HTML files. The output will be placed in a directory named manual-X.Y (where X.Y is the version number).

    ./acquireoriginal.py
    ./samples.py
    ./references.py 
    ./generate.py 
  5. Get started with PyOpenGL tutorials

    master

    If you are new to PyOpenGL, it is recommended to start with the OpenGLContext tutorials. These tutorials require the OpenGLContext package, which provides a high-level wrapper including a scenegraph engine and VRML97 parser.

    You can install it via pip:

    $ pip install "OpenGLContext-full==3.1.1"

    Alternatively, you can clone the openglcontext repository directly to access the tutorial sources.

  6. Install PyOpenGL and PyOpenGL_accelerate

    master

    You can install the packages via PyPI using pip:

    $ pip install PyOpenGL PyOpenGL_accelerate

    If you want to install from a local repository clone, run the following commands from the root of the repository:

    $ cd pyopengl
    $ pip install -e .
    $ cd accelerate
    $ pip install -e .

    Note: Compiling PyOpenGL_accelerate requires a functioning Python extension-compiling environment.

  7. Regenerate and update PyOpenGL modules

    master

    To update the PyOpenGL modules with the latest definitions from the Khronos registry, run the xml_generate.py script from the src directory. This script will clone or update the local Khronos registry checkout and parse the XML files to regenerate the OpenGL/raw hierarchy.

    cd src
    ./xml_generate.py
  8. Install PyOpenGL-accelerate

    master

    PyOpenGL-accelerate provides C (Cython) extensions that accelerate common operations in PyOpenGL 3.x. While it is not a strict requirement for using PyOpenGL, performance will be poor without it.

    Binary builds for most major platforms (Windows, Linux, Mac) are typically available via GitHub CI. If you need to build from source, you can do so from the PyOpenGL repository using pip install ..

    pip install .
  9. Configure test dwell time

    master
    You can control the inter-test pause (dwell time) by setting the TEST_DWELL environment variable to a floating point value. This is useful for controlling how long a window stays open before the next test begins. Note that this has no effect on headless runs (TEST_VISIBLE=false).
  10. Run PyOpenGL tests headlessly or with different windowing backends

    master

    You can configure how the test suite handles windowing and visibility using environment variables.

    Headless Mode

    To run tests without creating an on-screen display (improving speed and ergonomics), set TEST_VISIBLE=false:

    $ TEST_VISIBLE=false uv run --with tox,tox-uv tox

    Note: Some tests in test_checks.py may still run in a windowed mode.

    Windowing Backends (TEST_WINDOWING)

    The TEST_WINDOWING flag selects the backend for tests/gl, tests/gles, and tests/glu suites:

    VariableValueDescription
    TEST_WINDOWINGglfw(Default) Creates an on-screen window using GLFW.
    TEST_WINDOWINGpygameCreates an on-screen window using Pygame.
    TEST_WINDOWINGeglA headless backend that renders directly to a GPU via EGL_EXT_platform_device. Ideal for CI/Containers (e.g., NVIDIA container runtime).

    EGL Configuration

    When using TEST_WINDOWING=egl:

    • It forces PYOPENGL_PLATFORM=egl.
    • It serves both desktop OpenGL and OpenGL-ES contexts via an offscreen pbuffer.
    • TEST_VISIBLE and TEST_DWELL do not apply.
    • Use TEST_EGL_DEVICE=<n> to pin a specific EGL device index (defaults to the first non-software device).
    # Run headlessly
    $ TEST_VISIBLE=false uv run --with tox,tox-uv tox
    
    # Run using EGL (Headless/CI)
    $ TEST_WINDOWING=egl uv run --with tox,tox-uv tox
    
    # Run using Pygame
    $ TEST_WINDOWING=pygame uv run --with tox,tox-uv tox