I´m trying to make simple game using OpenGLES. I have two EAGLViews(menu and game view). Each view has its own viewController. Initializing of the views is done by initWithNIBName method of the viewController. And when I want to show the view, I simply use addSubview method of the main window. The game view is initialized only once at the launch time. Menu view is initialized only if it´s needed. Problem is, that when I go from game view to menu and then back, and then I redraw the game view, something goes wrong. (I'm setting EAGLContext in drawView method before drawing, so the context may be right). Don´t you know where is the problem? Or if the whole switching is managed wrong, gimme and advice please. Thanks for replies.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Why is glClear blocking in OpenGLES?
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
I guess you are having a trouble with texture not showing correctly?
I don't know the real thing behind OpenGL, but this is my hypothesis: Each time you came back to the EAGLView, The EAGLContext of EAGLView is changed. (if you have been copying and pasting from the OpenGLES template) The textures can only be loaded after the context is in its correct state, or else you cannot load any texture. Now, by leaving the EAGLView, and coming back, you are instantiating a new EAGLContext from initWithCoder:(NSCoder*)coder :
So how can we preserve this context? I make it global. Simple as that. And when EAGLView is to be instantiated once again, have it check that whether the "global" EAGLContext is nil or not. If it's nil, just instantiate it, else do nothing. And never ever release or dealloc this global EAGLContext unless you want to quit your program.
This works for me, but again, my hypothesis above may not be correct. If anybody knows the real thing, please lecture me. I am also humbly in need of guidance. I want to truly know why this occurs and why do we have to do this as well.
And by the way, does this answer your question, Jenicek?