Hi Vincent,

what errors/issues/non-results are you seeing?  Black?  Reversed colors?  
Crashes?

On 2/02/12 21:52 , Vincent Bourdier wrote:
> I'm currently trying to convert a bitmap image file to an osg::Image.
> I get my Bitmap from the win32 api making a screenshot, but as specified in 
> the plugin bmp
> the internal format of the Bitmap is not RGB but BGR.
> 
> Is there any way to directly use the BGR data buffer in a new osg::Image or 
> do I need to
> swap from BGR to RGB ?
> I use this :
> /    _texGrad->allocateImage(width, height, 1, GL_RGB, GL_UNSIGNED_BYTE);
>     _texGrad->setImage(width, height, 1, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 
> data,
> osg::Image::USE_NEW_DELETE); /
> 
> I tried to change the GL_RGB into GL_BGR without results...
> 
> Any suggestion will be very useful.

(As I understand it you want to use the Bitmap directly as an image (not save 
it and read
it back) so I'm not sure where the plugin fits into the picture.)

First of all you don't need to do 'allocateImage' *AND* 'setImage'.  
'allocateImage'
allocates memory internally to osg::Image that can then be filled but I assume 
you already
have a buffer that it should use, so 'setImage' would be enough.

osg::Image::setImage is designed to allow the user to specify a buffer that 
osg::Image
then uses (and manages, depending on the AllocationMode).  When you're passing 
a buffer
allocated by somebody else you may want to use AllocationMode::NO_DELETE, so 
that
osg::Image does not delete/free it.

Regarding the RGB vs BGR you only want to change the 'pixelFormat' parameter, 
not the
'internalTextureFormat'.

I would naively expect that either
        _image->setImage(width, height, 1, GL_RGB,
                GL_RGB, GL_UNSIGNED_BYTE, data, osg::Image::NO_DELETE);
or
        _image->setImage(width, height, 1, GL_RGB,
                GL_BGR, GL_UNSIGNED_BYTE, data, osg::Image::NO_DELETE);
would do the trick.

Hope this helps,
Cheers,
/ulrich
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to