Using GLKView with a UIViewController

I wanted to use OpenGL to do simple image processing, so I started with GLKView . Since I do not need to update the view every few seconds, I did not use the GLKViewController and instead used the usual UIViewController subclass.

My question is, am I just making the viewController a view as a GLKView or adding GLKView as a subzone of the view controller's view. Since I am adding UISlider to the view, I think the latter seems better, but I'm not sure. I also need to call setNeedsDisplay in GLKView in some cases.

+2
source share
1 answer

For your rendering you really have to use GLKView inside the GLKViewController. if you are worried that you don’t need to constantly update, use self.paused = YES inside your GLKViewController, this will stop the rendering cycle, and when you need to display again, just do self.paused = NO.

If you have glkview inside another view, you should set it using containment. in your case, you should have a regular UIView with a normal UIViewController, and then add a UISlider and your GLKViewController (with GLKView) to this.

After that, you can do your normal browsing in your parent controller, and your opengl is your glk controller.

A simple example for this is to set the parent that contains the UISlider:

inside custom UIViewController for parent

 @interface ParentViewController () { ... UISlider *_slider; // this is your slider CustomGLKViewController *_myGlkViewController; } 

then inside viewDidLoad:

 // assuming you're using a storyboard UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; // setup the opengl controller // first get an instance from storyboard _myGlkViewController = [myStoryboard instantiateViewControllerWithIdentifier:@"idForGlkViewController"]; // then add the glkview as the subview of the parent view [self.view addSubview:_myGlkViewController.view]; // add the glkViewController as the child of self [self addChildViewController:_myGlkViewController]; [_myGlkViewController didMoveToParentViewController:self]; // if you want to set the glkView to the same size as the parent view, // or you can do stuff like this inside myGlkViewController _myGlkViewController.view.frame = self.view.bounds; 

but this is just a simple example that will get you started, you really need to read Apple docs regarding the UIViewController for ios5 and docs for GLKit

+7
source

Source: https://habr.com/ru/post/1484831/


All Articles