简体   繁体   English

iPhone OpenGLES纹理 - 彩色条纹

[英]iPhone OpenGLES textures - colour banding

I've got a problem with openGL on iPhone which I'm sure must have a simple solution! 我在iPhone上的openGL有问题,我肯定必须有一个简单的解决方案!

When I load a texture and display it, I get a lot of what I believe is called 'Colour Banding', whereby the colours, particularly on gradients, seem to get automatically 'optimized'. 当我加载纹理并显示它时,我得到了许多我认为称为“颜色条带”的颜色,其中颜色,特别是渐变颜色,似乎会自动“优化”。

Just to demonstrate that this wasn't anything wrong with my own code, I downloaded the iPhone 'Crashlanding' app and replaced the background image, and as you can see in the image below (Taken from the simulator), the exact same thing happens. 为了证明我的代码没有任何问题,我下载了iPhone'Crashlanding'应用程序并替换了背景图像,正如您在下图中所看到的(从模拟器中获取),完全相同的事情发生。 The image on the left is the original PNG, and on the right is it in the game. 左边的图像是原始的PNG,右边的图像是游戏中的图像。 It's almost as if it's palette is being downsized to a 256 colour one. 这几乎就像它的调色板缩小到256色。

Screenshot 截图

I'm sure this is related to the format I'm saving the image as, although it doesn't just happen with PNG's, it seems to happen no matter what image format I chose. 我确定这与我保存图像的格式有关,虽然它不仅仅发生在PNG上,但无论我选择何种图像格式,它似乎都会发生。

Doing my head in! 尽我所能! If you want to recreate this, simply download the crash landing app, and replace the background. 如果要重新创建此功能,只需下载崩溃登陆应用程序,然后替换背景。 Thanks so much in advance for any help. 非常感谢您的帮助。

iPhone does not support 24bit color format (8 bits per color) . iPhone不支持24位彩色格式(每种颜色8位) It supports (uncompressed): 它支持(未压缩):

  • 565 format, red = 5 bits, green = 6 bits, blue = 5 bits 565格式,红色= 5位,绿色= 6位,蓝色= 5位
  • 5551 format, red = 5 bits, green = 5 bits, blue = 5 bits, alpha (transparency) - 1 bit 5551格式,红色= 5位,绿色= 5位,蓝色= 5位,alpha(透明度) - 1位
  • 4444 format, 4 bits for red/green/blue/transparency. 4444格式,红色/绿色/蓝色/透明度为4位。

So, if you'll draw gradient from 0 to 255 in red color, you'll see 256 gradations in 24bit format, but only 32 gradations in 565/5551 format or even 16 gradations in 4444. 24bit color is being transformed "on the fly", so it looks like it is being supported but it's not. 因此,如果您将以红色绘制0到255之间的渐变,您将看到24位格式的256个渐变,但是565/5551格式中只有32个渐变,或者4444中只有16个渐变.24位色彩正在转换为“飞“,所以它似乎得到了支持,但事实并非如此。

That's why there is color banding. 这就是为什么有色带。

/That's true for OpenGL ES 1.0, don't know details about 2.0 yet/ /这对于OpenGL ES 1.0来说是真的,不知道有关2.0的详细信息/

Update : My mistake. 更新 :我的错误。 iPhone does support other formats (8888), but, maybe, there is a conversion in the app itself? iPhone支持其他格式(8888),但也许,应用程序本身有转换?

Update 2 : Ah, you are using cocos2d. 更新2 :啊,你正在使用cocos2d。 And do not use (I assume) transparency in your image. 并且不要在图像中使用(我假设)透明度。 Cocos2d transforms this kind of images to a 565 format. Cocos2d将这种图像转换为565格式。 I think you'll have to modify cocos2d to "unimpliment" this optimisation, if you need. 如果您需要,我认为您必须将cocos2d修改为“unmpliment”此优化。

You should change the pixel format of Cocos2d's GLView. 您应该更改Cocos2d的GLView的像素格式。 Here's how to do it. 这是怎么做的。

If you use Cocos2d's template to create a new project, there's a file called AppDelegate.m. 如果您使用Cocos2d的模板来创建新项目,则会有一个名为AppDelegate.m的文件。 Find this method inside that file: 在该文件中找到此方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Then inside the method you will find: 然后在方法内你会发现:

CCGLView *glView = [CCGLView viewWithFrame:[_window bounds]
                               pixelFormat:kEAGLColorFormatRGB565
                               depthFormat:0
                        preserveBackbuffer:NO
                                sharegroup:nil
                             multiSampling:NO
                           numberOfSamples:0];

(might be a bit different depending on your version of Cocos2d. Mine is 2.1) (可能会有点不同,具体取决于您的Cocos2d版本。我的是2.1)

Anyway, you just need to change the pixelFormat from kEAGLColorFormatRGB565 (red, green, blue components each 5, 6, and 5 bits) to kEAGLColorFormatRGBA8 (red, green, blue, and alpha components 8 bits each). 无论如何,您只需要将pixelFormat从kEAGLColorFormatRGB565(红色,绿色,蓝色分量,每个5,6和5位)更改为kEAGLColorFormatRGBA8(红色,绿色,蓝色和alpha分量,每个8位)。 Note that it means more memory usage (16 bit vs 24 bit) and possibly lower performance. 请注意,这意味着更多的内存使用(16位与24位),可能性能更低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM