在带有 OpenGLES 的 iOS 上如何拥有多个视图?

发布于 2024-09-14 04:29:29 字数 345 浏览 7 评论 0原文

在 iOS 上,如果我想叠加两个视图,然后从一个场景混合到另一个场景。

例如:从游戏菜单到实际游戏。首先有菜单,然后单击(“开始游戏”)加载游戏视图,并从菜单到游戏阶段进行良好的混合/转换。

这不是混合的具体问题,而是关于如何在 OpenGL 应用程序中处理多个视图的问题。我已经阅读并学习了一些关于如何绘制线条、对象、闪电、颜色和类似内容的基础知识,但当谈到将它们放在一个真实的(不仅仅是一个静态视图)OpenGLES 应用程序中时,我完全不知道。我的意思是你必须使用不同的观点,对吗?或者我们在日常 UIKit 编程中习惯的这种具有不同视图控制器和视图的设计模式在 OpenGLES 中不适用?因为我就是无法让它发生。而且我找不到任何例子。

On iOS if I want to overlay two views and then blend from one scene to another.

E.g.: From menu of a game to the actual game. Have menu first, then on click ("start game") load game view and have a nice blend/transform from the menu to the game stage.

This is not a specific question for blending but on how to handle multiple views in an OpenGL application. I have read and played with some basics on how to draw lines, objects, lightning, colors and similar but I'm completely green when it comes to putting it all together in a real (not just one static view) OpenGLES Application. I mean you have to use different views, right ? Or is this design pattern with different viewcontrollers and views that we all got used to in our everyday UIKit programming not applicable when it comes to OpenGLES ? Cause I just can't make it happen. And I can't find any examples.

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

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

发布评论

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

评论(2

怪我鬧 2024-09-21 04:29:29

好吧,我在 cocos2d for iphone 中找到了我想要的东西,

它为您提供了图层、场景转换、随时可用的菜单、精灵等。
所以我不再担心如何做到这一点,现在只使用 cocos。

如果您也是 OpenGL 新手,请不要犹豫,它将使您的生活轻松 147 倍。顺便说一句...您还可以将其与 3d 结合起来。

Well I found what I was looking for in cocos2d for iphone

It gives you layers, scene transitions, ready to go menus, sprites, etc..
So I stopped bothering on how to do that and just use cocos now.

Don't hesitate if you are new to OpenGL as well, it will make your life 147* times easier. And btw... you can also combine it with 3d.

最偏执的依靠 2024-09-21 04:29:29

如果您想在应用程序中以 CAEAGLLayers 的形式拥有多个同时可见的 OpenGL 视图,那么需要记住一点:

[EAGLContext setCurrentContext:oglContext]

将更改上下文,而不仅仅是为了当前正在执行的视图,但适用于应用程序的所有 EAGL 视图。这可以通过使正在工作的其他视图冻结来体现,因为 OpenGL 调用现在将转到执行 [EAGLContext setCurrentContext:oglContext] 的最后一个视图。

为了解决这个问题,您必须在每次调用视图实例时调用[EAGLContext setCurrentContext:oglContext],然后再进行任何 OpenGL 调用。

在我的应用程序中,我仅在视图的 initWithFrame 中设置上下文一次。这多年来一直运作良好。一旦我创建了该视图的第二个实例,第一个视图就停止更新。现在,我在进行任何 CVOpenGLES 调用之前,在更新调用中设置上下文。

If you want to have multiple simultaneously visible OpenGL views in your app, in the form of CAEAGLLayers, then there is an important point to remember:

[EAGLContext setCurrentContext:oglContext]

will change the context, not just for the view that is currently being executed, but for all the EAGL views of your app. This can manifest itself by making other views that were working to freeze, as the OpenGL calls are now going to the last view that did the [EAGLContext setCurrentContext:oglContext].

To get around this, you have to call [EAGLContext setCurrentContext:oglContext] every time your view instance gets called, before making any OpenGL calls.

In my app, I only set the context once, in the view's initWithFrame. This worked fine for years. Once I created a second instance of that view, the first view stopped updating. Now I set the context in my update calls, before I make any CVOpenGLES calls.

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