Skip to main content

ModernGL: High performance rendering for Python 3

Project description

preview

ModernGL

pypi anaconda rtd

ModernGL is a python wrapper over OpenGL 3.3+ core that simplifies the creation of simple graphics applications like scientific simulations, games or user interfaces. Usually, acquiring in-depth knowledge of OpenGL requires a steep learning curve. In contrast, ModernGL is easy to learn and use, moreover it is capable of rendering with high performance and quality, with less code written. The majority of the moderngl code base is also written in C++ for high performance.

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 = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo1)
GL.glBufferData(GL.GL_ARRAY_BUFFER, b'Hello World!', GL.GL_STATIC_DRAW)

vbo2 = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo2)
GL.glBufferData(GL.GL_ARRAY_BUFFER, None, GL.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 test

python -m build .

FAQ

Is ModernGL faster than PyOpenGL?

In many cases yes, the core functions of ModernGL are written in C++. We do not call every OpenGL function from Python, we batch them in a single C++ function instead.

What version of OpenGL is used?

Most of the calls only require OpenGL 3.3. Compute Shaders require OpenGL 4.3. Some functionality relies on their specific extension.

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.

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, ModernGL is responsible for calling the OpenGL API and providing a Pythonic user-friendly API instead. We also provide a utility library moderngl-window making window creation and resource loading very simple.

Limitations using ModernGL over PyOpenGL?

All the necessary calls are (or can be) implemented in ModernGL. However you can interact 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 -m pip install -e .

Building the sphinx documentation

pip install -r docs/requirements.txt
python -m sphinx docs build/sphinx

Running tests

export LIBGL_ALWAYS_SOFTWARE=true
python3 -m pip install glcontext pytest numpy scipy
python3 -X dev -m pytest -s -vvv tests

Headless rendering

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

Citation

If you need to cite this repository in academic research:

@Online{Dombi2020,
  author = {Szabolcs Dombi},
  title = {ModernGL, high performance python bindings for OpenGL 3.3+},
  date = {2020-05-01},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/moderngl/moderngl}},
  commit = {<insert hash if needed>}
}

If commit hash is required this can be found per release here: https://github.com/moderngl/moderngl/releases

Community

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.9.0.tar.gz (189.3 kB view hashes)

Uploaded Source

Built Distributions

moderngl-5.9.0-pp310-pypy310_pp73-win_amd64.whl (106.7 kB view hashes)

Uploaded PyPy Windows x86-64

moderngl-5.9.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (119.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (124.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (110.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

moderngl-5.9.0-pp39-pypy39_pp73-win_amd64.whl (106.8 kB view hashes)

Uploaded PyPy Windows x86-64

moderngl-5.9.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (119.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (124.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (110.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

moderngl-5.9.0-pp38-pypy38_pp73-win_amd64.whl (106.7 kB view hashes)

Uploaded PyPy Windows x86-64

moderngl-5.9.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (119.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (124.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (110.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

moderngl-5.9.0-pp37-pypy37_pp73-win_amd64.whl (106.7 kB view hashes)

Uploaded PyPy Windows x86-64

moderngl-5.9.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (118.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (124.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (110.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

moderngl-5.9.0-cp312-cp312-win_amd64.whl (106.5 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

moderngl-5.9.0-cp312-cp312-win32.whl (97.7 kB view hashes)

Uploaded CPython 3.12 Windows x86

moderngl-5.9.0-cp312-cp312-musllinux_1_1_x86_64.whl (839.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

moderngl-5.9.0-cp312-cp312-musllinux_1_1_i686.whl (866.5 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

moderngl-5.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (294.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (267.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-cp312-cp312-macosx_10_9_x86_64.whl (116.6 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

moderngl-5.9.0-cp311-cp311-win_amd64.whl (106.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

moderngl-5.9.0-cp311-cp311-win32.whl (97.4 kB view hashes)

Uploaded CPython 3.11 Windows x86

moderngl-5.9.0-cp311-cp311-musllinux_1_1_x86_64.whl (838.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

moderngl-5.9.0-cp311-cp311-musllinux_1_1_i686.whl (866.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

moderngl-5.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (293.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (267.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-cp311-cp311-macosx_10_9_x86_64.whl (116.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

moderngl-5.9.0-cp310-cp310-win_amd64.whl (106.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

moderngl-5.9.0-cp310-cp310-win32.whl (97.4 kB view hashes)

Uploaded CPython 3.10 Windows x86

moderngl-5.9.0-cp310-cp310-musllinux_1_1_x86_64.whl (826.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

moderngl-5.9.0-cp310-cp310-musllinux_1_1_i686.whl (855.9 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

moderngl-5.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (281.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (255.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-cp310-cp310-macosx_10_9_x86_64.whl (115.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

moderngl-5.9.0-cp39-cp39-win_amd64.whl (106.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

moderngl-5.9.0-cp39-cp39-win32.whl (97.6 kB view hashes)

Uploaded CPython 3.9 Windows x86

moderngl-5.9.0-cp39-cp39-musllinux_1_1_x86_64.whl (825.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

moderngl-5.9.0-cp39-cp39-musllinux_1_1_i686.whl (854.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

moderngl-5.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (279.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (254.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-cp39-cp39-macosx_10_9_x86_64.whl (115.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

moderngl-5.9.0-cp38-cp38-win_amd64.whl (106.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

moderngl-5.9.0-cp38-cp38-win32.whl (97.5 kB view hashes)

Uploaded CPython 3.8 Windows x86

moderngl-5.9.0-cp38-cp38-musllinux_1_1_x86_64.whl (827.0 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

moderngl-5.9.0-cp38-cp38-musllinux_1_1_i686.whl (856.3 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

moderngl-5.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (281.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (256.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-cp38-cp38-macosx_10_9_x86_64.whl (115.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

moderngl-5.9.0-cp37-cp37m-win_amd64.whl (106.0 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

moderngl-5.9.0-cp37-cp37m-win32.whl (97.2 kB view hashes)

Uploaded CPython 3.7m Windows x86

moderngl-5.9.0-cp37-cp37m-musllinux_1_1_x86_64.whl (818.8 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

moderngl-5.9.0-cp37-cp37m-musllinux_1_1_i686.whl (848.9 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

moderngl-5.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (272.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

moderngl-5.9.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (248.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

moderngl-5.9.0-cp37-cp37m-macosx_10_9_x86_64.whl (115.5 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

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