Ok, so I wrote a quick function than can be called with a texture
region (as returned by atlas.add) as a parameter.
This will automatically tweak the texture coordinates so that nearby
textures in the atlas aren`t sampled while filtering.
Hope somebody else finds this useful.


def tex_border (tex):
        """ takes a pyglet texture/region and insets the texture coordinates
by half a texel
                allowing for sub-pixel blitting without interpolation with 
nearby
regions within
                same texture atlas """
        coord_width = tex.tex_coords[3] - tex.tex_coords[0]
        coord_height = tex.tex_coords[4] - tex.tex_coords[1]
        x_adjust = (coord_width / tex.width) / 2.0      # get tex coord half 
texel
width
        y_adjust = (coord_height / tex.height) / 2.0    # get tex coord half
texel width
        # create new 12-tuple texture coordinate
        tex.tex_coords = (      tex.tex_coords[0]+x_adjust, tex.tex_coords
[1]+y_adjust, 0,
                                                tex.tex_coords[3]-x_adjust, 
tex.tex_coords[4]+y_adjust, 0,
                                                tex.tex_coords[6]-x_adjust, 
tex.tex_coords[7]-y_adjust, 0,
                                                tex.tex_coords[9]+x_adjust, 
tex.tex_coords[10]-y_adjust, 0)


atlas = pyglet.image.atlas.TextureAtlas (width=1024, height=1024)
pic = pyglet.image.load('bug.png')
bug_tex = atlas.add (small_red_bug_pic)
tex_border (bug_tex)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to