Panda3D
 All Classes Functions Variables Enumerations
pview.cxx
1 // Filename: pview.cxx
2 // Created by: rdb (12Jan13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pandaFramework.h"
16 #include "pandaSystem.h"
17 #include "pystub.h"
18 #include "texturePool.h"
19 #include "multitexReducer.h"
20 #include "sceneGraphReducer.h"
21 #include "partGroup.h"
22 #include "cardMaker.h"
23 #include "bamCache.h"
24 #include "virtualFileSystem.h"
25 
26 // By including checkPandaVersion.h, we guarantee that runtime
27 // attempts to run pview will fail if it inadvertently links with the
28 // wrong version of libdtool.so/.dll.
29 
30 #include "checkPandaVersion.h"
31 
32 int main(int argc, char **argv) {
33  // A call to pystub() to force libpystub.so to be linked in.
34  pystub();
35 
36  PandaFramework framework;
37  framework.open_framework(argc, argv);
38  framework.set_window_title("Panda Viewer");
39 
40  int hierarchy_match_flags = PartGroup::HMF_ok_part_extra |
41  PartGroup::HMF_ok_anim_extra;
42 
43  WindowFramework *window = framework.open_window();
44  if (window != (WindowFramework *)NULL) {
45  // We've successfully opened a window.
46 
47  NodePath loading_np;
48 
49  if (true) {
50  // Put up a "loading" message for the user's benefit.
51  NodePath aspect_2d = window->get_aspect_2d();
52  PT(TextNode) loading = new TextNode("loading");
53  loading_np = aspect_2d.attach_new_node(loading);
54  loading_np.set_scale(0.125f);
55  loading->set_text_color(1.0f, 1.0f, 1.0f, 1.0f);
56  loading->set_shadow_color(0.0f, 0.0f, 0.0f, 1.0f);
57  loading->set_shadow(0.04, 0.04);
58  loading->set_align(TextNode::A_center);
59  loading->set_text("Loading...");
60 
61  // Allow a couple of frames to go by so the window will be fully
62  // created and the text will be visible.
63  Thread *current_thread = Thread::get_current_thread();
64  framework.do_frame(current_thread);
65  framework.do_frame(current_thread);
66  }
67 
68  window->enable_keyboard();
69  window->setup_trackball();
70  framework.get_models().instance_to(window->get_render());
71  //if (argc < 2) {
72  // If we have no arguments, get that trusty old triangle out.
73  //window->load_default_model(framework.get_models());
74  //} else {
75  // window->load_models(framework.get_models(), argc, argv);
76  //}
77 
78  window->load_model(framework.get_models(), "panda-model.egg");
79  window->load_model(framework.get_models(), "panda-walk4.egg");
80 
81  window->loop_animations(hierarchy_match_flags);
82 
83  // Make sure the textures are preloaded.
84  framework.get_models().prepare_scene(window->get_graphics_output()->get_gsg());
85 
86  loading_np.remove_node();
87 
88  window->center_trackball(framework.get_models());
89  window->set_anim_controls(true);
90 
91  framework.enable_default_keys();
92  framework.main_loop();
93  framework.report_frame_rate(nout);
94  } else {
95  assert(false);
96  }
97 
98  framework.close_framework();
99  return (0);
100 }
void close_framework()
Should be called at the end of an application to close Panda.
NodePath get_aspect_2d()
Returns the node under the 2-d scene graph that is scaled to suit the window&#39;s aspect ratio...
This encapsulates the data that is normally associated with a single window, or with a single display...
WindowFramework * open_window()
Opens a window on the default graphics pipe.
void open_framework(int &argc, char **&argv)
Should be called once at the beginning of the application to initialize Panda (and the framework) for...
A thread; that is, a lightweight process.
Definition: thread.h:51
The primary interface to this module.
Definition: textNode.h:52
void set_window_title(const string &title)
Specifies the title that is set for all subsequently created windows.
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165