Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/testbed/open_window.cxx

Go to the documentation of this file.
00001 // Filename: dxwindow.cxx
00002 // Created by:  drose (09Jan02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "graphicsWindow.h"
00020 #include "graphicsChannel.h"
00021 #include "graphicsLayer.h"
00022 #include "displayRegion.h"
00023 #include "camera.h"
00024 #include "perspectiveLens.h"
00025 #include "namedNode.h"
00026 #include "renderRelation.h"
00027 #include "transformTransition.h"
00028 #include "loader.h"
00029 #include "clockObject.h"
00030 
00031 #ifdef USE_GLX
00032   #include "glxGraphicsPipe.h"
00033 #else
00034   #include "wglGraphicsPipe.h"
00035   #include "wdxGraphicsPipe.h"
00036   #include "wcrGraphicsPipe.h"
00037 #endif
00038 
00039 
00040 // This program demonstrates creating a graphics window in Panda
00041 // explicitly, without using ChanCfg as an interface wrapper.
00042 // Normally we use ChanCfg to create the window and automatically set
00043 // up many of its parameters.
00044 
00045 void
00046 get_models(Node *root, int argc, char *argv[]) {
00047   Loader loader;
00048 
00049   for (int i = 1; i < argc; i++) {
00050     Filename filename = argv[i];
00051 
00052     cerr << "Loading " << filename << "\n";
00053     PT_Node node = loader.load_sync(filename);
00054     if (node == (Node *)NULL) {
00055       cerr << "Unable to load " << filename << "\n";
00056     } else {
00057       new RenderRelation(root, node);
00058     }
00059   }
00060 }
00061 
00062 
00063 int
00064 main(int argc, char *argv[]) {
00065   // First, create a GraphicsPipe.  For this we need a PipeSpecifier
00066   // to specify the parameters we want to pass to the pipe.  Yeah, I
00067   // know it's a weird way to pass parameters to an object.
00068 
00069   PipeSpecifier pipe_spec;
00070   PT(GraphicsPipe) pipe;
00071 
00072 #ifdef USE_GLX
00073   pipe = new glxGraphicsPipe(pipe_spec);
00074 #else
00075   // Yes, this is a stupid hard coded switch, but this is a test app, and
00076   // I'm just making it easier to see the choices (and switch between them).
00077   switch (2) {
00078     case 1:
00079       // ...OpenGL pipe
00080       pipe = new wglGraphicsPipe(pipe_spec);
00081       break;
00082     case 2:
00083       // ...Chromium OpenGL pipe (cr == chromium)
00084       pipe = new wcrGraphicsPipe(pipe_spec);
00085       break;
00086     default:
00087       // ...DirectX pipe
00088       pipe = new wdxGraphicsPipe(pipe_spec);
00089       break;
00090   }
00091 #endif
00092 
00093   // Now create a window on that pipe.
00094   GraphicsWindow::Properties window_prop;
00095   window_prop._xorg = 0;
00096   window_prop._yorg = 0;
00097   window_prop._xsize = 640;
00098   window_prop._ysize = 480;
00099   window_prop._title = "Window";
00100   //  window_prop._fullscreen = true;
00101 
00102   PT(GraphicsWindow) window = pipe->make_window(window_prop);
00103 
00104   // Get the first channel on the window.  This will be the only
00105   // channel on non-SGI hardware.
00106   PT(GraphicsChannel) channel = window->get_channel(0);
00107 
00108   // Make a layer on the channel to hold our display region.
00109   PT(GraphicsLayer) layer = channel->make_layer();
00110 
00111   // And create a display region that covers the entire window.
00112   PT(DisplayRegion) dr = layer->make_display_region();
00113 
00114   // Finally, we need a camera to associate with the display region.
00115   PT(Camera) camera = new Camera;
00116   PT(Lens) lens = new PerspectiveLens;
00117   lens->set_film_size(640, 480);
00118   camera->set_lens(lens);
00119   dr->set_camera(camera);
00120 
00121   // Window setup is complete.  Now we just need to make a scene graph
00122   // for the camera to render.
00123   PT_Node render_top = new NamedNode("render_top");
00124   camera->set_scene(render_top);
00125 
00126   PT_Node render = new NamedNode("render");
00127   NodeRelation *render_arc = new RenderRelation(render_top, render);
00128 
00129   // Put something in the scene graph to look at.
00130   get_models(render, argc, argv);
00131 
00132   // Put the scene a distance in front of our face so we can see it.
00133   LMatrix4f mat = LMatrix4f::translate_mat(0, 20, 0);
00134   TransformTransition *tt = new TransformTransition(mat);
00135   render_arc->set_transition(tt);
00136 
00137 
00138   // This is our main update loop.  Run for 5 seconds, then shut down.
00139   ClockObject *clock = ClockObject::get_global_clock();
00140   clock->tick();
00141   double now = clock->get_frame_time();
00142   while (clock->get_frame_time() - now < 5.0) {
00143     clock->tick();
00144     window->get_gsg()->render_frame();
00145     window->update();
00146   } 
00147 
00148   cerr << "Exiting.\n";
00149   return (0);
00150 }

Generated on Fri May 2 00:44:09 2003 for Panda by doxygen1.3