Skip to main content

preview

ModernGL

pip install moderngl

Features

  • GPU accelerated high quality graphics
  • Rendering modern OpenGL scenes with less headache
  • Simpler and faster than PyOpenGL
  • Can render without a window
  • 100% Pythonic

Sample usage

>>> import moderngl
>>> ctx = moderngl.create_standalone_context()
>>> buf = ctx.buffer(b'Hello World!')  # allocated on the GPU
>>> buf.read()
b'Hello World!'

For complete examples please visit the Examples.

Easy to use with Pillow and Numpy

>>> img = Image.open('texture.jpg')
>>> ctx.texture(img.size, 3, img.tobytes())
<Texture: 1>
>>> ctx.buffer(np.array([0.0, 0.0, 1.0, 1.0], dtype='f4'))
<Buffer: 1>

Compared to PyOpenGL

With PyOpenGL, using the original OpenGL API, you have to write three lines to achieve a simple task like binding a VBO:

vbo1 = glGenBuffers(1)
GL.glBindBuffer(GL_ARRAY_BUFFER, vbo1)
GL.glBufferData(GL_ARRAY_BUFFER, b'Hello World!', GL_STATIC_DRAW)

vbo2 = glGenBuffers(1)
GL.glBindBuffer(GL_ARRAY_BUFFER, vbo2)
GL.glBufferData(GL_ARRAY_BUFFER, b'\x00' * 1024, GL_DYNAMIC_DRAW)

With ModernGL you need just one simple line per VBO to achieve the same results:

vbo1 = ctx.buffer(b'Hello World!')
vbo2 = ctx.buffer(reserve=1024, dynamic=True)

Build

build build

python setup.py build_ext --inplace

FAQ

Is ModernGL faster than PyOpenGL?

In some cases yes, the core functions of ModernGL are written in C++, OpenGL functions are called in quick succession so these calls together count as a single python function call.

What version of OpenGL is used?

Most of the calls only require OpenGL 3.3 but Subroutines and Compute Shaders require OpenGL 4.0 and OpenGL 4.3

Is my old PC supported?

