Skip to main content

ModernGL: High performance rendering for Python 3

Project description



[![preview](https://github.com/cprogrammer1994/ModernGL/raw/master/.github/preview.png)](#readme)



# ModernGL

```sh
pip install ModernGL
```

- [Documentation](https://moderngl.readthedocs.io/)
- [Examples](https://github.com/cprogrammer1994/ModernGL/tree/master/examples/#readme)
- [ModernGL on Github](https://github.com/cprogrammer1994/ModernGL/)
- [ModernGL on PyPI](https://pypi.org/project/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

```py
>>> 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](https://github.com/cprogrammer1994/ModernGL/tree/master/examples/#readme).

## Easy to use with Pillow and Numpy

```py
>>> img = Image.open('texture.jpg')
>>> ctx.texture(img.size, 3, img.tobytes())
<Texture: 1>
```

```py
>>> 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

```py
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

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

## Build

[![build](https://img.shields.io/travis/cprogrammer1994/ModernGL/master.svg?label=build)](https://travis-ci.org/cprogrammer1994/ModernGL)
[![build](https://img.shields.io/appveyor/ci/cprogrammer1994/ModernGL/master.svg?label=build)](https://ci.appveyor.com/project/cprogrammer1994/ModernGL)

```sh
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.

[standalone_context]: https://github.com/cprogrammer1994/ModernGL/tree/master/examples/standalone

### 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.

[PyQt5]: https://pypi.org/project/PyQt5/
[pyglet]: https://bitbucket.org/pyglet/pyglet/wiki/Home
[pygame]: https://www.pygame.org/news
[GLUT]: https://wiki.python.org/moin/PyOpenGL

### 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](https://github.com/cprogrammer1994/ModernGL/issues) or raise a [PR](https://github.com/cprogrammer1994/ModernGL/pulls).

## Supported platforms

- [x] Windows
- [x] Linux
- [x] Mac

## Installing from source

### Installing on Ubuntu from source

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

### Building the sphinx documentation

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

### Running tests

```sh
pytest
```

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

### Headless rendering

```sh
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]

[pep8]: https://www.python.org/dev/peps/pep-0008/
[flake8]: http://flake8.pycqa.org/en/latest/
[prospector]: https://prospector.landscape.io/en/master/
[pylint]: https://www.pylint.org/

## Community

- [Code of conduct](https://github.com/cprogrammer1994/ModernGL/blob/master/.github/CODE_OF_CONDUCT.md)

## Contributors

- [Szabolcs Dombi](https://github.com/cprogrammer1994)
- [SimLeek](https://github.com/SimLeek)
- [Aljenci](https://github.com/Aljenci)
- [MinchinWeb](https://github.com/MinchinWeb)
- [Silexstudio](https://github.com/Silexstudio)
- [stuaxo](https://github.com/stuaxo)
- [Tomi Aarnio](https://github.com/toaarnio)
- [Joshua Reibert](https://github.com/joshua-r)
- [Einar Forselv](https://github.com/einarf)

and [many others](https://github.com/cprogrammer1994/ModernGL/graphs/contributors)

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.0.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.0-cp36-cp36m-win_amd64.whl (122.4 kB view details)

Uploaded CPython 3.6mWindows x86-64

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

Uploaded CPython 3.6mWindows x86

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.6m

moderngl-5.4.0-cp36-cp36m-macosx_10_6_intel.whl (245.8 kB view details)

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

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

Uploaded CPython 3.5mWindows x86-64

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

Uploaded CPython 3.5mWindows x86

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

moderngl-5.4.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: moderngl-5.4.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fdfb671c1bb31dfb8d9ea3c0c412d84cfc5f12c984311a0f90e036bffe8615a2
MD5 93222a9e279bdca9b03c4c1803506977
BLAKE2b-256 0c242316f7b4aec41501cbd9bb5dbcd7bf6d9d36be2bc4c4a9076559dd7043b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d2276a9deb6d460ae6099a2ebd26516c3124bd251f8b8ea24fce278a5c3a0226
MD5 5e67d9eb87106a2c7a695c8ac465dd44
BLAKE2b-256 32350f512839bca657abfdcd7da8284a2891beb479e6cacd2ef446961799e9b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 1d9298274ba10772b07c2f4cf88b679a9ac52bfba3113bdd30b2d48144d9bb83
MD5 b9742cf68fcc989e8e81904108c15352
BLAKE2b-256 ce8a018ccbd74b12380ca722ec99d953395080a95a91811fb2e20dfbbfa63003

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6871b0e88d4d01354afafee27f101fbd8d8b9b952ead62dd582a9db74ffc30aa
MD5 6a1499c2b69912625bf21c384339806f
BLAKE2b-256 84d5d6e2ff8e57cee155263d10f57f427985f5e0224c1caff6e07884c3fae177

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 69be5feb40252b171136fc860f7058d4cc533cb7de1f8efc81bfe5610552e73c
MD5 db36ff90a4ad6d94f0ea89daedbaea4f
BLAKE2b-256 8f6a8ea1e954b875bafcc152a95c9062c2761b6924be759e85f4f3a763d80c1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 245.8 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.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 84f13d296553aba4dddcdb23fd53e8800382136424acfd69410caec93bd0e5ed
MD5 b05f4cab757535e6e32f398d03f17403
BLAKE2b-256 6c9a78b94d4f23fb84700407775a41bcaedf662f2a97ca8311c2bd03ff611373

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 4d98bbaad45e23e33f6d4c4dcc8c68faf7b9b0f5dcf5cd815442d7169944dc82
MD5 4100e2304c79831f6f74a9cf87f16bb4
BLAKE2b-256 eb32ff8f0e4850ed04914cfd16abe40f45398598d2dcba96004ccaaa88367fce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 2c2767113b063a019c22e46e633667de936f7d726a3ac861cb5104e6892bee53
MD5 019e77fd4abcbb84489654a9fec32311
BLAKE2b-256 d1d8d834b87cfad44fb9d987b095fd9c30d92c029312317762b88c2e30092e54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8cf14c3cbbfa05f5207b6c08da1c5d53a82a5dd736ddee378e46c40f60e26ffc
MD5 db88fd8d7c60d37c4928f550d21245b5
BLAKE2b-256 3ed9681eff95068c25231bafa5877efd2a3efdff2417802e5caced7dcb87efe9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3e978cac03b5c4d3793d1e04d404eaee288fbf934935e9407ec68bb0160f6d30
MD5 5d717e21d0714fc85fe70e346022147a
BLAKE2b-256 924cd0bfe80dd6e45eb60b2dd715a216fe2725ccc7050ba3d01151839068a94b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 da042eff2e2b05491f9b2c82700267aac513f5814da406627fc94aa6f970e617
MD5 008a5daf524f4e115b680ec64bf73973
BLAKE2b-256 a3c21eef65bf13cde1715e48d6764f865af423091b800fb5f8b2411834ba58e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moderngl-5.4.0-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.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 872aaaa0ea6e3cc90a8d0c4504ea1933967316f175293f0dc9ec72d4ffbda61e
MD5 2c65fedb222f97fde8db6dab8d71863b
BLAKE2b-256 89c5826d7142ba1ba91f55ae1606d5b665f1023a9afaba2d532d357c70f35fe7

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