[osg-users] [forum] how to set raw image to texture in OSG
Sebastian Messerschmidt
sebastian.messerschmidt at gmx.de
Tue Jun 2 07:07:06 PDT 2015
Hi Harshal,
osgDB::readImageFile is your friend (see examples for usage)
As far as I know JPEG is compressed so, simply assigning the data will
result in displaying the raw-compressed data.
Cheers
Sebastian
> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
More information about the osg-users
mailing list