iPhone OpenGLES 纹理 - 色带
我在 iPhone 上遇到了 openGL 问题,我确信一定有一个简单的解决方案!
当我加载纹理并显示它时,我得到了很多我认为所谓的“色带”,其中颜色,特别是渐变上的颜色,似乎会自动“优化”。
只是为了证明我自己的代码没有任何问题,我下载了 iPhone“Crashlanding”应用程序并替换了背景图像,如下图所示(取自模拟器),发生了完全相同的事情。左边是原图PNG,右边是游戏中的。就好像它的调色板被缩小到 256 色。
我确定这与我将图像保存为,虽然它不仅仅发生在 PNG 上,但似乎无论我选择哪种图像格式都会发生。
我的头进去了!如果您想重新创建此内容,只需下载崩溃着陆应用程序并替换背景即可。预先非常感谢您的帮助。
I've got a problem with openGL on iPhone which I'm sure must have a simple solution!
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. The image on the left is the original PNG, and on the right is it in the game. It's almost as if it's palette is being downsized to a 256 colour one.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iPhone 不支持 24 位颜色格式(每种颜色 8 位)。它支持(未压缩):因此,如果您用红色绘制从 0 到 255 的渐变,您将在 24 位格式中看到 256 个渐变,但在 565/5551 格式中只有 32 个渐变,甚至在 4444 中只有 16 个渐变。24 位颜色正在“在Fly”,所以看起来它受到支持,但事实并非如此。
这就是为什么会有色带。
/对于 OpenGL ES 1.0 来说是这样,还不知道 2.0 的详细信息/
更新:我的错误。 iPhone 确实支持其他格式(8888),但是,也许应用程序本身有转换?
更新2:啊,你正在使用cocos2d。并且不要在图像中使用(我假设)透明度。 Cocos2d 将此类图像转换为 565 格式。我认为如果需要的话,您必须修改 cocos2d 以“取消实现”此优化。
iPhone does not support 24bit color format (8 bits per color). It supports (uncompressed):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.
That's why there is color banding.
/That's true for OpenGL ES 1.0, don't know details about 2.0 yet/
Update: My mistake. iPhone does support other formats (8888), but, maybe, there is a conversion in the app itself?
Update 2: Ah, you are using cocos2d. And do not use (I assume) transparency in your image. Cocos2d transforms this kind of images to a 565 format. I think you'll have to modify cocos2d to "unimpliment" this optimisation, if you need.
你应该改变Cocos2d的GLView的像素格式。以下是具体操作方法。
如果你使用Cocos2d的模板创建一个新项目,会有一个名为AppDelegate.m的文件。在该文件中找到这个方法:
然后在该方法中你会发现:(
根据你的Cocos2d版本可能会有点不同。我的是2.1)
无论如何,你只需要从kEAGLColorFormatRGB565(红色,绿色,蓝色分量)更改pixelFormat每个 5、6 和 5 位)到 kEAGLColorFormatRGBA8(红色、绿色、蓝色和 alpha 分量各 8 位)。请注意,这意味着更多的内存使用(16 位与 24 位),并且可能会降低性能。
You should change the pixel format of Cocos2d's 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. Find this method inside that file:
Then inside the method you will find:
(might be a bit different depending on your version of Cocos2d. Mine is 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). Note that it means more memory usage (16 bit vs 24 bit) and possibly lower performance.