Skip to main content

ModernGL: High performance rendering for Python 3

Project description

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)

Project details


Release history Release notifications | RSS feed

This version

5.4.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moderngl-5.4.2.tar.gz (112.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

moderngl-5.4.2-cp37-cp37m-win_amd64.whl (123.2 kB view details)

Uploaded CPython 3.7mWindows x86-64

moderngl-5.4.2-cp37-cp37m-win32.whl (109.8 kB view details)

Uploaded CPython 3.7mWindows x86

moderngl-5.4.2-cp36-cp36m-win_amd64.whl (123.2 kB view details)

Uploaded CPython 3.6mWindows x86-64

moderngl-5.4.2-cp36-cp36m-win32.whl (109.8 kB view details)

Uploaded CPython 3.6mWindows x86

moderngl-5.4.2-cp36-cp36m-manylinux1_x86_64.whl (655.0 kB view details)

Uploaded CPython 3.6m

moderngl-5.4.2-cp36-cp36m-manylinux1_i686.whl (615.4 kB view details)

Uploaded CPython 3.6m

moderngl-5.4.2-cp36-cp36m-macosx_10_6_intel.whl (249.7 kB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

moderngl-5.4.2-cp35-cp35m-win_amd64.whl (127.8 kB view details)

Uploaded CPython 3.5mWindows x86-64

moderngl-5.4.2-cp35-cp35m-win32.whl (114.2 kB view details)

Uploaded CPython 3.5mWindows x86

moderngl-5.4.2-cp35-cp35m-manylinux1_x86_64.whl (655.0 kB view details)

Uploaded CPython 3.5m

moderngl-5.4.2-cp35-cp35m-manylinux1_i686.whl (615.4 kB view details)

Uploaded CPython 3.5m

moderngl-5.4.2-cp35-cp35m-macosx_10_6_intel.whl (249.7 kB view details)

Uploaded CPython 3.5mmacOS 10.6+ Intel (x86-64, i386)

moderngl-5.4.2-cp34-cp34m-macosx_10_6_intel.whl (249.7 kB view details)

Uploaded CPython 3.4mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file moderngl-5.4.2.tar.gz.

File metadata

  • Download URL: moderngl-5.4.2.tar.gz
  • Upload date:
  • Size: 112.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2.tar.gz
Algorithm Hash digest
SHA256 274a801038ab9d6f3c693fb92e2c59bf130fc8880f77d14454d8a5eba7c356b5
MD5 d2ef3a0b0c81dc370121f6bfc3dfa5cf
BLAKE2b-256 c088be612f85165e6f84f2852774e80ec901f371a173c25531227a8060562403

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 123.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 20c11fe1a9dd721cbf4bb295d736215679f89ed6717020fc6dd8789c1a636763
MD5 75578fa728a50a21245bdf2a4f48efd0
BLAKE2b-256 c1aa3b613f2cce5e00955993472d18e38e024c1db1066490aee02a5a26fa2a2b

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp37-cp37m-win32.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 109.8 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 8f88554703259a71143e1d8659d0e6785a89f526a223ebf5f6c3d00975b65eff
MD5 eb35af619270a4d2c1e41c4a9990fc3f
BLAKE2b-256 bc95981efe99303098cdeb7b70c4709e17368458b4d56594a3456a86f7a2f201

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 123.2 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d877378637eb8ae4c8ec91ef75194ca0ce5be618360fc558f0a237a30322b2ae
MD5 c5b722fd92b3cfc1ea7b88d4d950c2f1
BLAKE2b-256 709d9e356ddabd0db8ac07c1b888248cf0cf5e6454f8a2963f2d15a798c34383

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp36-cp36m-win32.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 109.8 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 dce90681b1a8497e13740413816048c688fcdaaea5b66f855e8227e4c0a20abf
MD5 0a16e87ced244f0dd4c3ad8fc97b8b4a
BLAKE2b-256 34db0b3775fe1268471ed2f37406b4bf21fe3dc1c396d1cea0fac1a208c02068

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 655.0 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d05ad7fa3e8f7d77eab0e75ef1983e4d5ef0c3cae2818abf059850b79f7104e8
MD5 1fe4a01da248b6b7e3db6b349d737300
BLAKE2b-256 12ceb1a17f83a11f966dfc2745d420b2b1d9c0599845676799051d9437db75aa

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp36-cp36m-manylinux1_i686.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 615.4 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c7eddad679c06383f613161fabf76c911a0e88f1b7514e9534c56475ecd87d57
MD5 6c0577af11543b7f1b368d37614b6923
BLAKE2b-256 5fb193828c0aabc293cc1b2807d8dbd94cb05a49025c54bac6d5541d0fef8a4a

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 249.7 kB
  • Tags: CPython 3.6m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 4e5c5391db7e400776c0ebc3bbe0a9ba2257ec00f7424cfb32f42ec71a750812
MD5 a5a99b1948c5f2043d439b7940af0624
BLAKE2b-256 982c78a663a2957c1e00b4c63c2ede0a4c5a92002c16c6a417a615becb70831f

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 127.8 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 4b65fd4e51e41bf2a57915ff3972cd09b51ed0cbb0f470c1a576eac1d3106211
MD5 3c230066eee408301e4ac76eacc71f17
BLAKE2b-256 a0ba9631bd736275c2021e0944a28199defc89aba9fede7653c2040273030430

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp35-cp35m-win32.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 114.2 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 0a2e6717ff641f3c374609343571c6c954fad1753a4ec94636e40b66cfd29019
MD5 4d160ac8def5a2d6cadcbb594fb50e5f
BLAKE2b-256 1a96b48e403f2ca9cb2c79a68ddd310482c4840dcefdd26cc9f23dda0ceb135d

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 655.0 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4772a7aff2ef70128402f58e43f885728d505362de2405df9bbe999b49eb7444
MD5 f00ca762c8e1d8fba04d21c6c02fca61
BLAKE2b-256 a91f78eb5ca05005cfbf1df1ad823a8c6bd896b9a8c844902e1d77ec9ca47f1b

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp35-cp35m-manylinux1_i686.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp35-cp35m-manylinux1_i686.whl
  • Upload date:
  • Size: 615.4 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 433d17217e6149c1dc4a825b82461f3cad465ccb945b1f27854d5daaea5d6deb
MD5 d1848d5cdaa7362a4a9e4bc42c917112
BLAKE2b-256 9779599b65fc9af5ec8df1ac861cdddd114c2fa6dae90f509c31e5b16a979d4b

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 249.7 kB
  • Tags: CPython 3.5m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 7f3155e6c0ecf9d3763d8b82fb21b023010047fed596ba3a63b83e196b32c633
MD5 944fc891ccaa874d0caf4ca4981430dd
BLAKE2b-256 c8ec43d8b40e272f1c46c68ce2923234a57053a6ba06b6cac02b3ee911592977

See more details on using hashes here.

File details

Details for the file moderngl-5.4.2-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

  • Download URL: moderngl-5.4.2-cp34-cp34m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 249.7 kB
  • Tags: CPython 3.4m, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for moderngl-5.4.2-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 e0c43f6a831f7d57daedb60f72d680639d3848f0fd0d0ed081c8e3eac94d984f
MD5 07b5be0b3415b947e2245f4b455e4c04
BLAKE2b-256 74694465d2732cfdbed6f05e80d5d4b96a46927c3044061ae6947324e909b9ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page