[osg-users] Strange setImage behaviour
Max
osgforum at tevs.eu
Tue Mar 10 10:06:36 PDT 2009
Hi,
First, I'm sorry to disturb all of you with such a dumb question.
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.
It's in order to update a texture, here's my code:
Code:
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_TEXTURE_2D,GL_RGB,
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,
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.
The strange thing is it worked well yesterday, and I don't know why it doesn't anymore today, and as I work alone, I don't use any svn to get back an older version...
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 modify.
I really don't see where it comes from!
Thanks for reading me (and more if you reply).
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=8166#8166
More information about the osg-users
mailing list