如何在 UIView 和 EAGLView 之间进行混合?

发布于 2024-08-04 11:38:37 字数 287 浏览 5 评论 0原文

我在 EAGLView 层上渲染了一个 opengl 场景,在 UIView 上渲染了一些其他元素(圆圈等)(它是 EAGLView 的同级,位于其上方)。是否可以在两层之间混合颜色?我想做一些差异混合以获得 EAGLView 颜色的反转效果。

我一直在尝试 CGBlendMode,但它似乎只影响我在当前视图中绘制的内容。我认为这与 CGContext 有关,但我对细节有点模糊,我可以强制 UIView 和 EAGLView 具有相同的 CGContext 以便在它们之间进行混合吗?

感谢帮助、更正、澄清。提前致谢, -S

I have an opengl scene rendering on an EAGLView layer and some other elements (circles and such) rendering on a UIView (which is a sibling of the EAGLView, positioned above it). Is it possible to blend colors between the two layers? I'd like to do some difference blending to get an inversion effect on the colors from EAGLView.

I've been playing around with CGBlendMode but it only seems to affect what I'm drawing in that current view. I think this has something to do with the CGContext but I'm a little hazy on the details, can I force the UIView and the EAGLView to have the same CGContext so that the blending works between them?

Help, corrections, clarifications are all appreciated. Thanks in advance,
-S

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

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

发布评论

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

评论(2

2024-08-11 11:38:37

简短的回答是你不能。长答案如下。

EAGLView 指的是 Xcode 中 OpenGL ES 模板中包含的 UIView 子类。该类的特殊之处在于,layerClass 类方法被重写并返回 CAEAGLLayer 类,而不是默认的 CALayer 类。

UIViewCALayer 成对工作。所有 UIView 对象都由 CALayer 支持,CALayer 是负责布局和渲染到屏幕的对象。 UIViewCALayer 的委托,负责在需要时绘制其图形。

CALayer 将让它的委托(UIView)绘制到 CGContextRef 中。每个 UIView 都有一个上下文,因此您不能使用 CGBlendMode 来混合多个视图,因为它只能在一个 UIView 上下文中运行。

CALayer 的混合应该使用过滤器属性来完成。这些是为 iPhone 操作系统定义的,但根据文档,可用的过滤器未定义。这是因为 Core Image 目前在 iPhone 操作系统上不可用。

Short answer is you can not. Long answer follows.

By EAGLView you must mean the subclass of UIView that is included in the OpenGL ES Template in Xcode. What makes this class special is that the layerClass class method is overridden and return the CAEAGLLayer class instead of the CALayer class, as is default.

UIView and CALayer work in pairs. All UIView objects are backed by a CALayer, the CALayer is the object responsible for layout and rendering to screen. The UIView is a delegate to the CALayer, and is responsible for drawing it's graphics when needed.

CALayer will let it's delegate (the UIView) draw into a CGContextRef. It is one context per UIView, so you can not use CGBlendMode to blend several views since it will only function within one single UIView context.

Blending of CALayer should be done using the filter properties. These are defined for iPhone OS but the available filters are undefined according to the documentation. This is because Core Image is not available on iPhone OS at this time.

好久不见√ 2024-08-11 11:38:37

我不认为你能够在这个意义上混合颜色。你能做的最好的事情就是让一个完全遮挡另一个,或者让顶层半透明(在这种情况下,你会看到下面的部分) - 但你将无法进行 XOR 类型绘图。

I don't think you'll be able to blend colours in that sense. The best you can do is have one completely obscuring the other, or have the top layer semi-transparent (in which case, you'll see the part underneath) - but you won't be able to do XOR type drawing.

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