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

panda/src/testbed/motion.cxx

Go to the documentation of this file.
00001 // Filename: motion.cxx
00002 // Created by:  frang (23Mar99)
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 <eventHandler.h>
00020 #include <texture.h>
00021 #include <graphicsWindow.h>
00022 #include <graphicsStateGuardian.h>
00023 #include <chancfg.h>
00024 #include <notify.h>
00025 
00026 #include <string>
00027 #include "plist.h"
00028 
00029 extern GraphicsWindow* win;
00030 
00031 extern int framework_main(int argc, char *argv[]);
00032 extern void (*extra_display_func)();
00033 extern void (*define_keys)(EventHandler&);
00034 
00035 #include <GL/gl.h>
00036 typedef plist<Texture*> TexList;
00037 TexList screenshots;
00038 typedef plist<PixelBuffer*> PBList;
00039 PBList sshots;
00040 int num_frames = 4;
00041 int frame_num = 0;
00042 
00043 void motion_display_func( void ) {
00044   GraphicsStateGuardian* g = win->get_gsg();
00045   const RenderBuffer& r = g->get_render_buffer(RenderBuffer::T_front);
00046   Texture* t;
00047   PixelBuffer* p;
00048 
00049   if (frame_num < num_frames) {
00050     t = new Texture;
00051     t->_pbuffer->set_xsize(win->get_width());
00052     t->_pbuffer->set_ysize(win->get_height());
00053     p = new PixelBuffer;
00054     p->set_xsize(win->get_width());
00055     p->set_ysize(win->get_height());
00056     p->_image = PTA_uchar(win->get_width() * win->get_height() * 4);
00057   } else {
00058     TexList::iterator i = screenshots.begin();
00059     PBList::iterator l = sshots.begin();
00060     for (int j=0, k=frame_num%num_frames; j<k; ++i, ++j, ++l);
00061     t = *i;
00062     p = *l;
00063   }
00064 
00065   // g->copy_texture_from(t, r);
00066   g->copy_pixel_buffer_from(p, r);
00067 
00068   const RenderBuffer& rb = g->get_render_buffer(RenderBuffer::T_back);
00069 
00070   if (frame_num < num_frames) {
00071     // screenshots.push_back(t);
00072     sshots.push_back(p);
00073   }
00074 
00075   // now we accumulate.  Off the top of my head I have 3 plans for this:
00076   //   1) apply the screen shots to one or several whole-screen polygon(s) with
00077   //      appropriate alpha
00078   //   2) accumulate this into an accumulation buffer every frame
00079   //   3) blend the new frame into the accumulation buffer, and subtractively
00080   //      blend the old one out.
00081 
00082   // version 2.  Even this could be better if we didn't start by blowing away
00083   // the frame we just rendered.
00084   GLfloat d = 1. / GLfloat(screenshots.size() + 1.);
00085   TexList::iterator i = screenshots.begin();
00086   PBList::iterator j = sshots.begin();
00087   // for (TexList::iterator i=screenshots.begin(); i!=screenshots.end(); ++i) {
00088   for (; j!=sshots.end(); ++j) {
00089     // t = *i;
00090     // g->draw_texture_to(t, rb);
00091     p = *j;
00092     g->draw_pixel_buffer_to(p, rb);
00093     // if (i == screenshots.begin())
00094     if (j == sshots.begin())
00095       glAccum(GL_LOAD, d);
00096     else
00097       glAccum(GL_ACCUM, d);
00098   }
00099   glAccum(GL_RETURN, 1.0);
00100   g->end_frame();
00101 
00102   ++frame_num;
00103 }
00104 
00105 void event_plus(CPT_Event) {
00106   frame_num %= num_frames++;
00107   nout << "now blending " << num_frames << " frames." << endl;
00108 }
00109 
00110 void event_minus(CPT_Event) {
00111   frame_num %= --num_frames;
00112   nout << "now blending " << num_frames << " frames." << endl;
00113   // screenshots.erase(--(screenshots.end()));
00114   sshots.erase(--(sshots.end()));
00115 }
00116 
00117 void motion_keys(EventHandler& eh) {
00118   eh.add_hook("plus", event_plus);
00119   eh.add_hook("minus", event_minus);
00120 }
00121 
00122 int main(int argc, char *argv[]) {
00123   extra_display_func = &motion_display_func;
00124   define_keys = &motion_keys;
00125   return framework_main(argc, argv);
00126 }

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