[osg-users] get a Texel from an osg::Image

David Spilling david.spilling at gmail.com
Fri Jul 11 05:49:20 PDT 2008


Ming,

So long as you know that the image format is GL_RGBA8, and 2D, you can do
something like:

osg::Vec4 returnColour(int row, int col)
{
        unsigned char*  pSrc  = (unsigned char*)  image->data(row,col);
        float r = (float) *pSrc++/255.0f;
        float g = (float) *pSrc++/255.0f;
        float b = (float) *pSrc++/255.0f;
        float a = (float) *pSrc++/255.0f;
        return osg::Vec4(r,g,b,a);
}

If you are not in control of the image's format then you should check
whether it is RGB or RGBA before trying to get alpha, and also whether it is
RGBA8 and not (for example) RGBA16F, or RGBA32F, or something slighly more
esoteric.

Hope that helps,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080711/a4f110a2/attachment-0003.htm>


More information about the osg-users mailing list