ModernGL: High performance rendering for Python 3
Project description
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
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
Built Distributions
Hashes for moderngl-5.2.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6ec692c87af42fa1491ef5f84620a53964195073d3eec0b509ba16bc7d07c21 |
|
MD5 | a8948b000b85c5d3883bf7821130bdbf |
|
BLAKE2b-256 | 68d9ff20269fd7fd28a35c01c5ae4ee98e1451903d09681fc7f25f68aa661b07 |
Hashes for moderngl-5.2.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 660e78e3783d18087da3f69f808c55bb2c9419719fac2f60cea4bae7b6c474c1 |
|
MD5 | 5ef2cf353d77afc40ab2c04f55100429 |
|
BLAKE2b-256 | 99090b3c9fb21d8b8e0d6ac1fa6c0ed50b35104f51ae543dc93b74631ad654b0 |
Hashes for moderngl-5.2.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2a32393c3e2f9a4480461b466d59eec04a6ff8c9a6d83280cd4a8f0ed963a15 |
|
MD5 | 201837bb738fd731d44fab7768bcdca2 |
|
BLAKE2b-256 | f9f8bbafaa9102dc6ee5d9103eea663a68d8dc0e85475d807ccca32f3f252848 |
Hashes for moderngl-5.2.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58af3b3d06cac464ed336e2acd67fcad7a3d5e82a96e73ea494257c4f3b3838 |
|
MD5 | 7fa7961af4aac849578396a90f0a36f8 |
|
BLAKE2b-256 | 5aa908fed1ca478c3892f6c347964d189d062a27fb783b6c6bd511d87f56abdf |
Hashes for moderngl-5.2.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c74fddaa48524810fabea4088882ae984a4a9f7d1267e5f33fea90796e3dd2db |
|
MD5 | 201a34411dac297122595bd500af3292 |
|
BLAKE2b-256 | bc9b30a4f28d333818bb2177f759de6a85df2909e1785f6d48b077e66eb756c9 |
Hashes for moderngl-5.2.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3788b769e40c878ca99d201da2ddaca96658cc2f71d8de54e3cda67ebc631472 |
|
MD5 | 106bf17dddae554aa89fa054003cf946 |
|
BLAKE2b-256 | 0dd9762d74816d1ceceec7e6fd8f0f83a8171fa23c5fcbe4d0bb6af53653120e |
Hashes for moderngl-5.2.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ef9ea80a12644cec17e87a2047c1c3e9f04dd9485ba38785eb4947268252545 |
|
MD5 | e55b6ee67bbf5d606e3ab3223776e2ef |
|
BLAKE2b-256 | 1a9ca45d6e868730eac9ccdfa76b0cf30ae49512ea5913170f7088eb8db5ce07 |
Hashes for moderngl-5.2.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8be4431a8a6519a99975718fea2edc4a57ab953348e32cd88af3b18b45fb722e |
|
MD5 | ae0e3e1fe387d6a5760c1bf07b623fec |
|
BLAKE2b-256 | cad06275625293eddec2e81a9252d556b66d51dc23a6119b7f2cd265d6f31ca8 |
Hashes for moderngl-5.2.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 125fa2d7e755c02ceaf14ee14160da50057983e9a09e43a11bbdb50f5162a3ec |
|
MD5 | 5682ead4d9724e40c4515718f347e33c |
|
BLAKE2b-256 | dc0d23ad9de5042e06c08b4e82414f5aeb5744c27f15a35a41c9eb763a2e6fb1 |
Hashes for moderngl-5.2.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f919ad050c763775cfe95ca1da00069a65da41d86a73ba233268d89268809ac |
|
MD5 | aad07b8fbb0d63a39f90453c932b7858 |
|
BLAKE2b-256 | 8c73b7a395717b0d5febdf5fa4379a608edfa13305cb9e9b593f35b30ba43bb5 |
Hashes for moderngl-5.2.1-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67dddd3ffb2e6a094fc833e59d36219fd47a2a1e0b1d52288fe65b9fa094d5f7 |
|
MD5 | 49b8fb5f0d48685dff67e325b45f9143 |
|
BLAKE2b-256 | 243512eae1557b38291ee646d52a57c507cfff9537c761c865193d29f8af8467 |