Quote:
Originally Posted by RoryHarvey
I'm making a simple 2d game in OpenGL ES and I want to add movement buttons to it. What's the best way of going about this? In previous projects I've simply added UIButtons to the view but I hear there are performance implications in doing so with OpenGL ES so I'm wondering what the possible alternatives are if so.
|
The simplest/cleanest way to handle this is probably to make your OpenGL view be part of the screen, in a rectangular area.
Create another view controller that manages your Cocoa controls.
Note that the new GLKViewController class added in iOS 5 insists that the view controller's entire content view be a single GLKView (OpenGL View)
You can either toss out the GLKViewController and add a GLKView to a regular view controller, or use the new child view controller facility in iOS 5 to make a GLKViewController manage your OpenGL view, and the parent view controller manage the Cocoa controls. (or make the parent view controller manage another child view controller with your controls on it. That can make for an elegant, modular design.)
For the work I've done so far, I've tossed the GLKViewController and managed a GLKView myself, but I spent a lot of time figuring out how to get a GLKView working by itself. (Mostly it was unfamiliarity with OpenGL ES 2 and it's requirement that you write a shader to do everything.)
Next time I tackle OpenGL in iOS, I will probably make the OpenGL part(s) of my screens be child view GLKViewController objects where the GLKView is the whole content of the GLKViewController, as Apple intends.
BTW, I've added a Cocoa touch button on top of a GLKView and did not notice a performance penalty. I only added a single button though, and did not use shadows, partial transparency, or any of those performance-killing options.
You might want to code it so you can put you buttons on top of your GLKview or not, depending on what you find in terms of performance. If you manage your OpenGL content using a GLKViewController, with the buttons hosted in another view controller, you can put your buttons on top of the OpenGL view or not, without having to make structural changes.
OpenGL development is all about performance testing and iterative development. You have to write something, see how it performs, and fine-tune as needed to get the performance you want/need.
Make sure you test on the oldest/slowest device you plan to support. We've decided to drop support for iOS < 5.0, so we've dropped the iPhone 3G and the equivalent iPod touch (2nd gen, I think it is.)
Requiring iOS 5 enables us to use all the cool new features like GLKit, parent/child view controllers, block-based animation, etc, etc. Big win.
The 3G has MUCH more limited graphics hardware, much less memory, and a much slower processor. It is a LOT harder to get acceptable performance from a 3G. It's also getting pretty old and out-of-date.
The 3Gs is actually a pretty decent performer, and there are apparently a lot of them out in the field. That's our base platform going forward.