I can't get this to work. The upscaled image being filtered with bilinear
filtering. Can you tell me if the following code does nearest neighbour
scaling for you?
from pyglet.gl import *
import pyglet
class pixelatedSprite(pyglet.sprite.Sprite):
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)
window = pyglet.window.Window()
image = pyglet.image.load("gold.jpg")
# tried with image = pyglet.resource.image("gold.jpg") too - no dice
sprite = pixelatedSprite(image)
sprite.scale = 2
@window.event
def on_draw():
window.clear()
sprite.draw()
pyglet.app.run()
On Thursday, January 29, 2015 at 7:12:39 PM UTC+1, Leif Theden wrote:
>
> You will need to subclass pyglet.sprite.Sprite and override the following
> method:
>
> 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)
>
> The reason this works is due to the way pyglet handles the OpenGL state
> machine. When a sprite is going to get drawn, pyglet will execute the
> OpenGL commands inside Sprite.set_state so that the texture is rendered as
> intended. There really isn't an easier way. I've tested this, and on my
> computer, it works fine, even with fractional scale values on the sprite.
>
>
> 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.