ModernGL

5.12.0 · active · verified Tue Apr 14

ModernGL is a high-performance Python wrapper over OpenGL Core, simplifying the creation of graphics applications like scientific simulations, games, or user interfaces. It aims to provide a more Pythonic and less boilerplate-heavy API compared to direct OpenGL bindings like PyOpenGL. The current stable version is 5.12.0, with releases occurring periodically, often including breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a ModernGL context (headless in this example), allocating a buffer on the GPU, writing data to it, and reading it back. For graphical applications, `moderngl.create_context()` would typically be called after setting up a window with an OpenGL-capable library.

import moderngl

# Create a headless context or attach to an existing one
# For a windowed application, ctx = moderngl.create_context()
# after a window is created by a library like Pygame, GLFW, etc.
ctx = moderngl.create_context(standalone=True)

# Create a buffer on the GPU
buf = ctx.buffer(b"Hello ModernGL World!")

# Read data back from the buffer
print(buf.read())

# Release resources (important for standalone contexts)
# For windowed contexts, resource management is often handled by the windowing library.
ctx.release()

view raw JSON →