I have been making a 2.5D game, but I ran into a problem. a lot of the textures are very low resolution, and none of them have powers of 2 as dimensions. I tried padding the textures and transforming the UVs, but the result is still blurry, no matter what I do. My code is as follows:
loadPrcFileData('', 'textures-power-2 pad')
np = loader.loadModel("models/bolt.egg")
tex = loader.loadTexture("textures/bolt_tex.png")
tex.setWrapU(Texture.WMClamp)
tex.setWrapV(Texture.WMClamp)
scl = tex.getTexScale()
np.setTexture(tex, 1)
np.setTexScale(TextureStage.getDefault(),scl[0],scl[1])
np.reparentTo(render)
What result are you trying to achieve? Do you want the textures to be presented as pixel-art, with the edges between pixels clearly defined?
If so, then you might find these threads useful to you: Pixel-art sprite cards and a non-power-of-two pixel-centric texture loader for DirectGUI.
Yes, that is exactly what i am trying to do. Is there any way to put those textures on a 3d model besides a card? Whenever i try to put those images onto a card, it works fine, but when i try to put it onto other geometry, the texture gets blurry.
I think that the main thing should be to set the texture’s min- and mag- filters, as the sprite class to which I linked seems to do. However, there may well be other elements that I’m missing, so I defer to others who may have better information for you on this.
Thank you for pointing me in the right direction with the min and mag filters. I found the page on texture filter types in the manual, and got the code working. Here’s what I ended up with.
loadPrcFileData('', 'textures-power-2 pad')
np = loader.loadModel("models/bolt.egg")
tex = loader.loadTexture("textures/bolt_tex.png")
tex.setWrapU(Texture.WMClamp)
tex.setWrapV(Texture.WMClamp)
tex.setMagfilter(Texture.FTNearest)# \ these are the new lines
tex.setMinfilter(Texture.FTNearest)# /
scl = tex.getTexScale()
np.setTexture(tex, 1)
np.setTexScale(TextureStage.getDefault(),scl[0],scl[1])
np.reparentTo(render)
1 Like