Skip to main content

high-performance rendering

Project description

ZenGL

ZenGL is a minimalist Python module providing exactly one way to render scenes with OpenGL.

pip install zengl

ZenGL is ...

  • high-performance
  • simple - buffers, images, pipelines and there you go
  • easy-to-learn - it is simply OpenGL with no magic added
  • verbose - most common mistakes are catched and reported in a clear and understandable way
  • robust - there is no global state or external trouble-maker affecting the render
  • backward-compatible - it requires OpenGL 3.3 - it is just enough
  • cached - most OpenGL objects are reused between renders
  • zen - there is one way to do it

Concept

ZenGL provides a simple way to render from Python. We aim to support headless rendering first, rendering to a window is done by blitting the final image to the screen. By doing this we have full control of what we render. The window does not have to be multisample, and it requires no depth buffer at all.

Offscreen rendering works out of the box on all platforms if the right loader is provided. Loaders implement a load method to resolve a subset of OpenGL 3.3 core. The return value of the load method is an int, a void pointer to the function implementation. Virtualized, traced, and debug environments can be provided by custom loaders. The current implementation uses the glcontext from ModernGL to load the OpenGL methods.

ZenGL's main focus is on readability and maintainability. Pipelines in ZenGL are almost entirely immutable and they cannot affect each other except when one draws on top of the other's result that is expected. No global state is affecting the render, if something breaks there is one place to debug.

ZenGL does not use anything beyond OpenGL 3.3 core, not even if the more convenient methods are available. Implementation is kept simple. Usually, this is not a bottleneck.

ZenGL does not implement transform feedback, storage buffers or storage images, tesselation, geometry shader, and maybe many more. We have a strong reason not to include them in the feature list. They add to the complexity and are against ZenGL's main philosophy. ZenGL was built on top experience gathered on real-life projects that could never make good use of any of that.

ZenGL is using the same vertex and image format naming as WebGPU and keeping the vertex array definition from ModernGL. ZenGL is not the next version of ModernGL. ZenGL is a simplification of a subset of ModernGL with some extras that were not possible to include in ModernGL.

Examples

grass.py

grass

envmap.py

envmap

instanced_crates.py

instanced_crates

julia_fractal.py

julia_fractal

blending.py

blending

render_to_texture.py

render_to_texture

pybullet_box_pile.py

pybullet_box_pile

pygmsh_shape.py

pygmsh_shape

texture_array.py

texture_array

monkey.py

monkey

reflection.py

reflection

polygon_offset.py

polygon_offset

blur.py

blur

hello_triangle.py

hello_triangle

hello_triangle_srgb.py

hello_triangle_srgb

viewports.py

viewports

points.py

points

wireframe_terrain.py

wireframe_terrain

crate.py

crate

sdf_example.py

sdf_example

sdf_tree.py

sdf_tree

mipmaps.py

mipmaps

conways_game_of_life.py

conways_game_of_life

Headless

import zengl
from PIL import Image

ctx = zengl.context(zengl.loader(headless=True))

size = (1280, 720)
image = ctx.image(size, 'rgba8unorm', samples=1)

triangle = ctx.pipeline(
    vertex_shader='''
        #version 330

        out vec3 v_color;

        vec2 positions[3] = vec2[](
            vec2(0.0, 0.8),
            vec2(-0.6, -0.8),
            vec2(0.6, -0.8)
        );

        vec3 colors[3] = vec3[](
            vec3(1.0, 0.0, 0.0),
            vec3(0.0, 1.0, 0.0),
            vec3(0.0, 0.0, 1.0)
        );

        void main() {
            gl_Position = vec4(positions[gl_VertexID], 0.0, 1.0);
            v_color = colors[gl_VertexID];
        }
    ''',
    fragment_shader='''
        #version 330

        in vec3 v_color;

        layout (location = 0) out vec4 out_color;

        void main() {
            out_color = vec4(v_color, 1.0);
        }
    ''',
    framebuffer=[image],
    topology='triangles',
    vertex_count=3,
)

image.clear_value = (1.0, 1.0, 1.0, 1.0)
image.clear()
triangle.render()

Image.frombuffer('RGBA', size, image.read(), 'raw', 'RGBA', 0, -1).save('hello.png')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zengl-1.0.1.tar.gz (31.2 kB view hashes)

Uploaded Source

Built Distributions

zengl-1.0.1-pp37-pypy37_pp73-win_amd64.whl (38.0 kB view hashes)

Uploaded PyPy Windows x86-64

zengl-1.0.1-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (41.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

zengl-1.0.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (35.8 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

zengl-1.0.1-cp310-cp310-win_amd64.whl (38.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

zengl-1.0.1-cp310-cp310-musllinux_1_1_x86_64.whl (103.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

zengl-1.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (104.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

zengl-1.0.1-cp310-cp310-macosx_10_9_x86_64.whl (37.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

zengl-1.0.1-cp39-cp39-win_amd64.whl (38.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

zengl-1.0.1-cp39-cp39-musllinux_1_1_x86_64.whl (103.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

zengl-1.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (104.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

zengl-1.0.1-cp39-cp39-macosx_10_9_x86_64.whl (37.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

zengl-1.0.1-cp38-cp38-win_amd64.whl (38.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

zengl-1.0.1-cp38-cp38-musllinux_1_1_x86_64.whl (105.1 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

zengl-1.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (106.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

zengl-1.0.1-cp38-cp38-macosx_10_9_x86_64.whl (37.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

zengl-1.0.1-cp37-cp37m-win_amd64.whl (37.8 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

zengl-1.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (101.5 kB view hashes)

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

zengl-1.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (102.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

zengl-1.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (37.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

zengl-1.0.1-cp36-cp36m-win_amd64.whl (37.8 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

zengl-1.0.1-cp36-cp36m-musllinux_1_1_x86_64.whl (100.5 kB view hashes)

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

zengl-1.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (101.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

zengl-1.0.1-cp36-cp36m-macosx_10_9_x86_64.whl (37.7 kB view hashes)

Uploaded CPython 3.6m 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