Skip to main content

ModernGL: High performance rendering for Python 3

Project description

ModernGL
========

.. code-block:: 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.python.org/pypi/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
------------

.. code-block:: 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
---------------------------------

.. code-block:: py

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

.. code-block:: 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
~~~~~~~~~~~~~~

.. code-block:: 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
~~~~~~~~~~~~~~

.. code-block:: py

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

Build
-----

.. image:: https://img.shields.io/travis/cprogrammer1994/ModernGL/master.svg?label=build
:target: https://travis-ci.org/cprogrammer1994/ModernGL
:alt: build


.. image:: https://img.shields.io/appveyor/ci/cprogrammer1994/ModernGL/master.svg?label=build
:target: https://ci.appveyor.com/project/cprogrammer1994/ModernGL
:alt: build


.. code-block:: 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 <https://github.com/cprogrammer1994/ModernGL/tree/master/examples/standalone>`_ 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 <https://pypi.python.org/pypi/PyQt5/>`_\ , `pyglet <https://bitbucket.org/pyglet/pyglet/wiki/Home>`_\ ,
`pygame <https://www.pygame.org/news>`_\ , `GLUT <https://wiki.python.org/moin/PyOpenGL>`_ 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 <https://github.com/cprogrammer1994/ModernGL/issues>`_ or raise
a `PR <https://github.com/cprogrammer1994/ModernGL/pulls>`_.

Supported platforms
-------------------

* [x] Windows
* [x] Linux
* [x] Mac

Project details


Release history Release notifications | RSS feed

This version

5.0.7

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

Uploaded Source

Built Distributions

moderngl-5.0.7-cp36-cp36m-win_amd64.whl (102.6 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

moderngl-5.0.7-cp36-cp36m-win32.whl (89.7 kB view hashes)

Uploaded CPython 3.6m Windows x86

moderngl-5.0.7-cp36-cp36m-manylinux1_x86_64.whl (602.2 kB view hashes)

Uploaded CPython 3.6m

moderngl-5.0.7-cp36-cp36m-manylinux1_i686.whl (565.2 kB view hashes)

Uploaded CPython 3.6m

moderngl-5.0.7-cp36-cp36m-macosx_10_6_intel.whl (219.9 kB view hashes)

Uploaded CPython 3.6m macOS 10.6+ intel

moderngl-5.0.7-cp35-cp35m-win_amd64.whl (107.0 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

moderngl-5.0.7-cp35-cp35m-win32.whl (94.2 kB view hashes)

Uploaded CPython 3.5m Windows x86

moderngl-5.0.7-cp35-cp35m-manylinux1_x86_64.whl (602.4 kB view hashes)

Uploaded CPython 3.5m

moderngl-5.0.7-cp35-cp35m-manylinux1_i686.whl (565.3 kB view hashes)

Uploaded CPython 3.5m

moderngl-5.0.7-cp35-cp35m-macosx_10_6_intel.whl (219.9 kB view hashes)

Uploaded CPython 3.5m macOS 10.6+ intel

moderngl-5.0.7-cp34-cp34m-macosx_10_6_intel.whl (219.8 kB view hashes)

Uploaded CPython 3.4m macOS 10.6+ intel

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