Compact Python OpenGL rendering library
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.
Examples
pip install zengl[examples]
grass.py
envmap.py
normal_mapping.py
rigged_objects.py
instanced_crates.py
julia_fractal.py
blending.py
render_to_texture.py
pybullet_box_pile.py
pygmsh_shape.py
texture_array.py
monkey.py
reflection.py
polygon_offset.py
blur.py
hello_triangle.py
hello_triangle_srgb.py
viewports.py
points.py
wireframe_terrain.py
crate.py
sdf_example.py
sdf_tree.py
mipmaps.py
conways_game_of_life.py
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
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
zengl-1.6.0.tar.gz
(33.9 kB
view details)
File details
Details for the file zengl-1.6.0.tar.gz
.
File metadata
- Download URL: zengl-1.6.0.tar.gz
- Upload date:
- Size: 33.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7caf64bf489dcb1868d69d57a424fa7a9a6eac08a84b5f1a3c56cd46df8ccfe7 |
|
MD5 | ffd07cc995b87d661e77c22dad5f7912 |
|
BLAKE2b-256 | 8a9c6baddacc9a687517c1081a96aaf9fb0b0637cffef65e8f7ff0846341364e |