Howdy again.
Would anyone happen to have collected or written any best practices docs,
examples, or utilities for working with batches and groups, or simply have
any fundamental tips?
Reason I ask is that my first attempt, built upon the brief description in
the Pyglet programming guide, resulted in many subclasses of graphics.Group
and some hairy problems like how to elegantly insert translations for a
group of textures. For example, a cube made out of six quads.
I ended up doing something like this:
# Add hierarchical group to batch (init the modes, lights, and
transformations)
group = TextureEnableGroup(parent=
LightingOnGroup(parent=
ShadeModelGroup(parent=
TranslationGroup(parent=pyglet.graphics.OrderedGroup(0))))
batch.add(1, 0, group, '0g1f')
group = TextureBindGroup(parent=
pyglet.graphics.OrderedGroup(1))
# add cube vertex lists to batch
for name in cube_sides: # 'top', 'front', etc.
verts = cube_sides[name]
norms = cube_normals[name]
texcoords = cube_tex_coords[name]
batch.add(len(verts), GL_QUAD, group,
# vertex list specs...
)
# Add hierarchical group to batch (Unset-modes in the same manner as
the first group)
Hope that conveys the general idea. If not, I've uploaded the full program
here:
http://worldkit.googlecode.com/files/block_vs_group.zip -- see class
ShadedCubeScene or TexturedCubeScene.
Initially, I found it unwieldy to specify one polygon just to init the modes
via a hierarchical group, all but one polygon in a loop for economy, and the
final polygon to unset the modes via another group. What if I only had one
polygon, I'd be SOL. :) So naturally I wonder how it's typically done.
Grasping for ideas, I discovered that Pyglet batches would let me add an
empty generic vertex attribute with a group that simply changes state, as
shown above. I have no idea what the generic vertex attributes are intended
for, and half expect the practice might be considered an abuse. Would anyone
comment on this, please?
Also, if anyone has the guts to dig into my noob code I would greatly
appreciate his/her constructive feedback. =) If I'm doing anything
particularly wrong, I'd prefer to nip the bad habit in the bud. (And you'll
notice light and shadow are a work in progress.)
Thanks in advance for your sage advice! :)
Gumm
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.