3

i try to set up an Xcode project based on the template "OpenGL Game". That example has a StoryBoard with one GLKViewController and one GLKView.

I'd like to have:

  • one GLKView filling half the screen
  • one GLKView filling part of the other half
  • different things drawn in the two GLKViews

The problem: - I can't seem to put two GLKViews onto a screen when using a StoryBoard - I can't get GLKViews to work when using a NIB file

I wonder if any of the two ways is possible and what would be the best way to proceed.

Even when setting up just one GLKView and GLKViewController in a NIB file it seems that neither the method update: is called nor the glkView:drawInRect: of the GLKViewController.

How can i best place two GLKViews into an iPad app onto the same screen?

EDIT: Sorry for being imprecise.

Basically what i want to do:

  • I want to write an App that uses one screen
  • in one half of the screen i want one View in which i draw OpenGL
  • in one quarter i want another View in which i draw different OpenGL
  • in the rest there should be some buttons

I use Xcode 4.2 for iOS 5.1 for iPad

First approach, use a StoryBoard:

  • i can only place one large GLKView in which i draw OpenGL, no independent other GLKView
  • the example OpenGL code in that GLKView (using the GLKViewController) works fine though.

Second approach, delete the StoryBoard and create a NIB file:

  • i can place one GLKView into a Window, a GLKViewController-subclass next to it and link it to the GtkView, but there is nothing drawn in it
  • i can place a second GLKView into the window, a different GLKViewController-subclass next to it but there isn't anything drawn in both GLKView.
  • i used the GLKView / GLKViewController example that worked fine in a StoryBoard.

Any way would be fine with me, at the moment none works.

Thanks for any hints, Torsten.

SOLVED: I use a NIB file now and i added a PRECONFIGURED combination of GLKViewController / GLKView. Just placing a UIView and a UIViewController and then changing their type does not work.

user1607261
  • 402
  • 5
  • 10
Torsten Mohr
  • 489
  • 6
  • 16
  • What sort of problems are you seeing? You can't physically place the things, the connections to them from your code don't seem to work, you can draw to each view but somehow not correctly, or something else? – Tommy Apr 02 '12 at 21:57

1 Answers1

3

I ran into this same issue recently, but with only 2 GLKViews instead of 3.

I ended up doing it all programmatically, since the storyboard method didn't seem to be robust enough for this.

What I did was create a "master" GLKViewController that would house all of my other GLKViews/GLKViewControllers.

I then add child subclassed GLKViewControllers with their subsequent views.

The tricky part that I found was that I needed to add the ViewControllers as a child as well as add their views as a child to the "master" view.

    GLKViewController master = [[GLKViewController alloc] initWithNibName:nil bundle:nil];

    GLKView *masterView = (GLKView *)master.view;
    masterView.context = context;

    master.view = masterView;

    /* I created a constructor with a parameter to identify dimensions and position for rendering  */
    GLKViewController *child1 = [[SubclassGLKViewController alloc] initWithNibName:nil bundle:nil];

    GLKView *child1View = (GLKView *)child1.view;
    child1View.context = context;

    child1.view = child1View;

    GLKViewController *child2 = [[SubclassGLKViewController alloc] initWithNibName:nil bundle:nil];

    GLKView *child2View = (GLKView *)child2.view;
    child2View.context = context;

    child2.view = child2View;    

    /*It seems all three of these steps are needed*/
    [master addChildViewController:child1];
    [child1 didMoveToParentViewController:master];

    [master.view addSubview:child1View];

Another thing I had to do was implement viewDidAppear in my GLKViewController subclass.

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    if(some condition is met)
      change frame size to something
    else 
      change frame size to something else

    self.view.frame = frame;
}

Hope this helps.

zznq
  • 400
  • 1
  • 15