我正在学习OpenGLES,我正在尝试在UIViewController中放置一个GLKViewer。
我知道我可以通过使用GLViewController来解决主要问题,但我正在努力学习如何这样做。
我找到了这个问题,Nesting GLKView into UIViewController和Nested GLKView and GLKViewController,但是我肯定遗漏了一些东西,尽管我认为我正在做所有正确的步骤,因为当我运行我的项目时,我没有到达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;
@endMyGLController.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已按建议正确地连接起来,并添加了乔希-克纳普并命名为setNeedsDisplay。
如果我遗漏了什么,我在这里上传了一个项目的副本:https://github.com/jcrogel/OpenGLDebug.git
我在这件事上完全是个菜鸟,所以我为任何愚蠢的疏忽道歉:)
发布于 2012-11-12 16:56:48
您没有说您在故事板中连接了MyGLController的glview属性,所以请验证这一点。
接下来,您将在glview上下文加载之后设置它。如果没有GLKViewController,就没有什么能说明它需要绘制。确保在设置了上下文之后在某个地方调用了[self.glview setNeedsDisplay]。
发布于 2014-01-09 09:32:43
我也有过类似的问题。
默认情况下,xcode在enable setNeedsDisplay属性列表中将NO复选框设置为NO。
一旦我改变了它,它就成功了。
发布于 2013-01-07 07:10:51
我看这个问题已经回答了。但我也有同样的问题,有不同的解决方案。我想,我会在这里张贴的信息,在偶然的机会,其他人可能会从中受益。
问题描述
在使用GLKView和GLKViewController时,呈现循环函数(drawInRect)只被调用一次,而不是再次调用。
可能引起
CViewController的一些方法实现得不正确,没有调用它们的超级程序。下面的代码说明了三个这样的函数。下面的示例正确地实现了三个函数,调用它们的超级函数。
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:NO];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:NO];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:NO];
}https://stackoverflow.com/questions/13347480
复制相似问题