开发者

On iOS with OpenGLES how to have multiple views?

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