Jump to content

Pixel format from Image::getPixels2D not as expected


photo

Recommended Posts

We are trying to use the Unigine engine to render several viewpoints, and then blt them to (different locations) in a Windows window (HWND). We will do this for even 16 different renders per update cycle.

Following along the lines of that found within the Viewport example, the code looks roughly like (for demonstration):

 

Unigine::ImagePtr src = Unigine::Image::create();
Unigine::Variable src_image(Unigine::TypeInfo(Unigine::TypeID<Unigine::Image *>()), src.get());
Unigine::Variable width(200);
Unigine::Variable height(200);
g_engine->runWorld("engine.render.renderImage2D", projection, modelview, src_image, width, height, material, hdr);

if(src->isLoaded())
{
   unsigned char *pixels = src->getPixels2D();

   Gdiplus::Bitmap b(200, 200, 4 * 200, PixelFormat32bppARGB, pixels);
   g.DrawImage(&b, 50, 250, 200, 200);
}

 

It was expected that the pixels would come back as 0xFFRRGGBB, which is the format that Windows expects, the format that QImage expects (which the example uses), and that expected by far the majority of DirectX formats. However, the pixels actually come back in the format 0xFFBBGGRR. This results in our sky looking red!

 

This same problem applies even if we use:

 

src->convertToFormat(Unigine::Image::FORMAT_RGB8);

 

and

 

Gdiplus::Bitmap b(300, 300, 3 * 300, PixelFormat24bppRGB, pixels);

 

... which is what the sample code uses, so I don't really see how the sample can work properly.

 

So, is it possible that there is a setting that we can change that will return this in our desired format? Or does anybody know a way to use this data without going through and doing painful byte-swapping between the red and blue components on all pixels? (This isn't hard to do, just inefficient.)

 

More particularly, is this intended? Or a function of the graphics card/DirectX?

 

Thanks,

Luke

Link to comment
×
×
  • Create New...