Thanks a lot, this is very helpful for me. As far as I can tell this only 
works when you use pyglet.image.load -- not pyglet.resource.image -- to 
load an image file. I am unsure why... Something to do with different 
classes (ImageData vs. Texture vs. TextureRegion) perhaps? 

Is pyglet.resource.image supposed to be more efficient?

On Saturday, January 31, 2015 at 5:31:47 AM UTC+1, Leif Theden wrote:
>
> so, i may have made my reply too fast.  mattis n, this works and is tested 
> on my system.
>
> from pyglet.gl import *
> import pyglet
>
>
> def make_pixelated(sprite):
>     """ Make the goup of this sprite pixelated.
>
>     :param sprite: pyglet.sprite.Sprite
>     :return: None
>     """
>     import types
>
>     def set_state(self):
>         glEnable(self.texture.target)
>         glBindTexture(self.texture.target, self.texture.id)
>         glPushAttrib(GL_COLOR_BUFFER_BIT)
>         glEnable(GL_BLEND)
>         glTexParameteri(self.texture.target, GL_TEXTURE_MAG_FILTER, 
> GL_NEAREST)
>         glBlendFunc(self.blend_src, self.blend_dest)
>
>     group = sprite._group
>     group.set_state = types.MethodType(set_state, group)
>
> window = pyglet.window.Window()
> image = pyglet.image.load("gold.jpg")
> batch = pyglet.graphics.Batch()
> sprite = pyglet.sprite.Sprite(image, batch=batch)
>
> make_pixelated(sprite)
>
> sprite.scale = 2
>
>
> @window.event
> def on_draw():
>     window.clear()
>     batch.draw()
>
> pyglet.app.run()
>
>
> I missed the part where it isn't the sprite that sets the state, it is the 
> group that it belongs to.  What you see above is a hack that adds our 
> 'pixelated render' to the group that renders the sprite.  The correct was 
> of doing this isn't super obvious, due to how groups are created.  this is 
> just works easier.
>
>
> On Thursday, January 1, 2015 at 5:54:46 AM UTC-6, Salvakiya wrote:
>>
>> I am relatively new to python and am creating a game engine called PyGM. 
>> I am trying to create Game Maker logic in Python. I chose Pyglet to handle 
>> the graphics on this project however I have run into a few issues.
>>
>> The first issue was I could not scale a sprite without it becoming blurry 
>> due to the biliniar texture filtering. After some research I found a fix by 
>> using this code:
>>
>> def texture_set_mag_filter_nearest(texture):
>>     glBindTexture(texture.target, texture.id)
>>     glTexParameteri(texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
>>     glBindTexture(texture.target, 0)
>>
>> there is however another issue. The sprites look fine when scaled to a 
>> whole number but when scaling to anything else(like 2.5) produces strange 
>> results.
>>
>> Is there a way to fix this?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to