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

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.1.tar.gz (109.6 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.1-cp37-cp37m-win_amd64.whl (119.2 kB view details)

Uploaded CPython 3.7mWindows x86-64

moderngl-5.4.1-cp37-cp37m-win32.whl (105.8 kB view details)

Uploaded CPython 3.7mWindows x86

moderngl-5.4.1-cp36-cp36m-win_amd64.whl (122.4 kB view details)

Uploaded CPython 3.6mWindows x86-64

moderngl-5.4.1-cp36-cp36m-win32.whl (109.0 kB view details)

Uploaded CPython 3.6mWindows x86

moderngl-5.4.1-cp36-cp36m-manylinux1_x86_64.whl (651.0 kB view details)

Uploaded CPython 3.6m

moderngl-5.4.1-cp36-cp36m-manylinux1_i686.whl (611.4 kB view details)

Uploaded CPython 3.6m

moderngl-5.4.1-cp36-cp36m-macosx_10_6_intel.whl (245.7 kB view details)

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

moderngl-5.4.1-cp35-cp35m-win_amd64.whl (127.0 kB view details)

Uploaded CPython 3.5mWindows x86-64

moderngl-5.4.1-cp35-cp35m-win32.whl (113.4 kB view details)

Uploaded CPython 3.5mWindows x86

moderngl-5.4.1-cp35-cp35m-manylinux1_x86_64.whl (651.0 kB view details)

Uploaded CPython 3.5m

moderngl-5.4.1-cp35-cp35m-manylinux1_i686.whl (611.4 kB view details)

Uploaded CPython 3.5m

moderngl-5.4.1-cp35-cp35m-macosx_10_6_intel.whl (245.7 kB view details)

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

moderngl-5.4.1-cp34-cp34m-macosx_10_6_intel.whl (245.7 kB view details)

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

File details

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

File metadata

  • Download URL: moderngl-5.4.1.tar.gz
  • Upload date:
  • Size: 109.6 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.1.tar.gz
Algorithm Hash digest
SHA256 277a1dbd8b9193531de4df2052ac4adedd18858ac5926628f1dcdc40e5fb4812
MD5 a90bfc195e6a7054daab5379f329df51
BLAKE2b-256 8811ac18508d861ed0dd1e163f3b1c51a9a6ed1dba510886f681894457f5a224

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 119.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.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5ede32b8d66b802573137bf7e05b251ec8b72a01e8ff72f5f715ed101b859c60
MD5 e2da3852a733412e7a28e4b9256b228e
BLAKE2b-256 94ecb1056a53a5f3b9e814c230dab7a75fb8b5ef6c37e843717abc3f9310538c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 105.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.1-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 ad6ce61094eb0968affcec7725e831366f4b290746022a6da4e65151a30ceedf
MD5 0dd3ce0e254f62c0445508854a92ea15
BLAKE2b-256 92eae86bc7b5cce495787395203c241709ef5ecd2bc616cb2d065b5a7e49ba66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 122.4 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.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 8226de2475d134d203554c0366155fed553392bae661376705d7cf471eb35c12
MD5 b4c7da64d6bbe1a3770315adcc603299
BLAKE2b-256 95361c5485215c53f7a892b40bc1af69f288dac3be9efcbe3f9a81970d0058f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 109.0 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.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 2bd497d872d998e9bd5766932f03393d4414ca7940d6d3cf604d84a892bb8d10
MD5 9d67690e1cba9164993069606767ac16
BLAKE2b-256 7ca362a875f599a10ffb13bd91e7e7ec54b31366aa37846a03b26aa3a2b30c59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 651.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.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bd688091d53108a914a0e615450b3ebfc9bfb18e06f86c370f0e129c6b828c22
MD5 146e53dcb69e4756b0935281971b7f3d
BLAKE2b-256 de8074417bd4598f947c606028bcbcccde77011fb7159bc00b49f809bd32fec5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 611.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.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 213cde4be084c8f287619d58b30e5c34b6fdb9174cdc8d97344d1fda4f870090
MD5 25fcd4eaf925bf16b10298467dcc827e
BLAKE2b-256 45ccfc24fbb8e57e9f2976a57f08c1394a02204644cc58234f99353bfbd6a103

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 245.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.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 e6f1bccf888da9765826bbbe33edb3caa3e80938a37e1c08d02ae14cad84fb46
MD5 69aba0225692fad9c4dc921987c71130
BLAKE2b-256 bd4a59a2abdbeab7ca13e2bc2340f452725be394c2b56b088590397ac866bb82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 127.0 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.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 2f77406232d52740e487092812a4bdbe145e4d6e05c03c815f65eb73ba8a6d44
MD5 864c1e45d62cc41d33949cf780372f01
BLAKE2b-256 a8018f03857c36520b2736bd4fa03442e7f7b46a1a0ba3eef3264ee99d247015

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 113.4 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.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 f6464bf2300275ab54695075a34caf1d83bf808bb19ee203ef193c56770f7573
MD5 757310a253116f090bb08bb32f0c6b8e
BLAKE2b-256 a31a1fe3b0dad0a2703679e7bcd3c0bc913088a3e4bbab7100c52a278c7b7166

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 651.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.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c28298de9580be3414ca54e04cfe6d7dd7162ec660c94d1fdbf2d849d6576f97
MD5 39ecb456b37104cf763df0cfcc63d373
BLAKE2b-256 3fde5a6d42bd07e4e60d047ffafb70a724ec38c6e8d498ec70b1ea5213cc7523

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp35-cp35m-manylinux1_i686.whl
  • Upload date:
  • Size: 611.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.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 05352d310ded51165e4af98a225badba6e696e850c07705821b2fa0b15c4e150
MD5 41c4d94fbe76f367cff658e0dc854692
BLAKE2b-256 f2ffabb9320cc585ad16c08d78c83f33fcea64532b53aedca60fdc4a58a1a589

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 245.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.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 6a98d4b1a6207b500919d68924ea6496202c91ff67f82d62b4d3e7a5f599bcce
MD5 f8ca5988a94563f136f0a8e475b13737
BLAKE2b-256 5a40ce6c5d405531d5b9912358d9c531b2a378e42b8f4c60ea06b340318c5842

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.1-cp34-cp34m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 245.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.1-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5cd668fedef590ba407db7ba0f114a250dc1bddfef0e696bf484e8b303a72a1b
MD5 28fffc6eba48f9b516aa53c1d3fdc066
BLAKE2b-256 beab8d543fe2e4bed10018d4fba8f993cd50767b05fb8e117881e0e6b7ba13cd

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