Hi Andrew, Thanks for the callback code. Having a look at how this uses osg::Image and how readPixels() calls allocateImage() it looks to me the problems stems from the the later call not passing in the _packing value so this defaults to 0. Your suggested fix of passing in the _packing value to allocateImage() addresses this.
Looking at the API of the allocateImage() and readPixels() I can't help but feel that readPixels() should match allocateImage() in having the packing passed in as well, so avoid the need for you to call setPacking(4). I have made this change and checked it into svn/trunk. This will leave the original default behaviour in place but allow users like yourself to set a specific packing value. Robert. On 29 March 2012 01:20, Andrew Cunningham <[email protected]> wrote: > 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 > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

