peng3d.layer - Extensible 2D/3D Layering

class peng3d.layer.Layer(menu, window, peng)[source]

Base layer class.

A Layer can be used to separate background from foreground or the 3d world from a 2d HUD.

This class by itself does nothing, you will need to subclass it and override the draw() method.

draw()[source]

Called when this layer needs to be drawn.

Override this method in subclasses to redefine behavior.

on_menu_enter(old)[source]

Custom fake event handler called by Menu.on_enter() for every layer.

Useful for adding and removing event handlers per layer.

on_menu_exit(new)[source]

Custom fake event handler called by Menu.on_exit() for every layer.

Useful for adding and removing event handlers per layer.

on_redraw()[source]

Called whenever the Layer should redraw itself.

Note that this method should not be called manually, instead call redraw().

Returns:None
postdraw()[source]

Called after the draw() method is called.

This method can be used to reset OpenGL state to avoid conflicts with other code.

Override this method in subclasses to redefine behavior.

predraw()[source]

Called before the draw() method is called.

This method is used in the Layer2D() and Layer3D() subclasses for setting OpenGL state.

Override this method in subclasses to redefine behavior.

redraw()[source]

Call this to redraw the layer.

Note that the redraw will not happen immediately, rather on the next frame that this layer is rendered. This massively improves performance.

Returns:
class peng3d.layer.Layer2D(menu, window, peng)[source]

2D Variant of Layer() and a subclass of the former.

This class makes use of the predraw() method to configure OpenGL to draw 2-Dimensionally. This class uses PengWindow.set2d() to set the 2D mode.

When overriding the predraw() method, make sure to call the superclass.

predraw()[source]

Uses PengWindow.set2d() to enable a 2D OpenGL state.

class peng3d.layer.Layer3D(menu, window, peng, cam)[source]

3D Variant of Layer() and a subclass of the former.

This class works the same as Layer2D(), only for 3D drawing instead. This class uses PengWindow.set3d() to set the 3D mode.

Also, the correct glTranslatef() and glRotatef() are applied to simplify drawing objects. When writing the draw() method of this class, you will only need to use world coordinates, not camera coordinates. This allows for easy building of Games using First-Person-Perspectives.

predraw()[source]

Uses PengWindow.set3d() to enable a 3D OpenGL state.

class peng3d.layer.LayerGroup(menu, window, peng, group)[source]

Layer variant wrapping the supplied pyglet group.

group may only be an instance of pyglet.graphics.Group, else a TypeError will be raised.

Also note that both the predraw() and postdraw() methods are overwritten by this class.

See also

For more information about pyglet groups, see the pyglet docs.

postdraw()[source]

Re-sets the previous state.

predraw()[source]

Sets the group state.

class peng3d.layer.LayerWorld(menu, window, peng, world, viewname)[source]

Subclass of Layer3D() implementing a 3D Layer showing a specific WorldView.

All arguments passed to the constructor should be self-explanatory.

Note that you may not set any of the attributes directly, or crashes and bugs may appear indirectly within a certain during future re-drawing of the screen.

draw()[source]

Draws the view using the World.render3d() method.

on_menu_enter(old)[source]

Passes the event through to the WorldView to allow for custom behavior.

on_menu_exit(new)[source]

Same as on_menu_enter().

predraw()[source]

Sets up the attributes used by Layer3D() and calls Layer3D.predraw().

setView(name)[source]

Sets the view used to the specified name.

The name must be known to the world or else a ValueError is raised.