iPhone OpenGL color bug - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: iPhone OpenGL color bug (/thread-7975.html)
iPhone OpenGL color bug - agreendev - Aug 11, 2010 12:25 PM
Hey everyone, I'm having a bit of a color bug with openGL that I hope someone can clear up for me. The image below contains two instances of the same code, except the top is executing in the simulator while the lower image is a screenshot from my iPhone 3G running 3.1.3. I'm compiling with the 4.0 SDK. The shapes you see in the image are all textures, but for some funky reason the nongreen textures on the iPhone seem to get their colors shifted. Any ideas?
RE: iPhone OpenGL color bug - SethWillits - Aug 11, 2010 01:12 PM
Your blue and and red channels are swapped somewhere along the line. As an example, that'll happen when you have a BGRA texture and you tell OpenGL it's RGBA.
See how the B and R are swapped?
RE: iPhone OpenGL color bug - agreendev - Aug 11, 2010 02:07 PM
I have the simulator and the device both running ES1.1, and therefore they execute the exact same code. I suppose they could somehow handle the texture loading differently and the swap happens there, but that seems unlikely.
RE: iPhone OpenGL color bug - arekkusu - Aug 11, 2010 07:43 PM
It's very likely if you're using pngs.
Where you call glTexImage, examine your image data. Dump out a couple of pixels in hex and make sure they're what you think they are.
RE: iPhone OpenGL color bug - agreendev - Aug 12, 2010 06:06 AM
I am in fact using PNGs, so I'll check that out.
RE: iPhone OpenGL color bug - agreendev - Aug 12, 2010 01:09 PM
I ended up using a different method of loading pngs because I needed to be able to handle pvrs anyhow, so it's all taken care of. I do still have a weird error though, for some reason after making a few modifications to a png, it will stop working in my code (the primitive is rendered as if there is no texture there). It's as though something changes in the texture after a few saves that breaks the png loader. I'm using GIMP to make the textures.
RE: iPhone OpenGL color bug - OneSadCookie - Aug 12, 2010 02:23 PM
Xcode destroys PNGs during the build process for the iPhone by default... though that wouldn't explain why it would happen after a few builds...
RE: iPhone OpenGL color bug - agreendev - Aug 12, 2010 06:55 PM
It's not multiple builds of my app that causes it, it's multiple changes and saves made in gimp. The resolution doesn't change and the image is exported to a png with the same settings each time. Sometimes I can save what I believe to be the exact same image and it happens.
RE: iPhone OpenGL color bug - AnotherJake - Aug 12, 2010 08:20 PM
The next thing I'd do is go with arekkusu's suggestion but take it further and dump *all* the pixels to desktop just after they're loaded, as a tga or something simple, so that you can see the raw data that's being loaded. I'd want to do that to figure out if this is an image issue or whether it's a draw issue.