[osg-users] Strange setImage behaviour
u.hertlein at sandbox.de
Tue Mar 10 16:31:17 PDT 2009
Quoting Max <osgforum at tevs.eu>:
> I have a strange problem with osg::Image::setImage.
> I use both osg and opencv and I want to convert an opencv image into an osg.
Could you please tell us what the actual problem is?
> void updateTexture( IplImage *img, ref_ptr<Node> geode)
> ref_ptr<StateSet> state = geode->getOrCreateStateSet();
> ref_ptr<Texture2D> Tex = (Texture2D*)
> ref_ptr<Image> teximg = Tex->getImage();
> //teximg = osgDB::readImageFile("test.jpg");
> teximg->setImage(img->width, img->height,1,
> GL_UNSIGNED_BYTE, (unsigned char*) img->imageData,
> Image::NO_DELETE, 1);
> I wonder if I shouldn't put a
> teximg->allocateImage(img->width, img->height, 1,
> GL_RGB, GL_UNSIGNED_BYTE);
> because I already have an image I just update it. But with or
> without it , I have the same problem.
No you don't have to put in 'allocateImage()', the 'setImage()' call
will take ownership of the pointer you pass it.
Which also means that 'IplImage* img->imageData' has to be exist.
> When I un-comment the commented line, it works fine (but it's not my
> aim), thus the problem is in set Image, which I'm sure I didn't
Does it crash? Is teximg valid i.e. is there and image attached to
More information about the osg-users