Rendering Images

In order to render an image, it is necessary to first create a flat piece of geometry consisting of two triangles (usually called a quad or a card) and then apply the desired image as a texture. Panda3D provides convenience methods for creating such a card automatically.


Just like OnscreenText, you can use OnscreenImage as a quick way to put an image onscreen. Use an OnscreenImage whenever you want a quick way to display an ordinary image without a lot of fancy requirements.

from direct.gui.OnscreenImage import OnscreenImage
imageObject = OnscreenImage(image='myImage.jpg', pos=(-0.5, 0, 0.02))

If you want, you can change the image into another one using setImage():


When you want to take the image away, use:


A full list of arguments that can be passed to the constructor is available on the OnscreenText page of the API reference.

Generating a card

CardMaker is a convenience class that can be used to generate a card with arbitrary dimensions. It can be used for rendering an image in the 3D or 2D scene. The image should be loaded as a texture and then applied to the generated card:

cm = CardMaker('card')
card = render2d.attachNewNode(cm.generate())

tex = loader.loadTexture('maps/noise.rgb')

This will generate a card that causes the image to be stretched to cover the entire screen. To preserve the aspect ratio of the image, it is necessary to instead parent it to “aspect2d”, as well as use either NodePath.set_scale() or CardMaker.set_frame() to adjust the card dimensions to match the aspect ratio of the image.

See the CardMaker class in the API reference for a full list of methods to configure the generated card.


To enable transparency in images, you must tell Panda3D to enable a transparency mode on the object, otherwise the transparent parts of the image will show up as black. This can be done using the following code:

from panda3d.core import TransparencyAttrib

image = OnscreenImage(image='myImage.png', pos=(0, 0, 0))

See the section on Transparency and Blending for some caveats about rendering objects with transparency.