Starting Panda3D

Creating a New Panda3D Application

To start Panda3D, create a text file and save it with a .cxx extension. Any text editor will work. Enter the following text into your C++ file:

#include "pandaFramework.h"
#include "pandaSystem.h"

int main(int argc, char *argv[]) {
  // Open a new window framework
  PandaFramework framework;
  framework.open_framework(argc, argv);

  // Set the window title and open the window
  framework.set_window_title("My Panda3D Window");
  WindowFramework *window = framework.open_window();

  // Here is room for your own code

  // Do the main loop, equal to run() in python
  framework.main_loop();
  return 0;
}

For information about the Window Framework to open a window, click here.

pandaFramework.h and pandaSystem.h load most of the Panda3D modules. The main_loop() subroutine contains the Panda3D main loop. It renders a frame, handles the background tasks, and then repeats. It does not normally return, so it needs to be called only once and must be the last line in your script. In this particular example, there will be nothing to render, so you should expect a window containing an empty grey area.

Running the Program

The steps required to build and run your program were already explained in a previous page.

If Panda3D has been installed properly, a gray window titled My Panda3D Window will appear when you run your program. There is nothing we can do with this window, but that will change shortly.