[osg-users] Get RGB Values from Texture

Tang And Miao 819721810 at qq.com
Wed Nov 8 02:37:33 PST 2017

dieslower81 wrote:
> Hi,
> I have a osg::Texture2D that I'm using as a render to texture target. 
> I can see that it is working on the screen, but I need to have access to the RGB values of the texture itself so I can also copy them to another API. 
> How can I access the RGB values?
> After rendering a frame, if I access _image in the texture2D class, it is null, but I do see that the Texture of texture2D has an array size of 1. 
> How and where are the RGB values stored?
> Or do I need to get the RGB values not from the texture but from another object that is used in the camera to texture pipeline?
> Thank you!
> Maxim

    I met this problem before(can't read RGB from texture when using render to texture.),i don't know why Until now. But i can offer you another way . It's render to image.
    Code like that:
     osg::Image* image = new osg::Image;
	image->allocateImage(new_s, new_t, 1, GL_RGBA, GL_UNSIGNED_BYTE);
    camera->attach(osg::Camera::COLOR_BUFFER, image,0, 0);
    camera->setFinalDrawCallback(new MyCameraPostDrawCallback());
     Then you can write RGB into picture.If you still can't understand my meaning.You can read this file that i upload or osg Examples(osgprerender).
     Forgiving me for my english. I am chinese. This is my first reply.Hoping to help you.
     Good Luck.

Read this topic online here:


More information about the osg-users mailing list