00001 // This is core/vidl/gui/vidl_capture_tableau.cxx 00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00003 #pragma implementation 00004 #endif 00005 //: 00006 // \file 00007 // \brief Tableau for capturing OpenGL rendering to a video 00008 // \author Matt Leotta 00009 // \date 21 Nov 2008 00010 00011 #include "vidl_capture_tableau.h" 00012 #include <vil/vil_image_view.h> 00013 #include <vgui/vgui_utils.h> 00014 #include <vgui/vgui_gl.h> 00015 #include <vidl/vidl_convert.h> 00016 #include <vidl/gui/vidl_gui_param_dialog.h> 00017 00018 00019 vcl_string vidl_capture_tableau::type_name() const 00020 { 00021 return "vidl_capture_tableau"; 00022 } 00023 00024 00025 // Default constructor 00026 vidl_capture_tableau::vidl_capture_tableau( vgui_tableau_sptr const& child_tableau) 00027 : vgui_wrapper_tableau(child_tableau), 00028 ostream_(NULL) 00029 { 00030 } 00031 00032 00033 bool vidl_capture_tableau::handle( vgui_event const &e) 00034 { 00035 bool handled = false; 00036 if (child) 00037 { 00038 handled = child->handle(e); 00039 00040 if (e.type == vgui_DRAW && ostream_) 00041 { 00042 vil_image_view<vxl_byte> image = vgui_utils::colour_buffer_to_view(); 00043 vil_image_view_base_sptr img_sptr = new vil_image_view<vxl_byte>(image); 00044 ostream_->write_frame(vidl_convert_to_frame(img_sptr)); 00045 } 00046 if (e.type == vgui_RESHAPE) 00047 { 00048 GLint vp[4]; // x,y,w,h 00049 glGetIntegerv(GL_VIEWPORT, vp); 00050 vcl_cout << "window size = "<< vp[2] << ", "<<vp[3]<<vcl_endl; 00051 } 00052 } 00053 return handled; 00054 } 00055 00056 00057 //: Prompt the user to set an ostream with a gui dialog 00058 void vidl_capture_tableau::prompt_for_ostream() 00059 { 00060 ostream_ = vidl_gui_open_ostream_dialog(); 00061 } 00062 00063 00064 //: Stop the video capture and close the ostream 00065 void vidl_capture_tableau::close_ostream() 00066 { 00067 if (ostream_) 00068 { 00069 ostream_->close(); 00070 ostream_ = NULL; 00071 } 00072 } 00073 00074