This is a function which loads an image and creates a 3d plane proportional to the image. yresolution argument allows you to set the “pixel-perfect” resolution of the image, which means in that resolution one pixel in your image should match one pixel on your screen.
So this function can save you from using egg-texture-cards and if you have used Blender, it works like “2d cutout image importer” script.
This is how I believe OnScreenImage should have been implemented.
def loadImageAsPlane(filepath, yresolution = 600): """ Load image as 3d plane Arguments: filepath -- image file path yresolution -- pixel-perfect width resolution """ tex = loader.loadTexture(filepath) tex.setBorderColor(Vec4(0,0,0,0)) tex.setWrapU(Texture.WMBorderColor) tex.setWrapV(Texture.WMBorderColor) cm = CardMaker(filepath + ' card') cm.setFrame(-tex.getOrigFileXSize(), tex.getOrigFileXSize(), -tex.getOrigFileYSize(), tex.getOrigFileYSize()) card = NodePath(cm.generate()) card.setTexture(tex) card.setScale(card.getScale()/ yresolution) card.flattenLight() # apply scale return card
image = loadImageAsPlane('maps/circle.png') image.reparentTo(aspect2d) image.setTransparency(TransparencyAttrib.MAlpha)
Note that if you are using non power-of-two images (for your GUI), you will need to enable non power-of-two textures, or tell Panda to scale or pad them to the next bigger power-of-two, not the next smaller which is the default.
Put these lines in your Config.prc:
textures-auto-power-2 1 textures-power-2 up
This will tell Panda to try to enable non power-of-two images and if your GPU doesn’t support them, it will then scale those images up, not down.