I am trying to add a GLKViewController to my UserInterfaceViewController. I am using a sample project from the Raywenderlich tutorials ( http://www.raywenderlich.com/5235/beginning-opengl-es-2-0-with-glkit-part-2 )
Here is my code snippet
The above code draws the context in my UserInterfaceViewController view in the specified frame, which I expect. HelloGLKitViewController has code to rotate the cube in the GLKViewControllerDelegate "update" method, as follows. but GLKViewControllerDelegate is not called when the HelloGLKitViewController view is my ViewInterfaceViewController.
#import <GLKit/GLKit.h> @interface HelloGLKitViewController : GLKViewController @end @implementation HelloGLKitViewController #pragma mark - GLKViewDelegate - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { //glClearColor(_curRed, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); [self.effect prepareToDraw]; glBindVertexArrayOES(_vertexArray); glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0); } #pragma mark - GLKViewControllerDelegate - (void)update { if (_increasing) { _curRed += 1.0 * self.timeSinceLastUpdate; } else { _curRed -= 1.0 * self.timeSinceLastUpdate; } if (_curRed >= 1.0) { _curRed = 1.0; _increasing = NO; } if (_curRed <= 0.0) { _curRed = 0.0; _increasing = YES; } float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height); GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 4.0f, 10.0f); self.effect.transform.projectionMatrix = projectionMatrix; GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -6.0f); _rotation += -90 * self.timeSinceLastUpdate;//90 clockwise -90 anticlickwise modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(0), 1, 0, 0);//GLKMathDegreesToRadians(25) for bending Cube modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(_rotation), 0, 1, 0); // modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, self.view.frame.origin.x, self.view.frame.origin.y,0); // modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, -self.view.bounds.size.width/2, -self.view.bounds.size.height/2,0); self.effect.transform.modelviewMatrix = modelViewMatrix; } @end
What should I do to call the GLKViewControllerDelegate update method.
Akbar source share