how to render an exact copy of an image?

i have searched many hours, but not found how to render a clean, pixel-perfect image on any x,y-position on the screen.

it is very importend for me to render a image without! automatic scaling or aspect-correction, without repositioning oder using filters on it

i.e. i would say: render my pic “car.png” (40x20) on the screen-position x=340,y=400 after you have completed rendering the previous objects on the scene.

my code:

imageObject = OnscreenImage(image = ‘pic.png’, pos = (0,0,0))

renders the pic, but scales it to fit the entire window and the pic shows
“washy”. if i scale the pic down, it has not the correct aspect-ration and it is always washy.

what must i do to render a image without any adjustment from panda3d
on a fix screen-position?


or it is possible to use pygame to render 2d-stuff direct in the framebuffer of panda3d?

Here’s some sample code showing how:

from direct.directbase import DirectStart
from pandac.PandaModules import *
cm = CardMaker("blah")
cm.setFrame(-1, 1, -1, 1)
cm.setUvRange(Point2(0, 0), Point2(1, 1))
card = base.render2d.attachNewNode(cm.generate())
tex = Texture()
def adjustSize(task):
  card.setScale(1/float(*tex.getXSize(),1, 1/float(*tex.getYSize())
  return task.cont

taskMgr.add(adjustSize, "adjustSize")

Though really, I don’t recommend doing it this way. This will be very slow on older GPU’s. (thats why panda automatically rescales the texture to a power-of-two image: because most gpu’s can process that much faster. The setTexturesPower2 is to override that.)

thank you !!!

this works great, but now i try to understand the code…

I’ve also solved this in a way that shouldn’t trip up on non power of two hardware but could potentially waste a fair bit of memory. Copy the base class from this topic and create the following subclass:

class ClearPic(Sprite2d):

    PIXEL_SCALE = 400
    def __init__(self, img):
        Sprite2d.__init__(self, img, anchorY="Center", anchorX="Center")
        #self.texture.setAnisotropicDegree(2) # Not sure how if you want this.

To use it:

car_pic = ClearPic('car.png')
# Clean up the node
del car_pic