Thanks Ulrich, I eventually got it going, posting for reference:
Size I allocated was the issue.
Regards
Reading:
=======
unsigned char* data = new unsigned char[texSize*texSize*texSize*4];
std::ifstream fin(filename.c_str(),std::ios::in | std::ios::binary);
fin.read((char*)data ,(texSize*texSize*texSize*4));
fin.close();
osg::ref_ptr<osg::Image> image = new osg::Image;
image->setImage(texSize, texSize, texSize,4, GL_RGBA,
L_UNSIGNED_BYTE,data,osg::Image::USE_NEW_DELETE);
Writing:
=====
std::ofstream fout
("data/textures/image3d/imagedata3d_128",std::ios::app | std::ios::out |
std::ios::binary);
unsigned int size = image->getTotalSizeInBytesIncludingMipmaps();
fout.write( (char*)image->data(), size );
// Check
if ( fout.fail() )
std::cout<<"Failed to write image->data"<<std::endl;
fout.close();
On 06/24/2010 12:21 PM, Ulrich Hertlein wrote:
> Hi Paul,
>
> On 23/06/10 11:53 , Paul Pocock wrote:
>
>> I'm trying to write 3d texture data to file but when loading back into
>> osg::Image I'm getting rubbish:
>>
>> Writing to file with 3d texture data:
>>
>> unsigned int size = image->getTotalSizeInBytesIncludingMipmaps();
>> fout.write( (char*)image->data(), size );
>>
>>
>> Reading from file:
>>
>> unsigned char* data = new unsigned char[texSize*texSize*texSize*4];
>> std::ifstream fin("image3ddata2",std::ios::binary);
>>
>> fin.read((char*)&data ,(sizeof(unsigned char)* 4 * texSize * texSize *
>> texSize));
>>
>> osg::ref_ptr<osg::Image> image = new osg::Image;
>> image->setImage(texSize,texSize,texSize,4, GL_RGBA,
>> GL_UNSIGNED_BYTE,data, osg::Image::USE_NEW_DELETE);
>>
>>
>> Can anyone see anything I'm doing wrong? Either Writing or Reading?
>>
> I cannot spot anything obviously wrong with the code.
> Can you check if the file on disk is okay, so that either part (writing or
> reading) can be
> ruled out?
>
> I'd also try to set the memory to some pattern before reading, in case the
> file isn't
> fully read or something.
>
> Cheers,
> /ulrich
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
IMPORTANT: This email remains the property of the Department of Defence and is
subject to the jurisdiction of section 70 of the Crimes Act 1914. If you have
received this email in error, you are requested to contact the sender and
delete the email.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org