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 the original OpenGL API you have to write a couple of lines to achieve a simple task like compiling a shader or running a computation on the GPU. With ModernGL you will need just a few lines to achieve the same result.

Using PyOpenGL

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)

Using ModernGL

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.

Limitations using ModernGL over PyOpenGL?

All the neccessary 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

pytest

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.2.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.2.1
File Size Uploaded
moderngl-5.2.1.tar.gz 100.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for moderngl 5.2.1
File
moderngl-5.2.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
moderngl-5.2.1-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
moderngl-5.2.1-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
moderngl-5.2.1-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details
moderngl-5.2.1-cp36-cp36m-macosx_10_6_intel.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
moderngl-5.2.1-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
moderngl-5.2.1-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
moderngl-5.2.1-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
moderngl-5.2.1-cp35-cp35m-manylinux1_i686.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32 Details
moderngl-5.2.1-cp35-cp35m-macosx_10_6_intel.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
moderngl-5.2.1-cp34-cp34m-macosx_10_6_intel.whl CPython 3.4 CPython 3.4 pymalloc macOS 10.6+ Intel (x86-64, i386) Details

Total release size: 3.5 MB

Release files / moderngl-5.2.1.tar.gz

Download URL moderngl-5.2.1.tar.gz
Size 100.5 kB
Tags Source
SHA-256 checksum
How to use checksums
39a384fcf0667f9cdf12d0f846c66c30b5985431adc6a35bba0f448c56e49d41
BLAKE2b-256 checksum
How to use checksums
95874eea78b22db7597e5502e8969b81938dea9c47e9bff93707875542e64d96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL moderngl-5.2.1-cp36-cp36m-win_amd64.whl
Size 104.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
a6ec692c87af42fa1491ef5f84620a53964195073d3eec0b509ba16bc7d07c21
BLAKE2b-256 checksum
How to use checksums
68d9ff20269fd7fd28a35c01c5ae4ee98e1451903d09681fc7f25f68aa661b07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL moderngl-5.2.1-cp36-cp36m-win32.whl
Size 91.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
660e78e3783d18087da3f69f808c55bb2c9419719fac2f60cea4bae7b6c474c1
BLAKE2b-256 checksum
How to use checksums
99090b3c9fb21d8b8e0d6ac1fa6c0ed50b35104f51ae543dc93b74631ad654b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL moderngl-5.2.1-cp36-cp36m-manylinux1_x86_64.whl
Size 604.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
d2a32393c3e2f9a4480461b466d59eec04a6ff8c9a6d83280cd4a8f0ed963a15
BLAKE2b-256 checksum
How to use checksums
f9f8bbafaa9102dc6ee5d9103eea663a68d8dc0e85475d807ccca32f3f252848
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL moderngl-5.2.1-cp36-cp36m-manylinux1_i686.whl
Size 567.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
c58af3b3d06cac464ed336e2acd67fcad7a3d5e82a96e73ea494257c4f3b3838
BLAKE2b-256 checksum
How to use checksums
5aa908fed1ca478c3892f6c347964d189d062a27fb783b6c6bd511d87f56abdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / moderngl-5.2.1-cp36-cp36m-macosx_10_6_intel.whl

Download URL moderngl-5.2.1-cp36-cp36m-macosx_10_6_intel.whl
Size 221.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
c74fddaa48524810fabea4088882ae984a4a9f7d1267e5f33fea90796e3dd2db
BLAKE2b-256 checksum
How to use checksums
bc9b30a4f28d333818bb2177f759de6a85df2909e1785f6d48b077e66eb756c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / moderngl-5.2.1-cp35-cp35m-win_amd64.whl

Download URL moderngl-5.2.1-cp35-cp35m-win_amd64.whl
Size 108.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
3788b769e40c878ca99d201da2ddaca96658cc2f71d8de54e3cda67ebc631472
BLAKE2b-256 checksum
How to use checksums
0dd9762d74816d1ceceec7e6fd8f0f83a8171fa23c5fcbe4d0bb6af53653120e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / moderngl-5.2.1-cp35-cp35m-win32.whl

Download URL moderngl-5.2.1-cp35-cp35m-win32.whl
Size 95.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
8ef9ea80a12644cec17e87a2047c1c3e9f04dd9485ba38785eb4947268252545
BLAKE2b-256 checksum
How to use checksums
1a9ca45d6e868730eac9ccdfa76b0cf30ae49512ea5913170f7088eb8db5ce07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL moderngl-5.2.1-cp35-cp35m-manylinux1_x86_64.whl
Size 604.5 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
8be4431a8a6519a99975718fea2edc4a57ab953348e32cd88af3b18b45fb722e
BLAKE2b-256 checksum
How to use checksums
cad06275625293eddec2e81a9252d556b66d51dc23a6119b7f2cd265d6f31ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL moderngl-5.2.1-cp35-cp35m-manylinux1_i686.whl
Size 567.2 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
125fa2d7e755c02ceaf14ee14160da50057983e9a09e43a11bbdb50f5162a3ec
BLAKE2b-256 checksum
How to use checksums
dc0d23ad9de5042e06c08b4e82414f5aeb5744c27f15a35a41c9eb763a2e6fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / moderngl-5.2.1-cp35-cp35m-macosx_10_6_intel.whl

Download URL moderngl-5.2.1-cp35-cp35m-macosx_10_6_intel.whl
Size 221.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
7f919ad050c763775cfe95ca1da00069a65da41d86a73ba233268d89268809ac
BLAKE2b-256 checksum
How to use checksums
8c73b7a395717b0d5febdf5fa4379a608edfa13305cb9e9b593f35b30ba43bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / moderngl-5.2.1-cp34-cp34m-macosx_10_6_intel.whl

Download URL moderngl-5.2.1-cp34-cp34m-macosx_10_6_intel.whl
Size 221.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
67dddd3ffb2e6a094fc833e59d36219fd47a2a1e0b1d52288fe65b9fa094d5f7
BLAKE2b-256 checksum
How to use checksums
243512eae1557b38291ee646d52a57c507cfff9537c761c865193d29f8af8467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

5.5.1

11 release files

5.4.1

14 release files

5.4.0

12 release files

5.3.0

12 release files

This release

5.2.1 This release

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