This problem has been around for a while, although before i wondered if i was doing something wrong.
The problem is that the bytes of an ARGB image are mixed up when using images of OpenGLImageType on Android. Under Windows it’s fine and i havent yet tested iOS. This could be an endian problem. Note also, that if i change the code to use “normal”, ie non-opengl, image types, everything works.
in order to avoid copying my images all the time to opengl, im creating Image's using the
OpenGLImageType’ for my “hud”.
like this:
Then i draw to them and later i draw them using the paint' method of a component with an attached OpenGLContext. I create the image in
newOpenGLContextCreated’.
What happens is that, i think, red and blue are swapped. If i add in this nasty hack it fixes it,
void GLPanel::_fixPixelFormatARGB(Image& img)
{
Image::BitmapData* _data = new Image::BitmapData(img, Image::BitmapData::readOnly);
int i, j;
int n = _data->lineStride/4;
unsigned char* dp = _data->data;
for (i = 0; i < _data->height; ++i)
{
// ABCD -> CBAD
for (j = 0; j < n; ++j)
{
unsigned char v = dp[0];
dp[0] = dp[2];
dp[2] = v;
dp += 4;
}
}
delete _data;
}
You’ll notice im hacking the “readonly” bytes which is very naughty! Also, you’ll notice that this hack can’t work because you can’t do this to an OpenGLImageType. In fact, what i have to do is create a temp “normal” image, run my hack above, then copy it to the OpenGLImageType.
Like this, it works and i only need to do this hack in the initial image creation, but it’s annoying.
I’ve just updated to the latest code and it’s still there.
any suggestions welcome,
– hugh.