Renderers

A renderer object can be bound to a group, defining how the particles of the group are drawn. Renderers can be invoked via the ParticleSystem, each ParticleGroup or individually as desired. Like Controllers, renderers have a simple API and are easy to create for yourself.

OpenGL Renderers

class lepton.renderer.PointRenderer

Simple particle renderer using GL_POINTS. All particles in the group are rendered with the same point size

PointRenderer(point_size, texturizer=None)

point_size – Size of GL_POINTS points to draw (float)

texturizer – Texturizer used to apply texture to particles. If specified, the points are drawn using GL_POINT_SPRITES. Note that point sprites have fixed texture coordinates, thus they cannot use custom per-particle coordinates computed by the texturizer.

draw()

Draw the particles in the specified group using GL_POINTS

point_size

Size of GL_POINTS drawn

texturizer

Texturizer used to apply texture to particles

class lepton.renderer.BillboardRenderer

Particle renderer using textured billboard-aligned quads quads are aligned orthogonal to the model-view matrix

BillboardRenderer(texturizer=None)

texturizer – A texturizer object that generates texture coordinates for the particles and sets up texture state. If not specified, texture coordinates are fixed at (0,0) for the lower-left corner of each particle quad and (1,1) for the upper-right. Without a texturizer the application is responsible for setting up the desired texture state before invoking the renderer.

draw()

Draw the particles using textured billboard quads

texturizer

A texturizer object that generates texture coordinates for the particles and sets up texture state for the renderer.

Texturizers

class lepton.texturizer.FlipBookTexturizer

Animates sets of texture coordinates from a single resident “flipbook” texture to a particle group according to each particle’s age.

FlipBookTexturizer(texture, coords, duration, loop=True, dimension=2, filter=GL_LINEAR, wrap=GL_CLAMP, aspect_adjust_width=False, aspect_adjust_height=False)

texture – OpenGL texture name, acquired via glGenTextures. It is up to the application to load the texture’s data before using the texturizer

coords – A sequence of texture coordinate sets. Each set is used as one frame of the animation. Each set consists of coordinates for the four corners of the quad drawn for a particle (8 or 12 floats). When using 8 floats, the r value of the texture coordinates is set to 0.

duration – The time duration of each frame. This may be specified as a single value, if the duration of all frames are the same, or as a sequence of individual duration values for each frame.

loop – If true (the default), the animation will continuously loop through the frames from last back to first. If false, the animation will stop on the last frame.

dimension – The number of texture coordinate dimensions. Use 2 for 2D textures (the default) or 3 for 3D textures.

filter – The OpenGL filter used to scale the texture when rendering. One of: GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, etc.

wrap – The OpenGL wrapping parameter for texture application when rendering. One of: GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_EDGE, etc.

aspect_adjust_width, aspect_adjust_height – These two flags are used to match the aspect ratio of the particle’s width and height to the dimensions of its texture coordinates. This is useful to match particles to textures of various dimensions without distortion. If one flag is set, the texturizer adjusts the width or height of the particle size respectively as appropriate. Only one of these flags may be set at one time.

classmethod from_images(images, duration, loop=True, dimension=2, filter=None, wrap=None, aspect_adjust_width=False, aspect_adjust_height=False)

Create a FlipBookTexturizer from a sequence of Pyglet images

Note all the images must be able to fit into a single OpenGL texture, so their combined size should typically be less than 1024x1024

class lepton.texturizer.SpriteTexturizer

Applies a set of static texture coordinates from a single resident texture to a particle group

SpriteTexturizer(texture, coords=(), weights=(), filter=GL_LINEAR, wrap=GL_CLAMP, aspect_adjust_width=False, aspect_adjust_height=False)

texture – OpenGL texture name, acquired via glGenTextures. It is up to the application to load the texture’s data before using the texturizer

coords – A sequence of texture coordinate sets. Each set consists of coordinates for the four corners of the quad drawn for a particle (8 floats). Sets may consist of 4 coordinate pairs (tuples) or simply 8 floats corresponding to the bottom left, bottom right, top right and top left texture coordinates respectively. if omitted, coords defaults to a single set of coordinates: (0,0, 1,0, 1,1, 0,1)

weights – An optional list of weight values applied to the coordinate sets specified in coords. Must have the same length as the coords sequence. If specified, the coordinate set is randomly chosen for each particle in proportion to its weight. If not specified, the the coordinates are assigned evenly to the particles

filter – The OpenGL filter used to scale the texture when rendering. One of: GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, etc.

wrap – The OpenGL wrapping parameter for texture application when rendering. One of: GL_CLAMP, GL_REPEAT, GL_CLAMP_TO_EDGE, etc.

aspect_adjust_width, aspect_adjust_height – These two flags are used to match the aspect ratio of the particle’s width and height to the dimensions of its texture coordinates. This is useful to match particles to textures of various dimensions without distortion. If one flag is set, the texturizer adjusts the width or height of the particle size respectively as appropriate. Only one of these flags may be set at one time.

classmethod from_images(images, weights=None, filter=None, wrap=None, aspect_adjust_width=False, aspect_adjust_height=False)

Create a SpriteTexturizer from a sequence of Pyglet images.

Note all the images must be able to fit into a single OpenGL texture, so their combined size should typically be less than 1024x1024

Pygame Renderers

class lepton.pygame_renderer.FillRenderer(surface, flags=None)

Renders particles to a pygame surface using simple fills

class lepton.pygame_renderer.BlitRenderer(surface, particle_surface, rotate_and_scale=False)

Renders particles by blitting to a pygame surface