[osg-users] [forum] how to set raw image to texture in OSG

Harshal Chaudhari chaudhariharshal2010 at gmail.com
Mon Jun 1 22:22:00 PDT 2015


Hi,

I am trying to set an image on disk to my texture. Image dimension is 1800 by 1200 i.e. width = 1800 & height = 1200. But I am doing something wrong here due to which I am getting bad output. Can anyone help me here. This is my code -


std::ifstream imageToRead;
imageToRead.open("E:\\my code\\OpenSceneGraph-3.3.7\\OpenSceneGraph-Data-3.0.0\\Images\\1.jpg", std::ios::in | std::ios_base::binary);

imageToRead.seekg(0, std::ios::end);
int n = imageToRead.tellg();
imageToRead.seekg(0, std::ios::beg);

char* res = new char[n];

imageToRead.read(res, n);

imageToRead.clear();
imageToRead.close();

osg::Image* bufferImage = new osg::Image;
bufferImage->setImage(1800, 1200, 1, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char*)res, Image::USE_NEW_DELETE);

osg::Texture2D* texture = new osg::Texture2D(bufferImage);
texture->setResizeNonPowerOfTwoHint(false);
stateset->setTextureAttributeAndModes(0, texture);

... 


Thank you!

Cheers,
Harshal
Code:




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=63917#63917








More information about the osg-users mailing list