不调用glkView drawInRect
我正在学习OpenGLES,我正在尝试将一个GLKViewer放在UIViewController中。
我知道我可以通过使用GLViewController来解决主要问题,但我正在尝试学习如何使用这种方法。
我发现这个问题,将GLKView嵌套到UIViewController和嵌套的GLKView和GLKViewController中,但是我必须缺less一些东西,即使我想我正在做所有正确的步骤,因为当我运行我的项目时,我没有进入drawInRect打印行。
在故事板中,我将ViewController作为glkview组件的代表。
我尽量保持代码尽可能简单,任何帮助都将被认可:
MyController.h
#import <Foundation/Foundation.h> #import <GLKit/GLKit.h> @interface MyGLController : UIViewController <GLKViewDelegate> { GLuint vertexBufferID; } @property (weak, nonatomic) IBOutlet GLKView *glview; @property (strong, nonatomic) GLKBaseEffect *baseEffect; @end
MyGLController.m
#import "MyGLController.h" @implementation MyGLController //@synthesize baseEffect; -(void) viewDidLoad{ [super viewDidLoad]; self.glview.context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2]; [EAGLContext setCurrentContext:self.glview.context]; printf("View Loaded"); } - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { printf("DrawInRect"); } @end
*更新*
至于我可以告诉glkview正如所build议的正确连接,并添加了josh-knapp和setNeedsDisplay。
万一有什么我缺less,我已经上传了一个项目的副本在这里: https : //github.com/jcrogel/OpenGLDebug.git
我是一个总noob在这个,所以我道歉的任何愚蠢的监督:)
你没有说你在故事板上连接了MyGLController的glview属性,所以validation一下。
接下来,您在加载后设置glview上下文。 没有一个GLKViewController,没有什么可以告诉它需要绘制的glview。 请确保在设置上下文后在某处调用[self.glview setNeedsDisplay]
。
我有一个类似的问题。
默认情况下,xcode在GLKView
属性列表中将enable setNeedsDisplay
checkbox设置为NO
。
一旦我改变它,它的工作。
我看到这个问题已经回答了。 但是我遇到了同样的问题,采用了不同的解决scheme。 我想我会在这里发布信息,其他人可能会从中受益。
问题描述
在使用GLKView和GLKViewController时,渲染循环函数(drawInRect)被调用一次,但不会再被调用。
可能的原因
CViewController的一些方法已经被错误的实现,没有调用它们的超类。 下面的代码演示了三个这样的function。 下面的例子有三个正确实现的函数,调用它们的超类。
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:NO]; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:NO]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:NO]; }