7 min read


Panda3D 1.7 Game Developer’s Cookbook

Panda3D is a very powerful and feature-rich game engine that comes with a lot of features needed for creating modern video games. Using Python as a scripting language to interface with the low-level programming libraries makes it easy to quickly create games because this layer of abstraction neatly hides many of the complexities of handling assets, hardware resources, or graphics rendering, for example. This also allows simple games and prototypes to be created very quickly and keeps the code needed for getting things going to a minimum.

Panda3D is a complete game engine package. This means that it is not just a collection of game programming libraries with a nice Python interface, but also includes all the supplementary tools for previewing, converting, and exporting assets as well as packing game code and data for redistribution. Delivering such tools is a very important aspect of a game engine that helps with increasing the productivity of a development team.

The Panda3D engine is a very nice set of building blocks needed for creating entertainment software, scaling nicely to the needs of hobbyists, students, and professional game development teams. Panda3D is known to have been used in projects ranging from one-shot experimental prototypes to full-scale commercial MMORPG productions like Toontown Online or Pirates of the Caribbean Online.

Before you are able to start a new project and use all the powerful features provided by Panda3D to their fullest, though, you need to prepare your working environment and tools. By the end of this article, you will have a strong set of programming tools at hand, as well as the knowledge of how to configure Panda3D to your future projects’ needs.

Downloading and configuring NetBeans to work with Panda3D

When writing code, having the right set of tools at hand and feeling comfortable when using them is very important. Panda3D uses Python for scripting and there are plenty of good integrated development environments available for this language like IDLE, Eclipse, or Eric. Of course, Python code can be written using the excellent Vim or Emacs editors too.

Tastes do differ, and every programmer has his or her own preferences when it comes to this decision. To make things easier and have a uniform working environment, however, we are going to use the free NetBeans IDE for developing Python scripts. This choice was made out of pure preference and one of the many great alternatives might be used as well for following through the recipes in this article, but may require different steps for the initial setup and getting samples to run.

In this recipe we will install and configure the NetBeans integrated development environment to suit our needs for developing games with Panda3D using the Python programming language.

Getting ready

Before beginning, be sure to download and install Panda3D. To download the engine SDK and tools, go to www.panda3d.org/download.php:

The Panda3D Runtime for End-Users is a prebuilt redistributable package containing a player program and a browser plugin. These can be used to easily run packaged Panda3D games.

Under Snapshot Builds, you will be able to find daily builds of the latest version of the Panda3D engine. These are to be handled with care, as they are not meant for production purposes.

Finally, the link labeled Panda3D SDK for Developers is the one you need to follow to retrieve a copy of the Panda3D development kit and tools. This will always take you to the latest release of Panda3D, which at this time is version 1.7.0. This version was marked as unstable by the developers but has been working in a stable way for this article. This version also added a great amount of interesting features, like the web browser plugin, an advanced shader, and graphics pipeline or built-in shadow effects, which really are worth a try.

Click the link that says Panda3D SDK for Developers to reach the page shown in the following screenshot:

Here you can select one of the SDK packages for the platforms that Panda3D is available on. This article assumes a setup of NetBeans on Windows but most of the samples should work on these alternative platforms too, as most of Panda3D’s features have been ported to all of these operating systems.

To download and install the Panda3D SDK, click the Panda3D SDK 1.7.0 link at the top of the page and download the installer package. Launch the program and follow the installation wizard, always choosing the default settings. In this and all of the following recipes we’ll assume the install path to be C:Panda3D-1.7.0, which is the default installation location. If you chose a different location, it might be a good idea to note the path and be prepared to adapt the presented file and folder paths to your needs!

How to do it…

Follow these steps to set up your Panda3D game development environment:

  1. Point your web browser to netbeans.org and click the prominent Download FREE button:

    Panda3D Game Development tutorial

  2. Ignore the big table showing all kinds of different versions on the following page and scroll down. Click the link that says JDK with NetBeans IDE Java SE bundle.

    Panda3D Game Development tutorial

  3. This will take you to the following page as shown here. Click the Downloads link to the right to proceed.

    Panda3D Game Development tutorial

  4. You will find yourself at another page, as shown in the screenshot. Select Windows in the Platform dropdown menu and tick the checkbox to agree to the license agreement. Click the Continue button to proceed.

    Panda3D Game Development tutorial

  5. Follow the instructions on the next page. Click the file name to start the download.

    Panda3D Game Development tutorial

  6. Launch the installer and follow the setup wizard.
  7. Once installed, start the NetBeans IDE.
  8. In the main toolbar click Tools | Plugins.
  9. Select the tab that is labeled Available Plugins.
  10. Browse the list until you find Python and tick the checkbox next to it:

    Panda3D Game Development tutorial

  11. Click Install. This will start a wizard that downloads and installs the necessary features for Python development.
  12. At the end of the installation wizard you will be prompted to restart the NetBeans IDE, which will finish the setup of the Python feature.
  13. Once NetBeans reappears on your screen, click Tools | Python Platforms.
  14. In the Python Platform Manager window, click the New button and browse for the file C:Panda3D-1.7.0pythonppython.exe.
  15. Select Python 2.6.4 from the platforms list and click the Make Default button. Your settings should now reflect the ones shown in the following screenshot:

    Panda3D Game Development tutorial

  16. Finally we select the Python Path tab and once again, compare your settings to the screenshot:

    Panda3D Game Development tutorial

  17. Click the Close button and you are done!

How it works…

In the preceding steps we configured NetBeans to use the Python runtime that drives the Panda3D engine and as we can see, it is very easy to install and set up our working environment for Panda3D.

There’s more…

Different than other game engines, Panda3D follows an interesting approach in its internal architecture. While the more common approach is to embed a scripting runtime into the game engine’s executable, Panda3D uses the Python runtime as its main executable. The engine modules handling such things as loading assets, rendering graphics, or playing sounds are implemented as native extension modules. These are loaded by Panda3D’s custom Python interpreter as needed when we use them in our script code.

Essentially, the architecture of Panda3D turns the hierarchy between native code and the scripting runtime upside down. While in other game engines, native code initiates calls to the embedded scripting runtime, Panda3D shifts the direction of program flow. In Panda3D, the Python runtime is the core element of the engine that lets script code initiate calls into native programming libraries.

To understand Panda3D, it is important to understand this architectural decision. Whenever we start the ppython executable, we start up the Panda3D engine.

If you ever get into a situation where you are compiling your own Panda3D runtime from source code, don’t forget to revisit steps 13 to 17 of this recipe to configure NetBeans to use your custom runtime executable!

Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.


Please enter your comment!
Please enter your name here