pip install moderngl
- GPU accelerated high quality graphics
- Rendering modern OpenGL scenes with less headache
- Simpler and faster than PyOpenGL
- Can render without a window
- 100% Pythonic
>>> 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.
>>> 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>
With PyOpenGL, using the original OpenGL API, you have to write three lines to achieve a simple task like binding a VBO:
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)
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)
python setup.py build_ext --inplace
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.
Most of the calls only require OpenGL 3.3 but Subroutines and Compute Shaders require OpenGL 4.0 and OpenGL 4.3
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)
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.
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.
We currently have example windows you can use or look at in the standard example system currently supporting PyQt5, GLFW, SDL2 and Pyglet (1.x).
All the necessary 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.
- Windows
- Linux
- Mac
apt-get install python3-dev libgl1-mesa-dev libx11-dev
python3 setup.py install
pip install -r docs/requirements.txt
python setup.py build_sphinx
pytest
Some of the tests may be skipped when the supported OpenGL version is below the requirements of the given test.
apt-get install xvfb
alias xpy='xvfb-run -s "-screen 0 1x1x24" python3'
xpy -m ModernGL
Code is tested with pep8, flake8, prospector and pylint
- Szabolcs Dombi
- SimLeek
- Aljenci
- MinchinWeb
- Silexstudio
- stuaxo
- Tomi Aarnio
- Joshua Reibert
- Einar Forselv
and many others
Thank You!
Contributions are welcome. (Please add yourself to the list)