我们可以使用什么来代替 OpenGL ES 中的混​​合?

发布于 2024-08-26 22:09:58 字数 593 浏览 6 评论 0原文

我正在使用 OpenGL 制作 iPhone 图形。在我的一个项目中,我需要使用一张图像,我需要将其用作 OpenGL 中的纹理。 .png 图像的大小为 512 * 512,其背景是透明的,图像中心有一条蓝色粗线。

当我将图像应用到 OpenGL 中的多边形时,纹理看起来就像图像中的透明部分是黑色的,而粗蓝色线看起来就像它本身一样。为了去除黑色部分,我使用了混合:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

然后去除了多边形中纹理的黑色部分。现在只能看到蓝色带。这样问题就解决了。

但我想添加许多这样的图像并在OpenGL中制作许多对象。我能够做到这一点,但是当我向对象添加越来越多的图像时,帧速率非常低。但是当我注释掉混合时,帧速率正常,但看不到图像。

由于我没有良好的 fps,因此图形有点慢并且效果不稳定。

那么:

1)除了混合之外还有其他方法可以解决我的问题吗?

2) 如何提高 OpenGL 应用程序的帧速率?为了正确实现我的图形,需要采取哪些步骤?

I am doing my iPhone graphics using OpenGL. In one of my projects, I need to use an image, which I need to use as a texture in OpenGL. The .png image is 512 * 512 in size, its background is transparent, and the image has a thick blue line in its center.

When I apply my image to a polygon in OpenGL, the texture appears as if the transparent part in the image is black and the thick blue line is seen as itself. In order to remove the black part, I used blending:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Then my black part of the texture in the polygon is removed. Now only the blue band is seen. Thus the problem is solved.

But I want to add many such images and make many objects in OpenGL. I am able to do that, but the frame rate is very low when I add more and more images to objects. But when I comment out blending, the frame rate is normal, but the images are not seen.

Since I do not have good fps, the graphics are a bit slow and I get a shaky effect.

So:

1) Is there any other method than blending to solve my problem?

2) How can I improve the frame rate of my OpenGL app? What all steps need to be taken in order to implement my graphics properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我不是你的备胎 2024-09-02 22:09:58

如果您想要对象的透明部分,唯一的方法是将三角形的像素数据与当前缓冲区中的内容(您当前正在执行的操作)混合。通常,当使用实体纹理时,三角形的新像素数据只会覆盖缓冲区中的内容(只要它更接近,即 z 缓冲区)。但是对于透明度,它开始查看纹理该部分的透明度,查看其背后的内容,一直回到实体。然后将所有重叠的透明材料层组合起来,直到获得最终图像。

如果您想要的透明度只是简单的树精灵之类的东西,并从树干侧面移除“东西”等。那么您可能最好提供更复杂的几何图形,这些几何图形实际上定义了树干的形状,从而不需要为透明度而烦恼。

遗憾的是,我认为除了减少计算的透明度之外,您没有什么可以尝试加快 FPS。甚至可能添加一些优化来检查图像以查看是否可以打开该图像的 Alpha 混合。根据您的努力程度,可能会在长期错误中节省时间。

If you want to have transparent parts of an object, the only way is to blend to pixel data for the triangle with what is currently in the buffer (what you are currently doing). Normally, when using solid textures, the new pixel data for a triangle just overwrites what ever was in buffer (as long as it is closers, ie z-buffer). But with transparency, it has start looking at the transparency of that part of the texture, look at what is behind it, all the way back to something solid. Then has combine all of those over lapping layers of transparent stuff till you get the final image.

If all you are wanting your transparency for is something like a simple tree sprite, and removing the 'stuff' form the sides of the trunk etc. Then you may be better of providing more complex geometry that actually defines the shape of the trunk and thus not need to bother with transparency.

Sadly, I don't think there is much you can do to try to speed up your FPS, other then cut down the amount of transparency you are calculating. Maybe even adding some optimization that checks images to see if it can turn of alpha blending for this image or not. Depending on how much you are trying to push through, may save time in the long wrong.

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