I have a tileset of 8x8 pixel images, and I want to resize them in my game so they'd be double that (16x16 pixels, e.g. turning each pixel into a 2x2 block.) What I'm trying to achieve is a Minecraft-like effect, where you have small pixel images scale to larger blockier pixels.
In Pyglet, the sprite's scale
property blurs the pixels. Is there some other way?
Working Code:
Here's the solution that works (thanks to DMan's persistence and Jimmy's insight):
image = resource.image('tileset.png')
texture = image.get_texture()
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
texture.width = 16 # resize from 8x8 to 16x16
texture.height = 16
texture.blit(100, 30) # draw
from pyglet.gl import *
and then make a call to talisman.org/opengl-1.1/Reference/glTexParameter.html withGL_NEAREST
. \$\endgroup\$glEnable(GL_TEXTURE_2D)
. Then let's say you had a call toa = image.load('blah.jpg')
. Assigntex = a.texture
thenglBindTexture(GL_TEXTURE_2D, texture.id)
and finally a call topyglet.gl.glTexParameteri(pyglet.gl.GL_TEXTURE_2D, pyglet.gl.GL_TEXTURE_MIN_FILTER, pyglet.gl.GL_NEAREST)
. I'm not too familiar with the namespace for OpenGL in python, so the I left the full call qualified. Since we imported OpenGL, I believe you can remove at least the pyglet in the front, and maybe gl too. \$\endgroup\$glTexParameteri
. OpenGL 1/2/~3 which I presume Pyglet is based on have these immediate mode commands. That is, you execute a command to change the state, then everything after it will change. I'd begin by moving the calls underneath the gl calls. \$\endgroup\$