How to remove and restore a display region

I split the screen by creating another display region:

        dr1 = cam.node().getDisplayRegion(0)
        dr2 =, 0.4, 0.2, 0.6)
        dr.setDimensions(0, 0.5, 0, 1)
        dr2.setDimensions(0.5, 1, 0, 1)

        # then restore it later
        dr1.setDimensions(0, 1, 0, 1)

The restoration code seems not working very well. The window after restoration has a wrong aspect ratio, it becomes double wide. What is the proper way to do a restoring here ?

That should do it (except for the strange reference to “dr” instead of “dr1” in the second line). There must be something else changing your aspect ratio. This is a property of base.camLens, and is normally adjusted automatically by Panda when your window is resized by the user.


Here is the sample code:

revised-by: Fabius Astelix @ 2009-02
summary: Here how to have remote cameras in a scene: a camera is shooting a scene that is renderer in rectangular regions in the main scene.
from pandac.PandaModules import Camera, DirectionalLight
from pandac.PandaModules import NodePath,TextNode
from pandac.PandaModules import Point3,Vec3,Vec4
from import Actor
from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart

class World(DirectObject):
  def __init__(self):
    self.accept("escape", self.restore)
    self.accept("s", self.split)

  def split(self):
    self.splitScreen(, self.displayRegion2())

  def displayRegion1(self):, -10, 5) Actor('panda.egg', {'walk' : 'panda-walk.egg'}),0.25,0.25)"walk")

    dlight = NodePath(DirectionalLight('dlight'))

  def displayRegion2(self):
    dr2 =, 0.4, 0.2, 0.6)

    render2 = NodePath('render2')
    self.render2 = render2
    cam2 = render2.attachNewNode(Camera('cam2'))

    env = loader.loadModel('environment.egg')

    cam2.setPos(-22.5, -387.3, 58.1999)
    return cam2

  def splitScreen(self, cam, cam2):
    dr = cam.node().getDisplayRegion(0)
    self.dr1 = dr
    dr2 = cam2.node().getDisplayRegion(0)
    self.dr2 = dr2

    dr.setDimensions(0, 0.5, 0, 1)
    dr2.setDimensions(0.5, 1, 0, 1)

    cam.node().getLens().setAspectRatio(float(dr.getPixelWidth()) / float(dr.getPixelHeight()))
    cam2.node().getLens().setAspectRatio(float(dr2.getPixelWidth()) / float(dr2.getPixelHeight()))

  def restore(self):
      # then restore it later

      self.dr1.setDimensions(0, 1, 0, 1)


Run the program, the panda looks fine.
Press ‘s’, the screen split. The panda still looks fine.
Press ‘escape’. Now the panda becomes a fat one.

Where is the problem ?

It’s this line here:

    cam.node().getLens().setAspectRatio(float(dr.getPixelWidth()) / float(dr.getPixelHeight())) 

You’re fiddling with the aspect ratio of the camera to compensate for the new, skinny DisplayRegion. When you make the DisplayRegion wide again, you’ll have to fiddle it back.



I am really stupid and blind. Thank you for pointing this silly mistake.