In cocos2d or pyglet, the complement parameter of the texture used for 2D sprites seems to be GL_LINEAR
by default, and if you cut out a rectangle from a picture of tiled sprites and use it, the adjacent pixel will blur a little.
Well, if you scale the sprite, the border will not be blurred, but only the inside will be blurred, and it will look like OpenGL. I want to make it by dividing it with a jagged picture with an 8-bit feeling.
This seems to be good if you add GL_NEAREST
to GL_TEXTURE_MAG_FILTER
and GL_TEXTURE_MIN_FILTER
of the texture. I will attach it when I load it.
image = pyglet.image.load('hoge.png')
glBindTexture(image.texture.target, image.texture.id)
glTexParameteri(image.texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(image.texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
sprite = Sprite(image.texture)
This will not blur the pixels.
sprite1 = Sprite(image.texture.get_region(0, image.height - 32, 32, 32))
sprite2 = Sprite(image.texture.get_region(32, image.height - 32, 32, 32))
actor_layer.add(sprite1)
actor_layer.add(sprite2)
The pixels next to the tile also don't seep out.
When loading a TMX tile map, it seems that the image is implicitly loaded and becomes a separate texture, so apply it to all tile definitions in the tile set.
map_resource = cocos.tiles.load('fuga.tmx')
for res in map_resource.contents.values():
if isinstance(res, cocos.tiles.TileSet): #Tile set only
for tile in res.values():
glBindTexture(tile.image.texture.target, tile.image.texture.id)
glTexParameteri(tile.image.texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(tile.image.texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
Before application
After application