Bug 10668 - TexturedCube swaps red and blue when rendering the textures
Summary: TexturedCube swaps red and blue when rendering the textures
Alias: None
Product: Android
Classification: Xamarin
Component: Samples ()
Version: 4.8.x
Hardware: PC Mac OS
: Low enhancement
Target Milestone: ---
Assignee: dean.ellis
Depends on:
Reported: 2013-02-25 19:29 UTC by PJ
Modified: 2013-05-22 15:21 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description PJ 2013-02-25 19:29:55 UTC
Nobody caught this until one intrepid forum user!

"The sample app swaps Red and Blue channels on the loaded textures, which you can clearly see by comparing the textures rendered in the emulator to the files in Resources.

I narrowed it down to the following line: GL.TexImage2D (All.Texture2D, 0, (int)All.Rgba, w, h, 0, All.Rgba, All.UnsignedByte, pixels);

I tried fixing it by changing All.Rgba to All.GbraExt but it didn't help and the loaded texture appeared all white. I finally managed to fix it by replacing the line with GLUtils.TexImage2D((int)All.Texture2D, 0, bitmap, 0); but I don't want to use the GLUtils class.

Is there a way to fix it without changing the original code much?"

When investigating... by golly he's right! The texture is actually blue and the rendered texture is red. You can see that this has slipped by for a long time. The screenshots taken that show the expected behavior are clearly red.

Example screenshot: https://github.com/xamarin/monodroid-samples/blob/master/TexturedCube/Screenshots/TexturedCube2.png
Example texture: https://github.com/xamarin/monodroid-samples/blob/master/TexturedCube/Resources/drawable-nodpi/f_spot.png
Comment 1 Miguel de Icaza [MSFT] 2013-05-22 14:27:23 UTC
PJ, question: is this a bug in the code/sample, or a bug in our libraries that are causing this?

It was not clear from your research.
Comment 2 PJ 2013-05-22 14:56:01 UTC
This may need some eyes from Dean or Dominique. As far as I can tell, we could get the right colors if we could set All.Bgra instead of of All.Rgba.

That being said, oftentimes you need BGR for .bmp files and RGB for .png files, so I'm not sure why the channels are flipped for this png.  

All applicable values for TexImage2d's internalformat and format seem to result in either the existing behavior or a white/grey cube.
Comment 3 dean.ellis 2013-05-22 15:01:56 UTC
This is a bug in the sample. Its not using the android util method


 to create the texture. This method sorts out the RGBA/BGRA stuff automatically. The sample just needs updating.
Comment 4 PJ 2013-05-22 15:21:17 UTC
Oh ok, if that's the proper way to do it that works. Figured we wanted to get the Gl.TexImage2d call working correctly.

Fixed in monodroid-samples/master 522849f