Using multiple displays

Spanning the render view across multiple monitors can greatly enhance player immersion. In a racing game, for example, it's great to not only be able to see out of the car's front window, but also have the side windows available in two extra monitors.

In this short recipe you will learn how to configure Panda3D to use multiple displays and render across two monitors. While the sample assumes two display devices to be used, you can easily follow the principles presented in the following section to use three, four, or even more display devices.

Getting ready

This recipe requires the base code from Setting up the game structure to be present before proceeding. Please revisit this article found in Chapter 1 if you haven't read it yet.

Naturally, you will need two monitors for this recipe, which have to use the same resolution to properly display the sample code's output.

How to do it...

Follow these steps to create an application that takes advantage of a multi-monitor setup:

  1. Open Application.py and copy the following code:
    from direct.showbase.ShowBase import ShowBase
    from direct.actor.Actor import Actor
    from pandac.PandaModules import loadPrcFileData
    loadPrcFileData("", "win-origin 0 0")
    loadPrcFileData("", "win-size 2880 900")
    loadPrcFileData("", "undecorated 1")
    class Application(ShowBase):
    def __init__(self):
    ShowBase.__init__(self)
    self.pandas = []
    for i in range(8):
    panda = Actor("panda", {"walk": "panda-walk"})
    panda.reparentTo(render)
    panda.loop("walk")
    panda.setX(-28 + i * 8)
    self.pandas.append(panda)
    self.cam.setPos(0, -40, 6)
    
    
  2. Press F6 to run the code. You will now see the following scene across your monitors:
    How to do it...
  3. The sample uses a borderless window without controls, so use Alt+F4 to quit.

How it works...

The entire necessary configuration is done in the three highlighted lines of the previous source code. First, the window origin is set to the top left corner of the first display. Then we set the window size to 2880 by 900 pixels. This makes the window span across two monitors with a resolution of 1440 by 900 pixels. For displays with a different size, just multiply the horizontal resolution of your display by two and use the original vertical resolution. The last configuration option makes the window borderless and removes the controls for minimizing, maximizing, and closing the window. Panda3D provides no native fullscreen rendering mode for multiple displays. But using these settings, we are able to make the application window fill both screens and make it appear as if it were set to fullscreen mode.

The same effect can be achieved by adding the following lines shown to your Config.prc file.

win-origin 0 0
win-size 2880 900
undecorated 1
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset