用于 iPhone 混合的 OpenGL ES 不起作用

发布于 2024-09-28 03:14:16 字数 520 浏览 6 评论 0原文

一般来说,我是 3D 图形的初学者,我正在尝试为 iPhone 制作 3D 游戏,更具体地说,是使用包含透明度的纹理。我能够将纹理(8 位 .png 文件)加载到 OpenGL 中并将其映射到正方形(由三角形条带制成),但是当我在模拟器中运行应用程序时,图像的透明部分不透明 - 它们呈现背景颜色,无论其设置为何,但远处的图像会变得模糊。由于我是新用户,因此无法发布屏幕截图,因此对此表示歉意。我会尝试以其他方式上传并链接它。

更烦人的是,当我将图像加载到 Apple 的 GLSprite 示例代码中时,它完全按照我想要的方式工作。我已将 GLSprite 的 setupView 中的代码复制到我的项目中,但它仍然无法正常工作。

我正在使用混合功能:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

我的印象是这对于我想做的事情是正确的。

我在这里缺少一些非常基本的东西吗?任何帮助将不胜感激,因为我将在几周内将其作为课程作业项目提交,并且非常希望它能够发挥作用。

I'm a beginner to 3D graphics in general and I'm trying to make a 3D game for the iPhone, and more specifically, to use textures that contain transparency. I am able to load a texture (an 8 bit .png file) into OpenGL and map it to a square (made from a triangle strip) but the transparent parts of the image are not transparent when I run the app in the simulator - they take on the background colour, whatever it is set to, but obscure images that are further away. I am unable to post a screenshot as I am a new user, so my apologies for that. I will try to upload and link it some other way.

Even more annoying is that when I load the image into Apple's GLSprite example code, it works exactly as I want it to. I have copied the code from GLSprite's setupView into my project and it still doesn't work properly.

I am using the blend function:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

I was under the impression that this is correct for what I want to do.

Is there something very basic I am missing here? Any help would be much appreciated as I am submitting this as a coursework project in a few weeks and would very much like it to work.

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

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

发布评论

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

评论(1

梦中楼上月下 2024-10-05 03:14:16

让我分解一下:

首先绘制透明对象。

此时会发生两件事:

  • 像素被正确绘制到后台缓冲区
  • 深度缓冲区像素被设置在深度缓冲区中。请注意,深度缓冲区将在整个对象上写入值,并且透明度不会影响它。

然后在透明对象后面绘制其他对象。
但是这些对象像素中的任何一个都不会被绘制,因为它们的深度缓冲区值小于已经绘制的像素。

此问题的解决方案是从后到前绘制场景(从更远的东西)。

希望有帮助。

编辑:我假设您在这里使用深度缓冲区。如果这不正确,我会考虑写另一个答案。

Let me break this down:

First of all your transparent object is drawn.

At this point two things happen:

  • The pixels are drawn correctly to the back buffer
  • The depth buffer pixels are set in the depth buffer. Note that the depth buffer will write values all across your object, and transparency does not affect it.

You then draw other objects behind the transparent object.
But any of these objects pixels will not be drawn, because their depth buffer value are less than those already drawn.

The solution to this problem is to draw your scene back-to-front (draw starting at the further away things).

Hope that helps.

Edit: I'm assuming you are using the depth buffer here. If this isn't correct I'll consider writing another answer.

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