00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
00072 sshots.push_back(p);
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 GLfloat d = 1. / GLfloat(screenshots.size() + 1.);
00085 TexList::iterator i = screenshots.begin();
00086 PBList::iterator j = sshots.begin();
00087
00088 for (; j!=sshots.end(); ++j) {
00089
00090
00091 p = *j;
00092 g->draw_pixel_buffer_to(p, rb);
00093
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
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 }