[osg-users] Strange setImage behaviour

Ulrich Hertlein u.hertlein at sandbox.de
Tue Mar 10 16:31:17 PDT 2009

Hi Max,

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*)  
> state->getTextureAttribute(0,StateAttribute::TEXTURE);
> 	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);
> 	teximg->dirty();
> 	Tex->setImage(teximg.get());
> 	state->setTextureAttribute(0,Tex.get());
> 	geode->setStateSet(state.get());
> 	return;
> }
> I wonder if I shouldn't put a
> Code:
> 	teximg->allocateImage(img->width, img->height, 1,
> because I already have an image I just update it. But with or  
> without it , I have the same problem.

(What 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  
the texture?


More information about the osg-users mailing list