Re: [osg-users] How to create osg::Texture2D from osg::Vec3Array...?

111 views
Skip to first unread message

Filip Arlet

unread,
Jun 28, 2012, 7:49:54 AM6/28/12
to osg-...@lists.openscenegraph.org
Hi,

simplest technique is creating osg::Image, then assigning it to texture like this:

Code:

osg::Image* image = new osg::Image;
image->allocateImage(16, 1, 1, GL_RGBA, GL_FLOAT);
image->setInternalTextureFormat(GL_RGBA);

osg::Vec4* dataPtr = reinterpret_cast<osg::Vec4*>(image->data());
memcpy(); // copy your array Vec4Array

osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);




Cheers,
Filip

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





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

Kedar Kumbhar

unread,
Jun 28, 2012, 5:10:40 AM6/28/12
to osg-...@lists.openscenegraph.org
Hi,

The normal method given in many examples to create a Texture2D, is using a Image file.


Code:
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
osg::ref_ptr<osg::Image> image = osgDB::readImageFile("Images/lz.rgb" );
texture->setImage( image.get() );



Instead, I have a osg::Vect4Array in which I have color information (rgba).

How can I use this Vec4Array to create Texture2D?


Thank you!

Cheers,
Kedar

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

Ulrich Hertlein

unread,
Jun 30, 2012, 2:13:14 AM6/30/12
to osg-...@lists.openscenegraph.org
Hi Kedar,

On 28/06/12 19:10 , Kedar Kumbhar wrote:
> The normal method given in many examples to create a Texture2D, is using a Image file.
>
> Code:
> osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
> osg::ref_ptr<osg::Image> image = osgDB::readImageFile("Images/lz.rgb" );
> texture->setImage( image.get() );
>
> Instead, I have a osg::Vect4Array in which I have color information (rgba).
>
> How can I use this Vec4Array to create Texture2D?

Vec4Array is-a std::vector and contains a contiguous block of its base type, such as
float. I haven't tested this, but you should be able to just call:

osg::Image::setImage(
width, height, 1,
GL_RGBA8,
GL_RGBA, GL_FLOAT,
(unsigned char*) &vec4Array[0], NO_DELETE);

Hope this helps,
Cheers,
/ulrich

Kedar Kumbhar

unread,
Jul 6, 2012, 4:34:15 AM7/6/12
to osg-...@lists.openscenegraph.org
Hi Ulrich & Hroach,

I tried with your sample code and it is solution for my question.

@ Hroach - Only thing to be added in your code is, after memcpy(), dataptr needs to be assigned to image->setImage().


Code:

image1->setImage( 2,2, 1, GL_RGBA8, GL_RGBA, GL_FLOAT, (unsigned char *)dataptr, osg::Image::AllocationMode::NO_DELETE );




...

Thank you!

Cheers,
Kedar

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48727#48727
Reply all
Reply to author
Forward
0 new messages