File: rendering.rst

package info (click to toggle)
python-moderngl 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,700 kB
  • sloc: python: 15,758; cpp: 14,665; makefile: 14
file content (29 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.. py:currentmodule:: moderngl

Standalone rendering
====================

Standalone (offline) rendering allows you to render without using a window, and is included in ModernGL by default.

Rendering occurs when :py:meth:`VertexArray.render` is called. By default, the ``mode`` parameter is :py:attr:`moderngl.TRIANGLES`, but since we need to draw a line, we change the mode value to :py:attr:`moderngl.LINES`::

    vao.render(moderngl.LINES)  # "mode" is the first optional argument

To display the rendering result, we use the `Pillow (PIL)`_ library that comes with Python. Let's return the texture from the GPU memory to RAM and call the ``PIL.Image.show()`` method to show it.

.. rubric:: Entire source

.. literalinclude:: first.4.py
    :emphasize-lines: 4,46-
    :linenos:

The result will be something like this:

.. figure:: rendering_result.png
    :alt: Rendering result
    :align: center
    :figclass: align-center

    Rendering result

.. _Pillow (PIL): https://pillow.readthedocs.io/