Just imagine this scenario of a DrawCallBack

struct SnapImage : public osg::Camera::DrawCallback
{
    SnapImage(unsigned int format):
        _snapImage(false),_format(format)
    {
        _image = new osg::Image;     
        _image->setPacking(4);
    }

    ~SnapImage(){};
    virtual void operator () (osg::RenderInfo& renderInfo) const
    {

        if (!_snapImage) return;
    
        osg::notify(osg::NOTICE)<<"Camera callback"<<std::endl;

        osg::Camera* camera = renderInfo.getCurrentCamera();
        osg::Viewport* viewport = camera ? camera->getViewport() : 0;


        if (viewport && _image.valid())
        {
            
_image->readPixels(int(viewport->x()),int(viewport->y()),int(viewport->width()),int(viewport->height()),
                               _format,
                               GL_UNSIGNED_BYTE);
            
            osg::notify(osg::NOTICE)<<"Taken screenshot.." <<std::endl;         
    
        }
       
        _snapImage = false;
    }

    mutable bool                        _snapImage;
    mutable unsigned int                _format;
    mutable osg::ref_ptr<osg::Image>    _image;
};



This will likely crash when width is not a multiple of 4. I not calling 
setPacking() after the image has been allocated.
I wanted a packing of 4 as this matches the "packing" of BMP

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46659#46659





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to