iPhone OpenGL color bug

Apprentice
Posts: 18
Joined: 2010.07
Post: #1
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?
[Image: wlq048.jpg]
Quote this message in a reply
⌘-R in Chief
Posts: 1,256
Joined: 2002.05
Post: #2
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.

BGRA
RGBA

See how the B and R are swapped?
Quote this message in a reply
Apprentice
Posts: 18
Joined: 2010.07
Post: #3
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #4
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.
Quote this message in a reply
Apprentice
Posts: 18
Joined: 2010.07
Post: #5
I am in fact using PNGs, so I'll check that out.
Quote this message in a reply
Apprentice
Posts: 18
Joined: 2010.07
Post: #6
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
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...
Quote this message in a reply
Apprentice
Posts: 18
Joined: 2010.07
Post: #8
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.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #9
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Problem with the graphics color on a videogame for iphone femmedragon 6 4,679 Dec 16, 2012 07:37 PM
Last Post: SethWillits
  ? Find color value of 'pixel' in color buffer? Elphaba 1 4,461 Jul 22, 2009 01:23 PM
Last Post: Bachus
  OpenGL Color Buffer Overwrite Talyn 8 6,023 Jan 4, 2009 02:44 AM
Last Post: papillon68
  OpenGL Color map nkpkd 4 4,018 Mar 30, 2007 10:47 AM
Last Post: nkpkd
  OpenGl color map mode nkpkd 0 2,944 Mar 29, 2007 07:09 PM
Last Post: nkpkd