iPhone OpenGLES 纹理 - 色带

发布于 2024-09-02 01:49:01 字数 487 浏览 8 评论 0原文

我在 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.

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.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽心 2024-09-09 01:49:01

iPhone 不支持 24 位颜色格式(每种颜色 8 位)。它支持(未压缩):

  • 565格式,红色= 5位,绿色= 6位,蓝色= 5位
  • 5551格式,红色= 5位,绿色= 5位,蓝色= 5位,alpha(透明度)- 1位
  • 4444格式, 4 位用于红/绿/蓝/透明度。

因此,如果您用红色绘制从 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):

  • 565 format, red = 5 bits, green = 6 bits, blue = 5 bits
  • 5551 format, red = 5 bits, green = 5 bits, blue = 5 bits, alpha (transparency) - 1 bit
  • 4444 format, 4 bits for red/green/blue/transparency.

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.

遗心遗梦遗幸福 2024-09-09 01:49:01

你应该改变Cocos2d的GLView的像素格式。以下是具体操作方法。

如果你使用Cocos2d的模板创建一个新项目,会有一个名为AppDelegate.m的文件。在该文件中找到这个方法:

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

然后在该方法中你会发现:(

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

根据你的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:

- (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)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文