MonoTouch.GLKit.GLKViewController Class

See Also: GLKViewController Members

Syntax

[MonoTouch.Foundation.Register("GLKViewController", true)]
[MonoTouch.ObjCRuntime.Availability(Introduced=MonoTouch.ObjCRuntime.Platform.iOS_5_0)]
public class GLKViewController : MonoTouch.UIKit.UIViewController

Remarks

UIViewController specifically designed to host OpenGL content, in particular animated content rendered on a GLKView. It automatically sets up a CADisplayLink to synchornize the updates with the screen refresh.

This view controller drives the animation of the main thread of your application. You should configure the View property (which is guaranteed to be of type GLKView) appropriately to draw its contents and you should override the Update methods to keep track of time (it will be called just before the frame is displayed).

You should determine appropriate frame rate for your application and set the PreferredFramesPerSecond property.

The view controller can automatically stop animation when the view is obscured. See the PauseOnWillResignActive and Pause properties.

Since iOS 4.0, rotation is handled by the UIViewController. In addition to overriding the methods that control the orientation capabilities of your application, you should reallocate your framebuffer objects on the LayoutSubviews method.

c# Example

public override LayoutSubviews ()
{
    DeleteFramebuffer ();
    CreateFramebuffer ();
}
  

As with other C# bindings, you can choose to either subclass the GLKViewControllerDelegate class and assign it to the Delegate property, or you can use the mapped C# style events.

The following shows how to create your subclass of GLKViewController and do the basic setup. You should allocate your GL resources in the ViewDidLoad method and release them in ViewDidUnload.

c# Example

public class RippleViewController : GLKViewController {
                     
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

	// create rendering context
        context = new EAGLContext (EAGLRenderingAPI.OpenGLES2);

	// Get the nested GLKView and configure it.
        glkView = (GLKView) View;
        glkView.Context = context;
        glkView.MultipleTouchEnabled = true;

	// Hook up the rendering method.
        glkView.DrawInRect += Draw;
        
	// Configure the GLKViewController properties
        PreferredFramesPerSecond = 60;

	// Your own setup
        SetupGL ();
    }
                
    void Draw (object sender, GLKViewDrawEventArgs args)
    {
        GL.Clear ((int)All.ColorBufferBit);
	// More GL code here.
    }

    // Called before each frame is displayed, use to collect
    // information to compute data for the next frame to be
    // rendered.
    public override void Update ()
    {

    }

}

Related content

Requirements

Namespace: MonoTouch.GLKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0