-1

I try to rotate a simple sprite with this code:

test_img = pyglet.resource.image('img.png')
self.test_sprite = pyglet.sprite.Sprite(img=test_img,x=300,y=400, batch=self.main_batch)

def update(self, dt):
    self.test_sprite.rotation -= float(100 * dt)

it works great, but I see artifact while it rotates, see the picture below, the left is a static image, the right is the one rotating:

enter image description here

I did a quick search and I find a discussion regarding it here:

https://groups.google.com/forum/#!topic/pyglet-users/5NiNT1vRHGw

But honestly I'm a newbie in pyglet and I don't get how should I amend the code above to remove the artifact.

UPDATE:

I fix the issue with the following code, but still not sure if it's the best way to do it:

test_img = pyglet.resource.image('img.png').get_texture()
glTexParameteri(test_img.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(test_img.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

self.test_sprite = pyglet.sprite.Sprite(img=test_img,x=300,y=400, batch=self.main_batch) 

def update(self, dt): 
   self.test_sprite.rotation -= float(100 * dt)
NiBE
  • 857
  • 2
  • 16
  • 39

2 Answers2

0

It's not so much a coding problem, but that there's no safety margin around/between images in the texture (atlas) you use. You should a little margin around your picture (1 pixel should suffice), so that sample filtering doesn't bleed into the neighbour, clamps or wraps around.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • thanks for the answer but I really don't know how to do what you suggest – NiBE Jul 09 '15 at 09:41
  • @NiBE: Launch image manipulation program (Photoshop, GIMP, Paint.net), open image file, enlarge canvas, center the preexisting image, save image file. As I told: Not a coding but an arts department problem. – datenwolf Jul 09 '15 at 09:43
  • Ok thanks I got it right then, I left 1pixel for each side of the sprite, centering the preexisting image, but I still see the artifacts – NiBE Jul 09 '15 at 10:13
0

Old question and no upvote? The issue is commonly referred to as "Texture bleeding".

If anyone is stumbling upon this and need a solution there is a plugin for GIMP that handles this as well as margins:

http://registry.gimp.org/node/26044

Nine Magics
  • 637
  • 2
  • 8
  • 17