Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_IMAGE_IMAGE_SCREEN_CAPTURE_H
00002 #define OPENTISSUE_GPU_IMAGE_IMAGE_SCREEN_CAPTURE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl_util.h>
00013 #include <OpenTissue/gpu/image/image.h>
00014
00015 #include <boost/shared_ptr.hpp>
00016
00017 namespace OpenTissue
00018 {
00019 namespace image
00020 {
00021
00025 struct keep_transparency {};
00026 struct no_transparency {};
00027
00034 boost::shared_ptr<OpenTissue::image::Image<unsigned char> > screen_capture( keep_transparency const & )
00035 {
00036 typedef boost::shared_ptr<OpenTissue::image::Image<unsigned char> > image_pointer;
00037
00038 GLint viewport[4];
00039 glGetIntegerv(GL_VIEWPORT,viewport);
00040 image_pointer image( new OpenTissue::image::Image<unsigned char>( viewport[2], viewport[3], 4 ) );
00041 glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGBA, GL_UNSIGNED_BYTE, image->get_data() );
00042 return image;
00043 }
00044
00054 boost::shared_ptr<OpenTissue::image::Image<unsigned char> > screen_capture( no_transparency const & )
00055 {
00056 typedef boost::shared_ptr<OpenTissue::image::Image<unsigned char> > image_pointer;
00057
00058 GLint viewport[4];
00059 glGetIntegerv(GL_VIEWPORT,viewport);
00060
00061
00062 int count = viewport[2]*viewport[3];
00063
00064 std::vector<unsigned char> pixels4(4*count);
00065 std::vector<unsigned char> pixels3(3*count);
00066
00067
00068 glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGB, GL_UNSIGNED_BYTE, (&pixels3[0]));
00069
00070
00071 for (int x = 0; x < count; x++)
00072 {
00073 pixels4[x*4] = pixels3[x*3];
00074 pixels4[x*4+1] = pixels3[x*3+1];
00075 pixels4[x*4+2] = pixels3[x*3+2];
00076 pixels4[x*4+3] = 255;
00077 }
00078
00079
00080 unsigned char * raw_ptr = static_cast< unsigned char * > (&pixels4[0]);
00081 image_pointer image(new OpenTissue::image::Image<unsigned char>(viewport[2], viewport[3], 4, raw_ptr));
00082 return image;
00083 }
00084
00091 boost::shared_ptr<OpenTissue::image::Image<unsigned char> > screen_capture( )
00092 {
00093 return screen_capture( keep_transparency() );
00094 }
00095
00096 }
00097 }
00098
00099
00100 #endif