OpenGL 3.3 came out in February 2010. With up to date drivers you will be able to use the most of the ModernGL functions, even on integrated graphics cards. (No, Compute Shaders won't work)

Where can I use ModernGL?

Anywhere where OpenGL is supported. ModernGL is capable of rendering using a standalone_context as well. Rendering to a window only requires a valid OpenGL context.

Can ModernGL create a Window?

NO, Window creation is up to you. You can choose from a large variety of modules that can create a window: PyQt5, pyglet, pygame, GLUT and many others.

We currently have example windows you can use or look at in the standard example system currently supporting PyQt5, GLFW, SDL2 and Pyglet (1.x).

Limitations using ModernGL over PyOpenGL?

All the necessary calls are (or can be) implemented in ModernGL. However you can interract with the ModernGL objects from PyOpenGL. If something is missing write an issue or raise a PR.

Supported platforms

  • Windows
  • Linux
  • Mac

Installing from source

Installing on Ubuntu from source

apt-get install python3-dev libgl1-mesa-dev libx11-dev
python3 setup.py install

Building the sphinx documentation

pip install -r docs/requirements.txt
python setup.py build_sphinx

Running tests

pip install -r tests/requirements.txt
pytest tests

Some of the tests may be skipped when the supported OpenGL version is below the requirements of the given test.

Headless rendering

apt-get install xvfb
alias xpy='xvfb-run -s "-screen 0 1x1x24" python3'
xpy -m ModernGL

Code quality

Code is tested with pep8, flake8, prospector and pylint

Community

Contributors

and many others

Thank You!

Contributions are welcome. (Please add yourself to the list)

Metadata

Release files for moderngl 5.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moderngl 5.5.1
File Size Uploaded
moderngl-5.5.1.tar.gz 175.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for moderngl 5.5.1
File
moderngl-5.5.1-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
moderngl-5.5.1-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
moderngl-5.5.1-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
moderngl-5.5.1-cp37-cp37m-manylinux1_i686.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32 Details
moderngl-5.5.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
moderngl-5.5.1-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
moderngl-5.5.1-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
moderngl-5.5.1-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details
moderngl-5.5.1-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
moderngl-5.5.1-cp35-cp35m-manylinux1_i686.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32 Details

Total release size: 8.2 MB

Release files / moderngl-5.5.1.tar.gz

Download URL moderngl-5.5.1.tar.gz
Size 175.2 kB
Tags Source
SHA-256 checksum
How to use checksums
74de53bbc62db5d4908cd48e3dc876383fc9e777aa0cc7a1737c211c17817ff6
BLAKE2b-256 checksum
How to use checksums
9b6e89e4ebb6cc48d116fdcac770c87010a55b51825668abbc51716ddcf7f350
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp37-cp37m-win_amd64.whl

Download URL moderngl-5.5.1-cp37-cp37m-win_amd64.whl
Size 175.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
53821fee84f9e02a31578ae789735e0e423c6dfcb23fe8d11fd1426ed72cc47c
BLAKE2b-256 checksum
How to use checksums
5de3c79773dbf142cfaa051ad8d83bbdd7194ffc9a3a806e5f7e6cc393d3719b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp37-cp37m-win32.whl

Download URL moderngl-5.5.1-cp37-cp37m-win32.whl
Size 146.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
cc996d91456a8ce62930379e75aa88de304035b71ff412cf8684a3142ec405e1
BLAKE2b-256 checksum
How to use checksums
6136ec934b9b3daa658826898dc27ad0551bc3d71aad7d872608d5f639cf7e30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp37-cp37m-manylinux1_x86_64.whl

Download URL moderngl-5.5.1-cp37-cp37m-manylinux1_x86_64.whl
Size 1.2 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
52804dc476e31b42694f63ac44c0c313a43bbcd8448921e1ad51585e195d4f28
BLAKE2b-256 checksum
How to use checksums
d1d05e1c5c1377e25d54fb80fd327eabec6ec563f2ee081f1fbc0d9685126187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp37-cp37m-manylinux1_i686.whl

Download URL moderngl-5.5.1-cp37-cp37m-manylinux1_i686.whl
Size 1.2 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
f6aca7b1062361eee7d96d68dfca7822f1b103bdb723cea69892534ffcfc4ab8
BLAKE2b-256 checksum
How to use checksums
20be6dade2dc85572f6f86e795f017b87334514a56097a3d1e7cdbdd746b8851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp36-cp36m-win_amd64.whl

Download URL moderngl-5.5.1-cp36-cp36m-win_amd64.whl
Size 175.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
3bb410027290021b1ed192660d856af943d17d0bb4ce1cf21b7c67245d4f5e37
BLAKE2b-256 checksum
How to use checksums
88389ae73b3cb185b476a39245c50ad4414119c962ec6dc60bfa4f9b09a7dede
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp36-cp36m-win32.whl

Download URL moderngl-5.5.1-cp36-cp36m-win32.whl
Size 146.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
82254de64de40fe93dbc8feacd0dccddbfcec14fd3f8e0941f5f3753a4e7a613
BLAKE2b-256 checksum
How to use checksums
37394d7f9c04195294d47f0e565cfa4dee1b05b3ddee7b673a371d6de1a1b54e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp36-cp36m-manylinux1_x86_64.whl

Download URL moderngl-5.5.1-cp36-cp36m-manylinux1_x86_64.whl
Size 1.2 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
9cfef4c670aa1766577e7b0b8dc1dd36747964dac0ba6dbee6441c6e317cce3f
BLAKE2b-256 checksum
How to use checksums
3d503488dc1633b539a15a0fa5e37f84f81779dbfb53941b56a15a08b0d1ad8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp36-cp36m-manylinux1_i686.whl

Download URL moderngl-5.5.1-cp36-cp36m-manylinux1_i686.whl
Size 1.2 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
01096c839690b4d079b46fcac4d71d92ec0818dc9d3f85453dd8d12ce89f9ccb
BLAKE2b-256 checksum
How to use checksums
82fb3348cdda48e94466291d049cfce4fc859494a0d48b3fb944e0e52f7bacf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp35-cp35m-manylinux1_x86_64.whl

Download URL moderngl-5.5.1-cp35-cp35m-manylinux1_x86_64.whl
Size 1.2 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
4243433e8475e9bb761decbfa7052ac9053d35a6aa6a586bf2e62da449e5e29d
BLAKE2b-256 checksum
How to use checksums
d2f0d0eac5fb1fc2e401f6b4cca320f1902805809ef4c86500d575476270a011
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / moderngl-5.5.1-cp35-cp35m-manylinux1_i686.whl

Download URL moderngl-5.5.1-cp35-cp35m-manylinux1_i686.whl
Size 1.2 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
49782a7b730e93d74e0ee325db2ce632a1b441cbaf8ca97b215647b0b8abadb9
BLAKE2b-256 checksum
How to use checksums
3a319ebb8d49ee86008bfb97773b601cc79e8f6ae34ee19a1cd611e19e0e7056
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

5.9.0

59 release files

5.8.2

50 release files

5.8.1

50 release files

5.8.0

50 release files

5.7.4

50 release files

5.7.3

50 release files

5.7.0

45 release files

5.6.4

57 release files

5.6.3

24 release files

5.5.4

19 release files

5.5.3

14 release files

5.5.2

13 release files

This release

5.5.1 This release

11 release files

5.4.1

14 release files

5.4.0

12 release files

5.3.0

12 release files

5.2.1

12 release files

5.2.0

12 release files

5.1.0

12 release files

5.0.6

12 release files

5.0.5

12 release files

5.0.3

12 release files

5.0.2

12 release files

5.0.1

11 release files

5.0.0

1 release file

4.2.1

12 release files

4.2.0

8 release files

4.1.12

5 release files

4.1.9

8 release files

4.1.8

8 release files

4.1.7

8 release files

4.1.6

8 release files

4.1.4

8 release files

4.1.3

8 release files

4.1.2

8 release files

4.1.1

8 release files

4.1.0

8 release files

4.0.0

8 release files

3.1.5

8 release files

3.1.4

6 release files

3.1.3

6 release files

3.1.2

4 release files

2.4.1

30 release files

2.4.0

19 release files

2.2.1

25 release files

2.0.9

21 release files

2.0.8

8 release files

2.0.7

5 release files

2.0.6

5 release files

2.0.5

5 release files

2.0.4

5 release files

2.0.3

5 release files

2.0.2

5 release files

0.9.4

5 release files

0.9.3

5 release files

0.9.2

5 release files

0.9.1

3 release files

0.8.8

3 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

1 release file

0.8.4

2 release files

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page