views:

199

answers:

1

This is a question about some openGLES spookiness on iPhone.

I've noticed that the color of pixels on device and the color of pixels in simulator vary slightly. For example, a green pixel might be (0,241,0) in simulator and (0,239,0) on device. This wouldn't be a big issue normally (to the naked eye they look exactly the same) but I'm using pixel data to encode some information and color matching needs to be exact.

I assume I'm overlooking some limitation of the GLES implementation... My framebuffer that receives the rendering is set up using the following commands:

// Generate an offscreen framebuffer/renderbuffer for rendering the hit detection polys // Create framebuffer glGenFramebuffersOES(1, &hitDetectionFbo); glBindFramebufferOES(GL_FRAMEBUFFER_OES, hitDetectionFbo); // Create colorbuffer glGenRenderbuffersOES(1, &colorBuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorBuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, SCREEN_WIDTH, SCREEN_HEIGHT); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBuffer); // Create depthbuffer glGenRenderbuffersOES(1, &depthBuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthBuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24_OES, SCREEN_WIDTH, SCREEN_HEIGHT); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBuffer);

NSAssert(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES, @"Framebuffer is not ready for rendering");

I'd appreciate any help or thoughts, everything works perfectly in simulator (colors match as expected) but I start losing precision on device.

Thanks, -S

+2  A: 

There's a lot of color variation between the desktop and iPhone and in fact, across different models of iPhone (the 3GS is notably brighter than the first-gen and 3G phones.)

Also, the default display gamma value for Mac OS was changed from 1.8 to 2.2 when Snow Leopard came out so your simulator colors will look different depending on what OS version you're running.

Here are some tips on adjusting original artwork to match across displays. On the iPhone you can also adjust the colorspace display gamma, white, and black values through CGColorSpaceCreateCalibratedRGB, but it's at CoreGraphics level. Not sure if it'll make a difference in GL-ES world.

If accuracy is a MUST, you may want to invest in a color calibration device and match your monitor w/ various iPhone models then skew your GL RGB values by the difference. Here's an article (in Spanish) that shows how you can color-calibrate your iPhone.

Good luck.

Ramin