Hi Thomas,

On 16/12/09 3:23 AM, Thomas Canipel wrote:
> //creation of the data
> int height=100;
> int width=100;
> int length=100;
> const long size = width*height*length;

For RGB this needs to be (w*h*l)*3, ie. number-of-pixels * channels-per-pixel.

> unsigned short* data = (unsigned short*)calloc(size, sizeof(unsigned short));
> 
> for(long i=0; i < size ; i+= 3) {
>   data[i]=255;//red
>   data[i+1]=0;//green 
>   data[i+2]=0;//blue
> }

For unsigned short the maximum is 2^16-1 ie. 65535, not 255.

> // declaration and allocation of the 3d image (size : 100,100,100) 
> osg::ref_ptr<osg::Image> image = new osg::Image;
> image->allocateImage(width, height, length, GL_RGB, GL_UNSIGNED_SHORT);
> image->setOrigin(osg::Image::BOTTOM_LEFT); 
> image->setImage(width, height, length,GL_RGB,GL_RGB,GL_UNSIGNED_SHORT, 
> (unsigned char*)data,osg::Image::NO_DELETE);

I don't believe the 'allocateImage' call is necessary, 'setImage' will 
overwrite that.

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

Reply via email to