Renderer

All rendering related functions and classes. The ModernGL python library is used for all rendering functions in pysg.

Base Class

class pysg.renderer.Renderer(scene: pysg.scene.Scene, camera: pysg.camera.Camera)

Base class. All renderer implementations need to inherit form this class.

Parameters:
  • scene (Scene) – Scene which shall be rendered.
  • camera (Camera) – Camera which is used to view scene.
ctx = None

The ModernGL context object which can be used to set some OpenGL related settings. For example the context can be used to deactivate backface culling:

camera.ctx.disable(moderngl.CULL_FACE)

See https://moderngl.readthedocs.io/en/stable/reference/context.html for more information.

Type:Context
render() → None

Base render function which needs to be implemented by sub-classes.

GLRenderer

class pysg.renderer.GLRenderer(scene: pysg.scene.Scene, camera: pysg.camera.Camera)

Render the scene to a given viewport.

Parameters:
  • scene (Scene) – Scene which shall be rendered.
  • camera (Camera) – Camera which is used to view scene.
render() → None

Set viewport and call _render() function of base class.

viewport = None

Viewport is a tuple of size four (x, y, width, height).

Type:tuple

HeadlessGLRenderer

class pysg.renderer.HeadlessGLRenderer(scene: pysg.scene.Scene, camera: pysg.camera.Camera, *, width: int, height: int)

Render the scene to a framebuffer which can be read to CPU memory to be used as an image.

Parameters:
  • scene (Scene) – Scene which shall be rendered.
  • camera (Camera) – Camera which is used to view scene.
  • width (float) – Width of output image in pixel
  • height (float) – Height of output image in pixel
current_image() → bytes

Render the current scene and camera into a buffer. The buffer can later be returned with the ‘current_image’ method.

Returns:The rendered byte array. Copy from vRAM to RAM.
Return type:bytes
render() → None

Render the current scene and camera into a buffer. The buffer can later be returned with the current_image method.