Panda3D Manual: The Window Framework
<<prev | top | next>> |
Note: The WindowFramework class is for use in C++ only. If you use Python, you can just use DirectStart to open a window and skip this page. This page will explain how to use the WindowFramework class in C++ to open a blank window. First of all, we need to include the appropiate header files:
    #include "pandaFramework.h"
    #include "pandaSystem.h"
Second, we need to create an instance of the WindowFramework class and open the main int of course.
    PandaFramework framework;
    int main(int argc, char *argv[]) {
Now, we must open the framework, give the window a nice title and open the window:
    framework.open_framework(argc, argv);
    framework.set_window_title("Hello World!");
    //open it!
    WindowFramework *window = framework.open_window();
Optionally, we can enable keyboard support, in case we want to check for keyboard presses, and we can enable the default camera trackball.
    //enable keyboard detection
    window->enable_keyboard();
    //enable default camera movement
    window->setup_trackball();
Now, we're going to check if the window has opened successfully. If so, the main loop must be called, using the function framework.main_loop(). This is equal to the run() function in Python.
    if (window != (WindowFramework *)NULL) {
      nout << "Opened the window successfully!\n";

      //put here your own code, such as the loading of your models

      framework.main_loop();
    } else {
      nout << "Could not load the window!\n";
    }
Afterwards, we need to close the framework:
      framework.close_framework();
      return (0);
    }
Now, compile and run your file and you have your own window opened! For the lazy ones among us, here is the full code:
    //include all the stuff
    #include "pandaFramework.h"
    #include "pandaSystem.h"

    //init the PandaFramework class
    PandaFramework framework;

    int main(int argc, char *argv[]) {
      //open the framework
      framework.open_framework(argc, argv);
      //set a nice title
      framework.set_window_title("Hello World!");
      //open it!
      WindowFramework *window = framework.open_window();

      //check whether the window is loaded correctly
      if (window != (WindowFramework *)NULL) {
        nout << "Opened the window successfully!\n";

        window->enable_keyboard(); //enable keyboard detection
        window->setup_trackball(); //enable default camera movement

        //put here your own code, such as the loading of your models

        //do the main loop
        framework.main_loop();
      } else {
        nout << "Could not load the window!\n";
      }
      //close the framework
      framework.close_framework();
      return (0);
    }
The WindowFramework class also provides all the basic things the python ShowBase /DirectStart equivalent would normally take care of:
    const NodePath &get_render();
    const NodePath &get_render_2d();
    const NodePath &get_aspect_2d();

    void set_wireframe(bool enable);
    void set_texture(bool enable);
    void set_two_sided(bool enable);
    void set_one_sided_reverse(bool enable);
    void set_lighting(bool enable);

    const NodePath &get_camera_group();

    INLINE int get_num_cameras() const;
    INLINE Camera *get_camera(int n) const;

    //WindowFramework also provides access to the GraphicsWindow.
    //for example, to set the background color to black, you can do this:
    window->get_graphics_window()->set_clear_color(Colorf(0,0,0,1));
It's very useful to study the file panda/src/framework/windowFramework.h, since you will need to use it often.
<<prev | top | next>> |