Background Image

Thank’s a lot!

I had the same need and I solved it using the OnscreenImage technic with render2dp, my code below:

def loadBackground(imagepath):
        ''' Load a background image behind the models '''

        # We use a special trick of Panda3D: by default we have two 2D renderers: render2d and render2dp, the two being equivalent. We can then use render2d for front rendering (like modelName), and render2dp for background rendering.
        self.background = OnscreenImage(parent=render2dp, image=imagepath) # Load an image object
        base.cam2dp.node().getDisplayRegion(0).setSort(-20) # Force the rendering to render the background image first (so that it will be put to the bottom of the scene since other models will be necessarily drawn on top)

I used this way over the rendering of a plane in the 3D render because my images can be of different sizes and I didn’t want to have to do tedious maths calculations to correctly place my background images each time I loaded one (plus it was less efficient since this method required to call a few more functions).

Also another thread I’ve found interesting but did not yet use: loadImageAsPlane(), a replacement for OnscreenImage:
[loadImageAsPlane())