Hey bobmitch,

Thanks heaps for that - it sounds like a more robust solution than my
dirty hack.

I'm still a little hazy on the implications.

So if you apply tex_border() to an TextureRegion in an atlas, and then
use that TexttureRegion as the image on a sprite, and draw the sprite
at 1.0 zoom and 0.0 rotation, does the small texture co-ordinate
offset you have applied result in any visible deformation of the image
on-screen?

I'll be trying out your code as an alternative to mine when I get home
tonight.




On Dec 1, 8:43 am, bobmitch <[email protected]> wrote:
> From another thread I started with the same complaint, I came up with
> this:
>
> 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)
>
> On Dec 1, 1:08 am, Jonathan Hartley <[email protected]> wrote:
>
> > I see, thanks.
>
> > Yeah, removing the texture from the atlas does fix it. I'd like to
> > keep the framerate if I'm able to though
>
> > Ahar! So adding a blank 1-pixel tall image to the atlas between each
> > horizontal row of textureregions seems to make it go away.
>
> >         from pyglet.image import load, SolidColorImagePattern
> >         SPACER = SolidColorImagePattern((0, 0, 0, 0)).create_image
> > (1024, 1)
>
> >         for filename in glob('%s/*.png' % (IMAGES_DIR)):
> >             self.atlas.add(SPACER)
> >             region = self.atlas.add(load(filename))
> >             ....
>
> > Not a watertight fix, no doubt, but it seems to work for my particular
> > set of images, which aren't likely to change much at this stage.
> > Hurrah! Thanks for the pointer Tristam.
>
> > On Nov 30, 11:53 pm, Tristam MacDonald <[email protected]> wrote:
>
> > > On Mon, Nov 30, 2009 at 4:22 PM, jonathan hartley 
> > > <[email protected]>wrote:
>
> > > > Hi there list,
>
> > > > I noticed that since I started subtly rotating my pyglet sprites (with
> > > > images stored in a texture atlas), i am seeing brown artifacts along the
> > > > sprite's top edges (here enlarged 8x):
>
> > > >http://brokenspell.googlecode.com/svn/trunk/docs/screenshots/unexpect...
> > > > I'm talking about the single-pixel straight lines above each duck.
>
> > > > I read what Brian wrote on this thread with much interest:
> > > >    "Depth buffer tile sorting?"
>
> > > >http://groups.google.com/group/pyglet-users/browse_thread/thread/7647...
>
> > > > Is what I am seeing perhaps exactly what Brian described?
>
> > > Regardless of what Brian described, you are seeing 'pixel bleed' from the
> > > next image in the texture atlas, due to the bilinear filtering. Either set
> > > the texture filter to GL_NEAREST, or remove your texture from the atlas, 
> > > and
> > > the artefacts should disappear.
>
> > > --
> > > Tristam MacDonaldhttp://swiftcoder.wordpress.com/

--

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